Skip to content

Commit

Permalink
Add TypeScript definition (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 22, 2019
1 parent 167194b commit 63f7d33
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 11 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
language: node_js
node_js:
- '10'
- '8'
14 changes: 14 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
List of words for making random mnemonic sentences.
@example
```
import mnemonicWords = require('mnemonic-words');
console.log(mnemonicWords);
//=> ['abandon', 'ability', …]
```
*/
declare const mnemonicWords: readonly string[];

export = mnemonicWords;
6 changes: 6 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {expectType} from 'tsd';
import mnemonicWords = require('.');
import mnemonicWordsJson = require('./words.json');

expectType<readonly string[]>(mnemonicWords);
expectType<readonly string[]>(mnemonicWordsJson);
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"words.json"
"index.d.ts",
"words.json",
"words.json.d.ts"
],
"keywords": [
"mnemonic",
Expand All @@ -31,7 +33,8 @@
"bitcoin"
],
"devDependencies": {
"ava": "*",
"xo": "*"
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
10 changes: 5 additions & 5 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import test from 'ava';
import m from '.';
import mnemonicWords from '.';

test(t => {
t.true(Array.isArray(m));
t.true(m.length > 0);
t.is(m[20], 'action');
test('main', t => {
t.true(Array.isArray(mnemonicWords));
t.true(mnemonicWords.length > 0);
t.is(mnemonicWords[20], 'action');
});
3 changes: 3 additions & 0 deletions words.json.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare const mnemonicWordsJson: readonly string[];

export = mnemonicWordsJson;

0 comments on commit 63f7d33

Please sign in to comment.