https://github.com/flex-development/is-builtin
Universal drop-in replacement for module.isBuiltin
https://github.com/flex-development/is-builtin
builtin module node nodejs ponyfill typescript
Last synced: 2 months ago
JSON representation
Universal drop-in replacement for module.isBuiltin
- Host: GitHub
- URL: https://github.com/flex-development/is-builtin
- Owner: flex-development
- License: bsd-3-clause
- Created: 2022-10-08T08:39:10.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-08T18:01:40.000Z (8 months ago)
- Last Synced: 2024-11-08T19:17:31.234Z (8 months ago)
- Topics: builtin, module, node, nodejs, ponyfill, typescript
- Language: JavaScript
- Homepage: https://github.com/flex-development/is-builtin
- Size: 5.33 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/funding.yml
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# is-builtin
[](https://github.com/flex-development/is-builtin/releases/latest)
[](https://npmjs.com/package/@flex-development/is-builtin)
[](https://codecov.io/github/flex-development/is-builtin)
[](https://github.com/voxpelli/badges-cjs-esm)
[](LICENSE.md)
[](https://conventionalcommits.org)
[](https://typescriptlang.org)
[](https://vitest.dev)
[](https://yarnpkg.com)Universal drop-in replacement for [`module.isBuiltin`][moduleisbuiltin]
## Contents
- [What is this?](#what-is-this)
- [When should I use this?](#when-should-i-use-this)
- [Install](#install)
- [Use](#use)
- [API](#api)
- [`isBuiltin(m)`](#isbuiltinm)
- [Types](#types)
- [Related](#related)
- [Contribute](#contribute)## What is this?
This package is a universal drop-in replacement for [`module.isBuiltin`][moduleisbuiltin].
## When should I use this?
This package exports a single function that can be used to determine if a module is a [builtin module][builtin]. Builtin
modules are core modules maintained by Node.js. They can be imported by name or using a [`node:` URL][node-url].## Install
This package is [ESM only][esm].
In Node.js (version 18+) with [yarn][]:
```sh
yarn add @flex-development/is-builtin
```
See Git - Protocols | Yarn
Β for details regarding installing from Git.
In Deno with [`esm.sh`][esmsh]:
```ts
import { isBuiltin } from 'https://esm.sh/@flex-development/is-builtin'
```In browsers with [`esm.sh`][esmsh]:
```html
import { isBuiltin } from 'https://esm.sh/@flex-development/is-builtin'
```
## Use
```ts
import { isBuiltin } from '@flex-development/is-builtin'isBuiltin('@flex-development/is-builtin') // false
isBuiltin('assert') // true
isBuiltin('fs/promises') // true
isBuiltin(new URL('node:os')) // true
isBuiltin('node:module') // true
isBuiltin('node:test/reporters') // true
isBuiltin('test') // false
isBuiltin(null) // false
```## API
This package exports the identifier [`isBuiltin`](#isbuiltinm).
The default export is also `isBuiltin`.
### `isBuiltin(m)`
Check if `m` references a [builtin module][builtin].
> π **Note**: `m` will be converted to a string (`String(m)`) before being checked.
#### Parameters
- `m` (`unknown`) β the thing to check
#### Returns
`true` if `m` references builtin module, `false` otherwise.
## Types
This package is fully typed with [TypeScript][].
## Related
- [`builtin-modules`][builtin-modules]
β Universal drop-in replacement for [`module.builtinModules`][modulebuiltinmodules]## Contribute
See [`CONTRIBUTING.md`](./CONTRIBUTING.md).
This project has a [code of conduct](./CODE_OF_CONDUCT.md). By interacting with this repository, organization, or
community you agree to abide by its terms.[builtin-modules]: https://github.com/flex-development/builtin-modules
[builtin]: https://nodejs.org/api/esm.html#builtin-modules
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[modulebuiltinmodules]: https://nodejs.org/api/module.html#modulebuiltinmodules
[moduleisbuiltin]: https://nodejs.org/api/module.html#moduleisbuiltinmodulename
[node-url]: https://nodejs.org/api/esm.html#node-imports
[typescript]: https://www.typescriptlang.org
[yarn]: https://yarnpkg.com