Skip to content

Commit

Permalink
docs: api
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed Jan 29, 2023
1 parent e7f5a05 commit 5f7573c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
35 changes: 29 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Universal drop-in replacement for [`module.isBuiltin`][1]
- [Install](#install)
- [Use](#use)
- [API](#api)
- [isBuiltin(id)](#isbuiltinid-url--string--boolean)
- [Types](#types)
- [Related](#related)
- [Contribute](#contribute)
Expand Down Expand Up @@ -67,15 +68,34 @@ console.debug(isBuiltin(pathToFileURL('node_modules/@flex-development/mlly')))

## API

**TODO**: api documentation.
This package exports the following identifiers:

- [`isBuiltin`](#isbuiltinid-url--string--boolean)

There is no default export.

### `isBuiltin(id: URL | string) => boolean`

Checks if the given module `id` is a [builtin module][2].

Supports [bare specifiers][5] and [`node:` URLs][3]. If the given module `id` is an instance of [`URL`][6],
[`id.href`][7] will be checked instead.

#### Parameters

- `id` (`URL | string`) &mdash; Module id to evaluate

#### Returns

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

## Types

This package is fully typed with [TypeScript][5].
This package is fully typed with [TypeScript][8].

## Related

- [`builtin-modules`][6] &mdash; Universal drop-in replacement for [`module.builtinModules`][7]
- [`builtin-modules`][9] &mdash; Universal drop-in replacement for [`module.builtinModules`][10]

## Contribute

Expand All @@ -85,6 +105,9 @@ See [`CONTRIBUTING.md`](CONTRIBUTING.md).
[2]: https://nodejs.org/api/esm.html#builtin-modules
[3]: https://nodejs.org/api/esm.html#node-imports
[4]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[5]: https://www.typescriptlang.org
[6]: https://github.com/flex-development/builtin-modules
[7]: https://nodejs.org/api/module.html#modulebuiltinmodules
[5]: https://nodejs.org/api/esm.html#terminology
[6]: https://nodejs.org/api/url.html#class-url
[7]: https://nodejs.org/api/url.html#urlhref
[8]: https://www.typescriptlang.org
[9]: https://github.com/flex-development/builtin-modules
[10]: https://nodejs.org/api/module.html#modulebuiltinmodules
5 changes: 4 additions & 1 deletion src/is-builtin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import type { URL } from 'node:url'
/**
* Checks if the given module `id` is a [builtin module][1].
*
* Supports [bare specifiers][2] and [`node:` URLs][3].
* Supports [bare specifiers][2] and [`node:` URLs][3]. If the given module `id`
* is an instance of [`URL`][4], [`id.href`][5] will be checked instead.
*
* [1]: https://nodejs.org/api/esm.html#builtin-modules
* [2]: https://nodejs.org/api/esm.html#terminology
* [3]: https://nodejs.org/api/esm.html#node-imports
* [4]: https://nodejs.org/api/url.html#class-url
* [5]: https://nodejs.org/api/url.html#urlhref
*
* @example
* isBuiltin('@flex-development/is-builtin') // false
Expand Down

0 comments on commit 5f7573c

Please sign in to comment.