Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Mar 31, 2019
1 parent d5627c1 commit 61852f0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
27 changes: 22 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
/**
[FNV-1a](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function) non-cryptographic hash function.
declare const fnv1a: {
/**
[FNV-1a](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function) non-cryptographic hash function.
@returns The hash as a positive integer.
*/
export default function fnv1a(string: string): number;
@returns The hash as a positive integer.
@example
```
import fnv1a = require('@sindresorhus/fnv1a');
fnv1a('🦄🌈');
//=> 582881315
```
*/
(string: string): number;

// TODO: remove this in the next major version, refactor the whole definition to:
// declare function fnv1a(string: string): number;
// export = fnv1a;
default: typeof fnv1a;
};

export = fnv1a;
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ const fnv1a = string => {
};

module.exports = fnv1a;
// TODO: remove this in the next major version, refactor the whole definition to:
module.exports.default = fnv1a;
4 changes: 2 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expectType} from 'tsd-check';
import fnv1a from '.';
import {expectType} from 'tsd';
import fnv1a = require('.');

expectType<number>(fnv1a('🦄🌈'));
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"node": ">=6"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand All @@ -36,8 +36,8 @@
"vo"
],
"devDependencies": {
"ava": "^1.3.1",
"tsd-check": "^0.5.0",
"ava": "^1.4.1",
"tsd": "^0.7.1",
"xo": "^0.24.0"
}
}

0 comments on commit 61852f0

Please sign in to comment.