From 9d918d99236ac3c2e43d86b9648b0b210ec63368 Mon Sep 17 00:00:00 2001 From: "hemanth.hm" Date: Fri, 8 Jul 2022 01:12:32 -0700 Subject: [PATCH] module: add isBuiltIn method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/43396 Fixes: https://github.com/nodejs/node/issues/42785 Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Michaël Zasso Reviewed-By: Anto Aravinth Reviewed-By: Juan José Arboleda --- doc/api/module.md | 16 ++++++++++++++++ lib/internal/modules/cjs/loader.js | 11 +++++++++++ test/parallel/test-module-isBuiltin.js | 16 ++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 test/parallel/test-module-isBuiltin.js diff --git a/doc/api/module.md b/doc/api/module.md index 85ba9a79e2291d..04b5263155c76b 100644 --- a/doc/api/module.md +++ b/doc/api/module.md @@ -62,6 +62,22 @@ const require = createRequire(import.meta.url); const siblingModule = require('./sibling-module'); ``` +### `module.isBuiltin(moduleName)` + + + +* `moduleName` {string} name of the module +* Returns: {boolean} returns true if the module is builtin else returns false + +```mjs +import { isBuiltin } from 'node:module'; +isBuiltin('node:fs'); // true +isBuiltin('fs'); // true +isBuiltin('wss'); // false +``` + ### `module.syncBuiltinESMExports()`