initial commit
This commit is contained in:
+22
@@ -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;
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
const builtinModules = require('builtin-modules');
|
||||
|
||||
const moduleSet = new Set(builtinModules);
|
||||
const NODE_PROTOCOL = 'node:';
|
||||
|
||||
module.exports = moduleName => {
|
||||
if (typeof moduleName !== 'string') {
|
||||
throw new TypeError('Expected a string');
|
||||
}
|
||||
|
||||
if (moduleName.startsWith(NODE_PROTOCOL)) {
|
||||
moduleName = moduleName.slice(NODE_PROTOCOL.length);
|
||||
}
|
||||
|
||||
const slashIndex = moduleName.indexOf('/');
|
||||
if (slashIndex !== -1) {
|
||||
moduleName = moduleName.slice(0, slashIndex);
|
||||
}
|
||||
|
||||
return moduleSet.has(moduleName);
|
||||
};
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "is-builtin-module",
|
||||
"version": "3.2.0",
|
||||
"description": "Check if a string matches the name of a Node.js builtin module",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/is-builtin-module",
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"builtin",
|
||||
"built-in",
|
||||
"builtins",
|
||||
"node",
|
||||
"modules",
|
||||
"core",
|
||||
"bundled",
|
||||
"list",
|
||||
"array",
|
||||
"names",
|
||||
"is",
|
||||
"detect",
|
||||
"check",
|
||||
"match"
|
||||
],
|
||||
"dependencies": {
|
||||
"builtin-modules": "^3.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^0.25.0",
|
||||
"tsd": "^0.7.2",
|
||||
"xo": "^0.23.0"
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
# is-builtin-module
|
||||
|
||||
> Check if a string matches the name of a Node.js builtin module
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install is-builtin-module
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const isBuiltinModule = require('is-builtin-module');
|
||||
|
||||
isBuiltinModule('fs');
|
||||
//=> true
|
||||
|
||||
isBuiltinModule('fs/promises');
|
||||
//=> true
|
||||
|
||||
isBuiltinModule('node:fs/promises');
|
||||
//=> true
|
||||
|
||||
isBuiltinModule('unicorn');
|
||||
//=> false
|
||||
```
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [builtin-modules](https://github.com/sindresorhus/builtin-modules) - List of the Node.js builtin modules
|
||||
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<b>
|
||||
<a href="https://tidelift.com/subscription/pkg/npm-is-builtin-module?utm_source=npm-is-builtin-module&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
||||
</b>
|
||||
<br>
|
||||
<sub>
|
||||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
||||
</sub>
|
||||
</div>
|
||||
Reference in New Issue
Block a user