Skip to content

Commit 61852f0

Browse files
BendingBendersindresorhus
authored andcommitted
Refactor TypeScript definition to CommonJS compatible export (#6)
1 parent d5627c1 commit 61852f0

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

index.d.ts

+22-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1-
/**
2-
[FNV-1a](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function) non-cryptographic hash function.
1+
declare const fnv1a: {
2+
/**
3+
[FNV-1a](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function) non-cryptographic hash function.
34
4-
@returns The hash as a positive integer.
5-
*/
6-
export default function fnv1a(string: string): number;
5+
@returns The hash as a positive integer.
6+
7+
@example
8+
```
9+
import fnv1a = require('@sindresorhus/fnv1a');
10+
11+
fnv1a('🦄🌈');
12+
//=> 582881315
13+
```
14+
*/
15+
(string: string): number;
16+
17+
// TODO: remove this in the next major version, refactor the whole definition to:
18+
// declare function fnv1a(string: string): number;
19+
// export = fnv1a;
20+
default: typeof fnv1a;
21+
};
22+
23+
export = fnv1a;

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ const fnv1a = string => {
1616
};
1717

1818
module.exports = fnv1a;
19+
// TODO: remove this in the next major version, refactor the whole definition to:
1920
module.exports.default = fnv1a;

index.test-d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {expectType} from 'tsd-check';
2-
import fnv1a from '.';
1+
import {expectType} from 'tsd';
2+
import fnv1a = require('.');
33

44
expectType<number>(fnv1a('🦄🌈'));

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"node": ">=6"
1414
},
1515
"scripts": {
16-
"test": "xo && ava && tsd-check"
16+
"test": "xo && ava && tsd"
1717
},
1818
"files": [
1919
"index.js",
@@ -36,8 +36,8 @@
3636
"vo"
3737
],
3838
"devDependencies": {
39-
"ava": "^1.3.1",
40-
"tsd-check": "^0.5.0",
39+
"ava": "^1.4.1",
40+
"tsd": "^0.7.1",
4141
"xo": "^0.24.0"
4242
}
4343
}

0 commit comments

Comments
 (0)