Skip to content

Commit

Permalink
fix: Warning on assert import in browser env
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Shirokov committed May 29, 2024
1 parent 76da6db commit c65e99b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,16 @@ MIT

## Contributing

add a link
All contributions are welcome. Please make sure to add tests for your changes.

You need to initialise the repository with the following command:

```shell
git submodule update --init --recursive
```

Then you can run tests with:

```shell
npm test
```
6 changes: 3 additions & 3 deletions src/decoder.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import assert from 'assert';
import utils from './utils';
import { Cache } from './types';

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

constructor(db: Buffer, baseOffset = 0, cache: Cache = noCache) {
assert((this.db = db), 'Database buffer is required');
utils.assert(Boolean(db), 'Database buffer is required');
this.db = db;
this.baseOffset = baseOffset;
this.cache = cache;
}
Expand Down
3 changes: 1 addition & 2 deletions src/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from 'assert';
import Decoder from './decoder';
import utils from './utils';

Expand Down Expand Up @@ -35,7 +34,7 @@ export const parseMetadata = (db: Buffer): Metadata => {
);
}

assert(
utils.assert(
[24, 28, 32].indexOf(metadata.record_size) > -1,
'Unsupported record size'
);
Expand Down
7 changes: 7 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ Upgrade instructions can be found here: \
https://github.com/runk/node-maxmind/wiki/Migration-guide\n\
If you want to use legacy library then explicitly install maxmind@1`;

const assert = (condition: boolean, message: string): void => {
if (!condition) {
throw new Error(message);
}
}

export default {
assert,
concat2,
concat3,
concat4,
Expand Down

0 comments on commit c65e99b

Please sign in to comment.