Commit b6225ea

Anton Golub <antongolub@antongolub.com>
2025-01-05 21:18:25
chore: simplify regexes (#1055)
1 parent 4c45e44
Changed files (2)
src/deps.ts
@@ -98,8 +98,7 @@ const builtins = new Set([
   'zlib',
 ])
 
-const nameRe =
-  /^(?<name>(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*)\/?.*$/i
+const nameRe = /^(?<name>(@[a-z\d-~][\w-.~]*\/)?[a-z\d-~][\w-.~]*)\/?.*$/i
 const versionRe = /^@(?<version>[~^]?(v?[\dx*]+([-.][\d*a-z-]+)*))/i
 
 export function parseDeps(content: Buffer | string): Record<string, string> {
src/util.ts
@@ -265,7 +265,7 @@ export function formatCmd(cmd?: string): string {
   }
 
   function word() {
-    if (/[0-9a-z/_.]/i.test(ch)) return word
+    if (/[\w/.]/i.test(ch)) return word
     return root
   }