This package provides a highly focused and reliable regular expression specifically designed to validate NPM package names according to the official NPM registry rules. It is currently stable at version 5.0.0 and receives regular maintenance, with major version bumps primarily driven by Node.js End-of-Life (EOL) cycles to ensure compatibility with modern runtime environments. The library differentiates itself by offering a pre-tested, up-to-date regex, saving developers from manually crafting and maintaining complex validation logic, which can be prone to errors as NPM naming conventions evolve. It is a lightweight utility intended for scenarios requiring strict package name validation, such as package managers, build tools, or user input forms, and ships with TypeScript types for enhanced developer experience.
npm install package-name-regexVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to import and use the `packageNameRegex` to test various strings for NPM package name validity.
Upgrade your Node.js runtime to version 22 or later. If you need to support older Node.js environments, consider using an earlier major version of `package-name-regex`.
Ensure your Node.js environment is at least version 18. For environments that cannot upgrade, pin the `package-name-regex` dependency to `<4.0.0`.
If using Node.js 12 or earlier, do not upgrade to v3.0.0+. For newer Node.js, ensure your project uses `import` statements or configure your `package.json` with `"type": "module"` for ESM compatibility. For CommonJS projects, use dynamic `import()` or stick to `package-name-regex@<3.0.0`.
Always invoke the `test` method directly on the `packageNameRegex` object. Avoid trying to use it as a standalone function or assuming it returns a boolean directly without the method call.
Ensure you are using `import packageNameRegex from 'package-name-regex';` or `import { packageNameRegex } from 'package-name-regex';` and that your environment supports ESM. Also, verify that the variable you are calling `.test()` on is indeed the imported regex.Either convert your project to an ESM module by adding `"type": "module"` to your `package.json`, use dynamic `import('package-name-regex')` in your CJS code, or downgrade `package-name-regex` to a version prior to 3.0.0 if CJS is strictly required for your project.No dependency data recorded yet.