Skip to main content
AllDevToolsHub
Back to all patterns

npm Package Name Validation

Validation

Validates npm package names including scoped packages like @org/package.

/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/

How it works

npm package names must be lowercase, URL-safe, and not start with a dot or underscore. Scoped packages start with @scope/.

Test Cases

Should Match

  • react
  • my-package
  • @org/my-package
  • lodash.merge

Should NOT Match

  • MyPackage
  • .hidden
  • _private
  • @/no-scope

Quick Summary

Validates npm package names including scoped packages (@org/name). Names must be lowercase and URL-safe. For strict validation, use the validate-npm-package-name package.

Key Takeaways

Key Takeaways

  • Must be lowercase, npm rejects uppercase package names
  • Scoped packages: @scope/name format
  • Cannot start with a dot or underscore
  • For production validation, use the validate-npm-package-name npm package
Use Cases

When to use it

  • Validating package name inputs in project scaffolding tools
  • Checking package names in monorepo workspace configurations
  • Linting package.json name fields in CI/CD
Watch out

Common Mistakes

  • Using uppercase letters, npm normalizes to lowercase and may reject uppercase names
  • Not handling scoped packages (@org/name) in your validation logic
FAQ

npm Package Name Validation, Frequently Asked

What is a scoped npm package?

Scoped packages are prefixed with @scope/ (e.g., @babel/core). They allow organizations to publish packages under a namespace.

How long can an npm package name be?

npm limits package names to 214 characters total.