summaryrefslogtreecommitdiff
path: root/cli/npm/common.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-10-03 19:05:06 -0400
committerGitHub <noreply@github.com>2023-10-03 19:05:06 -0400
commit8c1677ecbcbb474fc6a5ac9b5f73b562677bb829 (patch)
tree885a45a67e6aed7dc70307df718b176a729c8655 /cli/npm/common.rs
parent494822175fd69f8c20a2e21ddcedcb3287064cce (diff)
refactor(npm): break up `NpmModuleLoader` and move more methods into the managed `CliNpmResolver` (#20777)
Part of https://github.com/denoland/deno/issues/18967
Diffstat (limited to 'cli/npm/common.rs')
-rw-r--r--cli/npm/common.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/cli/npm/common.rs b/cli/npm/common.rs
new file mode 100644
index 000000000..c7ae55f8f
--- /dev/null
+++ b/cli/npm/common.rs
@@ -0,0 +1,23 @@
+// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+
+/// Gets the corresponding @types package for the provided package name.
+pub fn types_package_name(package_name: &str) -> String {
+ debug_assert!(!package_name.starts_with("@types/"));
+ // Scoped packages will get two underscores for each slash
+ // https://github.com/DefinitelyTyped/DefinitelyTyped/tree/15f1ece08f7b498f4b9a2147c2a46e94416ca777#what-about-scoped-packages
+ format!("@types/{}", package_name.replace('/', "__"))
+}
+
+#[cfg(test)]
+mod test {
+ use super::types_package_name;
+
+ #[test]
+ fn test_types_package_name() {
+ assert_eq!(types_package_name("name"), "@types/name");
+ assert_eq!(
+ types_package_name("@scoped/package"),
+ "@types/@scoped__package"
+ );
+ }
+}