builtin-modules 2.0.0
Install from the command line:
Learn more about npm packages
$ npm install @flex-development/builtin-modules@2.0.0
Install via package.json:
"@flex-development/builtin-modules": "2.0.0"
About this version
Universal drop-in replacement for module.builtinModules
This package is a universal drop-in replacement for the builtinModules
constant exported by node:module
.
This package exports an array containing the names of modules provided by Node.js. It can be used to not only verify
that a module is maintained by Node.js, but to also determine if a module can be imported using a node:
URL.
This package is ESM only.
yarn add @flex-development/builtin-modules
From Git:
yarn add @flex-development/builtin-modules@flex-development/builtin-modules
See Git - Protocols | Yarn for details on requesting a specific branch, commit, or tag.
import { builtinModules } from '@flex-development/builtin-modules'
/**
* Set containing the names of modules provided by Node.js.
*
* **Note**: Includes [`node:` URLs][1].
*
* [1]: https://nodejs.org/api/esm.html#node-imports
*
* @const {Set<string>} BUILTIN_MODULES
*/
const BUILTIN_MODULES = new Set(builtinModules.flatMap(m => [m, 'node:' + m]))
/**
* Checks if the given module `name` is the name of a [builtin module][1].
*
* Allows for [`node:` URLs][2].
*
* [1]: https://nodejs.org/api/esm.html#builtin-modules
* [2]: https://nodejs.org/api/esm.html#node-imports
*
* @example
* isBuiltin('node:module') // true
* @example
* isBuiltin('fs/promises') // true
* @example
* isBuiltin('@flex-development/builtin-modules') // false
*
* @param {string} name - Module name to evaluate
* @return {boolean} `true` if `name` is name of builtin module
*/
const isBuiltin = (name: string): boolean => BUILTIN_MODULES.has(name)
console.debug(isBuiltin('node:module'))
console.debug(isBuiltin('fs/promises'))
console.debug(isBuiltin('@flex-development/builtin-modules'))
This package exports the identifier builtinModules
.
There is no default export.
An array containing the names of modules provided by Node.js.
The array is a superset of module.builtinModules
given the running version of Node.js.
Possible use cases:
- Check if a module can be imported using a
node:
URL - Check if a module is maintained by Node.js
This package is fully typed with TypeScript.
-
is-builtin
— Universal drop-in replacement formodule.isBuiltin
See CONTRIBUTING.md
.
Details
- builtin-modules
-
flex-development
- almost 2 years ago
- BSD-3-Clause
- 79 dependencies
Assets
- builtin-modules-2.0.0.tgz
Download activity
- Total downloads 40
- Last 30 days 0
- Last week 0
- Today 0