Skip to content

Commit

Permalink
Add TypeScript definition (#11)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
sagargurtu and sindresorhus committed Jul 31, 2022
1 parent 819869f commit cbcb463
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
22 changes: 22 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
Returns `true` if the given `moduleName` is a Node.js builtin module, `false` otherwise.
@param moduleName - The name of the module.
@example
```
import isBuiltinModule = require('is-builtin-module');
isBuiltinModule('fs/promises');
//=> true
isBuiltinModule('node:fs');
//=> true
isBuiltinModule('unicorn');
//=> false
```
*/
declare function isBuiltinModule(moduleName: string): boolean;

export = isBuiltinModule;
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, expectError} from 'tsd';
import isBuiltinModule = require('.');

expectType<(moduleName: string) => boolean>(isBuiltinModule);
expectError<() => boolean>(isBuiltinModule);
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=6"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"keywords": [
"builtin",
Expand All @@ -39,6 +40,7 @@
},
"devDependencies": {
"ava": "^0.25.0",
"tsd": "^0.7.2",
"xo": "^0.23.0"
}
}

0 comments on commit cbcb463

Please sign in to comment.