MCPcopy Create free account
hub / github.com/npmx-dev/npmx.dev / normalizePackageName

Function normalizePackageName

app/utils/package-name.ts:16–29  ·  view source on GitHub ↗
(name: string)

Source from the content-addressed store, hash-verified

14 * This aims to mirror npm's typosquatting detection algorithm.
15 */
16export function normalizePackageName(name: string): string {
17 // Remove scope if present
18 const unscoped = name.startsWith('@') ? name.split('/')[1] || name : name
19
20 // Normalize: lowercase, remove punctuation (.-_), remove 'js' and 'node' suffixes/prefixes
21 return (
22 unscoped
23 .toLowerCase()
24 // Remove all punctuation
25 .replace(/[.\-_]/g, '')
26 // Remove common suffixes/prefixes
27 .replace(/^(node|js)|(-?js|-?node)$/g, '')
28 )
29}
30
31/**
32 * Calculate similarity between two strings using Levenshtein distance.

Callers 2

findSimilarPackagesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected