Skip to content

flex-development/is-builtin

is-builtin

github release npm codecov module type: esm license conventional commits typescript vitest yarn

Universal drop-in replacement for module.isBuiltin

Contents

What is this?

This package is a universal drop-in replacement for module.isBuiltin.

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 modules are core modules maintained by Node.js. They can be imported by name or using a node: URL.

Install

This package is ESM only.

yarn add @flex-development/is-builtin

From Git:

yarn add @flex-development/is-builtin@flex-development/is-builtin
See Git - Protocols | Yarn  for details on requesting a specific branch, commit, or tag.

Use

import { isBuiltin } from '@flex-development/is-builtin'
import { URL, pathToFileURL } from 'node:url'

console.debug(isBuiltin('@flex-development/is-builtin'))                        // false
console.debug(isBuiltin('fs/promises'))                                         // true
console.debug(isBuiltin('node:module'))                                         // true
console.debug(isBuiltin(new URL('node:os')))                                    // true
console.debug(isBuiltin(pathToFileURL('node_modules/@flex-development/mlly')))  // false

API

This package exports the following identifiers:

There is no default export.

isBuiltin(id: URL | string) => boolean

Checks if the given module id is a builtin module.

Supports bare specifiers and node: URLs. If the given module id is an instance of URL, id.href will be checked instead.

Parameters

  • id (URL | string) — Module id to evaluate

Returns

Returns true if id is a builtin module, false otherwise.

Types

This package is fully typed with TypeScript.

Related

Contribute

See CONTRIBUTING.md.