summaryrefslogtreecommitdiff
path: root/ext/node/polyfill.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node/polyfill.rs')
-rw-r--r--ext/node/polyfill.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/ext/node/polyfill.rs b/ext/node/polyfill.rs
index 7772e3a16..a4c87bef7 100644
--- a/ext/node/polyfill.rs
+++ b/ext/node/polyfill.rs
@@ -1,5 +1,7 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+use deno_core::ModuleSpecifier;
+
/// e.g. `is_builtin_node_module("assert")`
pub fn is_builtin_node_module(module_name: &str) -> bool {
SUPPORTED_BUILTIN_NODE_MODULES
@@ -7,6 +9,18 @@ pub fn is_builtin_node_module(module_name: &str) -> bool {
.any(|m| *m == module_name)
}
+/// Ex. returns `fs` for `node:fs`
+pub fn get_module_name_from_builtin_node_module_specifier(
+ specifier: &ModuleSpecifier,
+) -> Option<&str> {
+ if specifier.scheme() != "node" {
+ return None;
+ }
+
+ let (_, specifier) = specifier.as_str().split_once(':')?;
+ Some(specifier)
+}
+
macro_rules! generate_builtin_node_module_lists {
($( $module_name:literal ,)+) => {
pub static SUPPORTED_BUILTIN_NODE_MODULES: &[&str] = &[