Skip to content

Commit

Permalink
Add TypeScript definition (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 7, 2019
1 parent 7ba6bb5 commit e18e6ac
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: node_js
node_js:
- '11'
- '10'
- '8'
- '6'
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 the Node.js builtin modules.
@example
```
import builtinModules = require('builtin-modules');
console.log(builtinModules);
//=> ['assert', 'buffer', …]
```
*/
declare const builtinModules: readonly string[];

export = builtinModules;
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const blacklist = [
'sys'
];

// eslint-disable-next-line node/no-deprecated-api
module.exports = (builtinModules || Object.keys(process.binding('natives')))
.filter(x => !/^_|^(internal|v8|node-inspect)\/|\//.test(x) && !blacklist.includes(x))
.sort();
9 changes: 9 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {expectType, expectError} from 'tsd';
import builtinModules = require('.');
import builtinModulesStatic = require ('./static');

expectType<readonly string[]>(builtinModules);
expectError<string[]>(builtinModules);

expectType<readonly string[]>(builtinModulesStatic);
expectError<string[]>(builtinModulesStatic);
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
"node": ">=6"
},
"scripts": {
"test": "xo && ava",
"test": "xo && ava && tsd",
"make": "node make.js"
},
"files": [
"index.js",
"index.d.ts",
"static.js",
"static.d.ts",
"builtin-modules.json"
],
"keywords": [
Expand All @@ -34,7 +36,8 @@
"names"
],
"devDependencies": {
"ava": "*",
"xo": "*"
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
14 changes: 14 additions & 0 deletions static.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
Static list of the Node.js builtin modules.
@example
```
import builtinModulesStatic = require('builtin-modules/static');
console.log(builtinModulesStatic);
//=> ['assert', 'buffer', …]
```
*/
declare const builtinModulesStatic: readonly string[];

export = builtinModulesStatic;

0 comments on commit e18e6ac

Please sign in to comment.