Skip to content

Commit

Permalink
Require Node.js 8, add TypeScript definition (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed May 3, 2019
1 parent 7816a9f commit 793178c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- '12'
- '10'
- '8'
- '6'
31 changes: 31 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import supervillainsJson = require('./supervillains.json');

declare const supervillains: {
/**
Supervillain names in alphabetical order.
@example
```
const supervillains = require('supervillains');
supervillains.all;
//=> ['Abattoir', 'Able Crown', …]
```
*/
readonly all: Readonly<typeof supervillainsJson>;

/**
Random supervillain name.
@example
```
const supervillains = require('supervillains');
supervillains.random();
//=> 'Mud Pack'
```
*/
random(): string;
};

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

expectType<readonly string[]>(supervillains.all);
expectType<string>(supervillains.random());
15 changes: 11 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts",
"supervillains.json"
],
"keywords": [
Expand All @@ -35,10 +36,16 @@
"comics"
],
"dependencies": {
"unique-random-array": "^1.0.0"
"unique-random-array": "^2.0.0"
},
"devDependencies": {
"ava": "^1.2.1",
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
},
"tsd": {
"compilerOptions": {
"resolveJsonModule": true
}
}
}
5 changes: 4 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ $ npm install supervillains
```js
const supervillains = require('supervillains');

supervillains.all;
//=> ['Abattoir', 'Able Crown', …]

supervillains.random();
//=> 'Mud Pack'
```
Expand All @@ -28,7 +31,7 @@ supervillains.random();

### .all

Type: `Array`
Type: `string[]`

Supervillain names in alphabetical order.

Expand Down

0 comments on commit 793178c

Please # to comment.