builtin_modules 0.2.0

A static list of the Node.js builtin modules from the latest Node.js version in rust
Documentation
use std::{collections::HashSet, sync::LazyLock};

/// Get BUILTIN_MODULES for nodejs module
///
/// [
///     "_http_agent",
///     "_http_client",
///     "_http_common",
///     "_http_incoming",
///     "_http_outgoing",
///     "_http_server",
///     "_stream_duplex",
///     "_stream_passthrough",
///     "_stream_readable",
///     "_stream_transform",
///     "_stream_wrap",
///     "_stream_writable",
///     "_tls_common",
///     "_tls_wrap",
///     "assert",
///     "assert/strict",
///     "async_hooks",
///     "buffer",
///     "child_process",
///     "cluster",
///     "console",
///     "constants",
///     "crypto",
///     "dgram",
///     "diagnostics_channel",
///     "dns",
///     "dns/promises",
///     "domain",
///     "events",
///     "fs",
///     "fs/promises",
///     "http",
///     "http2",
///     "https",
///     "inspector",
///     "inspector/promises",
///     "module",
///     "net",
///     "os",
///     "path",
///     "path/posix",
///     "path/win32",
///     "perf_hooks",
///     "process",
///     "punycode",
///     "querystring",
///     "readline",
///     "readline/promises",
///     "repl",
///     "stream",
///     "stream/consumers",
///     "stream/promises",
///     "stream/web",
///     "string_decoder",
///     "sys",
///     "test/mock_loader",
///     "timers",
///     "timers/promises",
///     "tls",
///     "trace_events",
///     "tty",
///     "url",
///     "util",
///     "util/types",
///     "v8",
///     "vm",
///     "wasi",
///     "worker_threads",
///     "zlib",
/// ]
///
/// # Example
///
/// ```
/// assert!(builtin_modules::BUILTIN_MODULES.contains("path"));
/// ```
pub static BUILTIN_MODULES: LazyLock<HashSet<String>> = LazyLock::new(|| {
    [
        "_http_agent",
        "_http_client",
        "_http_common",
        "_http_incoming",
        "_http_outgoing",
        "_http_server",
        "_stream_duplex",
        "_stream_passthrough",
        "_stream_readable",
        "_stream_transform",
        "_stream_wrap",
        "_stream_writable",
        "_tls_common",
        "_tls_wrap",
        "assert",
        "assert/strict",
        "async_hooks",
        "buffer",
        "child_process",
        "cluster",
        "console",
        "constants",
        "crypto",
        "dgram",
        "diagnostics_channel",
        "dns",
        "dns/promises",
        "domain",
        "events",
        "fs",
        "fs/promises",
        "http",
        "http2",
        "https",
        "inspector",
        "inspector/promises",
        "module",
        "net",
        "os",
        "path",
        "path/posix",
        "path/win32",
        "perf_hooks",
        "process",
        "punycode",
        "querystring",
        "readline",
        "readline/promises",
        "repl",
        "stream",
        "stream/consumers",
        "stream/promises",
        "stream/web",
        "string_decoder",
        "sys",
        "test/mock_loader",
        "timers",
        "timers/promises",
        "tls",
        "trace_events",
        "tty",
        "url",
        "util",
        "util/types",
        "v8",
        "vm",
        "wasi",
        "worker_threads",
        "zlib",
    ]
    .iter()
    .map(|m| m.to_string())
    .collect::<HashSet<_>>()
});

/// Check whether builtin module
///
/// # Example
/// ```
/// assert!(builtin_modules::is_builtin_module("path"));
/// assert!(builtin_modules::is_builtin_module("fs/promises"));
/// assert!(!builtin_modules::is_builtin_module("abc"));
/// ```
pub fn is_builtin_module(name: &str) -> bool {
    BUILTIN_MODULES.contains(name)
}