From 63f7d332f7c0a91d2c10af5afd0be568592750f1 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Mon, 22 Apr 2019 07:19:48 +0000 Subject: [PATCH] Add TypeScript definition (#2) --- .gitattributes | 3 +-- .travis.yml | 1 + index.d.ts | 14 ++++++++++++++ index.test-d.ts | 6 ++++++ package.json | 11 +++++++---- test.js | 10 +++++----- words.json.d.ts | 3 +++ 7 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 index.d.ts create mode 100644 index.test-d.ts create mode 100644 words.json.d.ts diff --git a/.gitattributes b/.gitattributes index 391f0a4..6313b56 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1 @@ -* text=auto -*.js text eol=lf +* text=auto eol=lf diff --git a/.travis.yml b/.travis.yml index b3be97a..f3fa8cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ language: node_js node_js: + - '10' - '8' diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..6b84917 --- /dev/null +++ b/index.d.ts @@ -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; diff --git a/index.test-d.ts b/index.test-d.ts new file mode 100644 index 0000000..2faa4a7 --- /dev/null +++ b/index.test-d.ts @@ -0,0 +1,6 @@ +import {expectType} from 'tsd'; +import mnemonicWords = require('.'); +import mnemonicWordsJson = require('./words.json'); + +expectType(mnemonicWords); +expectType(mnemonicWordsJson); diff --git a/package.json b/package.json index 09edf5d..5e71fa5 100644 --- a/package.json +++ b/package.json @@ -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", @@ -31,7 +33,8 @@ "bitcoin" ], "devDependencies": { - "ava": "*", - "xo": "*" + "ava": "^1.4.1", + "tsd": "^0.7.2", + "xo": "^0.24.0" } } diff --git a/test.js b/test.js index dcba1b9..857eff6 100644 --- a/test.js +++ b/test.js @@ -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'); }); diff --git a/words.json.d.ts b/words.json.d.ts new file mode 100644 index 0000000..1e496f6 --- /dev/null +++ b/words.json.d.ts @@ -0,0 +1,3 @@ +declare const mnemonicWordsJson: readonly string[]; + +export = mnemonicWordsJson;