Skip to content

Commit 1dec2e7

Browse files
authored
Merge pull request #193 from runk/fix-assert-in-browser
fix: Warning on assert import in browser env
2 parents 76da6db + c65e99b commit 1dec2e7

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,16 @@ MIT
6363

6464
## Contributing
6565

66-
add a link
66+
All contributions are welcome. Please make sure to add tests for your changes.
67+
68+
You need to initialise the repository with the following command:
69+
70+
```shell
71+
git submodule update --init --recursive
72+
```
73+
74+
Then you can run tests with:
75+
76+
```shell
77+
npm test
78+
```

src/decoder.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import assert from 'assert';
21
import utils from './utils';
32
import { Cache } from './types';
43

5-
assert(
4+
utils.assert(
65
typeof BigInt !== 'undefined',
76
'Apparently you are using old version of node. Please upgrade to node 10.4.x or above.'
87
);
@@ -47,7 +46,8 @@ export default class Decoder {
4746
private cache: Cache;
4847

4948
constructor(db: Buffer, baseOffset = 0, cache: Cache = noCache) {
50-
assert((this.db = db), 'Database buffer is required');
49+
utils.assert(Boolean(db), 'Database buffer is required');
50+
this.db = db;
5151
this.baseOffset = baseOffset;
5252
this.cache = cache;
5353
}

src/metadata.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import assert from 'assert';
21
import Decoder from './decoder';
32
import utils from './utils';
43

@@ -35,7 +34,7 @@ export const parseMetadata = (db: Buffer): Metadata => {
3534
);
3635
}
3736

38-
assert(
37+
utils.assert(
3938
[24, 28, 32].indexOf(metadata.record_size) > -1,
4039
'Unsupported record size'
4140
);

src/utils.ts

+7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ Upgrade instructions can be found here: \
1515
https://github.com/runk/node-maxmind/wiki/Migration-guide\n\
1616
If you want to use legacy library then explicitly install maxmind@1`;
1717

18+
const assert = (condition: boolean, message: string): void => {
19+
if (!condition) {
20+
throw new Error(message);
21+
}
22+
}
23+
1824
export default {
25+
assert,
1926
concat2,
2027
concat3,
2128
concat4,

0 commit comments

Comments
 (0)