MCPcopy Index your code
hub / github.com/npmx-dev/npmx.dev / isNpmPackage

Function isNpmPackage

server/utils/code-highlight.ts:101–113  ·  view source on GitHub ↗

* Check if a module specifier is an npm package (not a relative/absolute path or Node built-in)

(specifier: string)

Source from the content-addressed store, hash-verified

99 * Check if a module specifier is an npm package (not a relative/absolute path or Node built-in)
100 */
101function isNpmPackage(specifier: string): boolean {
102 // Remove quotes
103 const pkg = specifier.replace(/^['"]|['"]$/g, '').trim()
104 // Relative or absolute paths
105 if (pkg.startsWith('.') || pkg.startsWith('/')) return false
106 // Node built-ins with node: prefix
107 if (pkg.startsWith('node:')) return false
108 // Node built-ins without prefix
109 if (isBuiltin(pkg)) return false
110 // Empty
111 if (!pkg) return false
112 return true
113}
114
115/**
116 * Extract the package name from a module specifier (handles scoped packages and subpaths)

Callers 1

getHrefFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected