1.0.1 • Published 9 months ago

@betternpm/validate-npm-package-name v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

image

nameValidator

import { nameValidator } from "@betternpm/validate-npm-package-name";
nameValidator("examplename");
nameValidator("some-package");
nameValidator("example.com");
nameValidator("under_score");
nameValidator("123numeric");
nameValidator("@npm/thingy");
nameValidator("@jane/foo.js");
{
  validForNewPackages: boolean;
  validForOldPackages: boolean;
  errors?:TMyError[]
  warnings?:TMyError[]
}

List of Contents

Exports

ExportDescriptionReturn Type
nameValidatorNPM package name Validatorobject
isScopedPackageNPM package name Scope Validatorboolean
SCOPED_PACKAGE_PATTERNRegExp pattern checking ScopeRegExp
MyErrorListList of Errors which nameValidator can throwas const satisfies TMyErrorList
BLACK_LISTBlack listed NamesSet<string>

nameValidator MyErrorList BLACK_LIST SCOPED_PACKAGE_PATTERN

Naming Rules (Error Codes and Descriptions)

Below is a table of errors that indicate when invalid npm package names do not conform to the required rules:

Error CodeDescriptionDon't
NULL_NAMEPackage name cannot be null.null
UNDEFINED_NAMEPackage name cannot be undefined.undefined | void 0
INVALID_TYPEPackage name must be a string.Non-string types (e.g., numbers)
TOO_SHORT_LENGTH_NAMEPackage name length should be greater than zero.An empty string
TOO_LONG_LENGTH_NAMEPackage name length cannot exceed 214 characters.Names longer than 214 characters
CANNOT_START_WITH_PERIODPackage name cannot start with a period.Names starting with .
CANNOT_START_WITH_UNDERSCOREPackage name cannot start with an underscore.Names starting with _
CANNOT_HAVE_SPACESPackage name cannot contain spaces.Names with any spaces
CORE_MODULE_NAMEPackage name cannot be the same as a node.js/io.js core module or a reserved name.Names like http, stream, node_modules, favicon.ico
NO_CAPITAL_LETTERSAll characters in the package name must be lowercase.Uppercase or mixed case names
SPECIAL_CHARACTERSPackage name cannot contain special characters (~'!()*).Names containing any of these characters: ~'!()*
URL_FRIENDLYPackage name must only contain URL-friendly characters.Names with non-URL-friendly characters
BLACK_LISTEDPackage name cannot be on the blacklist of prohibited names.Names that are explicitly prohibited