|
| 1 | + |
| 2 | + |
| 3 | +<h1 align="center"> NPM package name Validator</h1> |
| 4 | +<p align="center">validate-npm-package-name</p> |
| 5 | +<p align="center">This package exports functions and few elements.</p> |
| 6 | + |
| 7 | +<!-- <img alt="Crates.io Size" src="https://img.shields.io/bundlephobia/size/@better/validate-npm-package-name"> --> |
| 8 | +<hr/> |
| 9 | + |
| 10 | +## **nameValidator** |
| 11 | + |
| 12 | +```typescript |
| 13 | +import { nameValidator } from "@betternpm/validate-npm-package-name"; |
| 14 | +nameValidator("examplename"); |
| 15 | +nameValidator("some-package"); |
| 16 | +nameValidator("example.com"); |
| 17 | +nameValidator("under_score"); |
| 18 | +nameValidator("123numeric"); |
| 19 | +nameValidator("@npm/thingy"); |
| 20 | +nameValidator("@jane/foo.js"); |
| 21 | +``` |
| 22 | + |
| 23 | +```typescript |
| 24 | +{ |
| 25 | + validForNewPackages: boolean; |
| 26 | + validForOldPackages: boolean; |
| 27 | + errors?:TMyError[] |
| 28 | + warnings?:TMyError[] |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +<hr/> |
| 33 | + |
| 34 | +## List of Contents |
| 35 | + |
| 36 | +- [**nameValidator**](#namevalidator) |
| 37 | +- [List of Contents](#list-of-contents) |
| 38 | +- [Exports](#exports) |
| 39 | +- [Naming Rules (Error Codes and Descriptions)](#naming-rules-error-codes-and-descriptions) |
| 40 | + |
| 41 | +## Exports |
| 42 | + |
| 43 | +| Export | Description | Return Type | |
| 44 | +| ---------------------- | ---------------------------------------------- | --------------------------------- | |
| 45 | +| nameValidator | NPM package name Validator | `object` | |
| 46 | +| isScopedPackage | NPM package name Scope Validator | `boolean` | |
| 47 | +| SCOPED_PACKAGE_PATTERN | RegExp pattern checking Scope | `RegExp` | |
| 48 | +| MyErrorList | List of Errors which `nameValidator` can throw | `as const satisfies TMyErrorList` | |
| 49 | +| BLACK_LIST | Black listed Names | `Set<string>` | |
| 50 | + |
| 51 | +nameValidator MyErrorList BLACK_LIST SCOPED_PACKAGE_PATTERN |
| 52 | + |
| 53 | +## Naming Rules (Error Codes and Descriptions) |
| 54 | + |
| 55 | +Below is a table of errors that indicate when invalid `npm` package names do not conform to the required rules: |
| 56 | + |
| 57 | +| Error Code | Description | Don't | |
| 58 | +| ------------------------------ | ------------------------------------------------------------------------------------ | ---------------------------------------------------------- | |
| 59 | +| `NULL_NAME` | Package name cannot be null. | `null` | |
| 60 | +| `UNDEFINED_NAME` | Package name cannot be undefined. | `undefined` \| `void 0` | |
| 61 | +| `INVALID_TYPE` | Package name must be a string. | Non-string types (e.g., numbers) | |
| 62 | +| `TOO_SHORT_LENGTH_NAME` | Package name length should be greater than zero. | An empty string | |
| 63 | +| `TOO_LONG_LENGTH_NAME` | Package name length cannot exceed 214 characters. | Names longer than 214 characters | |
| 64 | +| `CANNOT_START_WITH_PERIOD` | Package name cannot start with a period. | Names starting with `.` | |
| 65 | +| `CANNOT_START_WITH_UNDERSCORE` | Package name cannot start with an underscore. | Names starting with `_` | |
| 66 | +| `CANNOT_HAVE_SPACES` | Package name cannot contain spaces. | Names with any spaces | |
| 67 | +| `CORE_MODULE_NAME` | Package 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` | |
| 68 | +| `NO_CAPITAL_LETTERS` | All characters in the package name must be lowercase. | Uppercase or mixed case names | |
| 69 | +| `SPECIAL_CHARACTERS` | Package name cannot contain special characters (~'!()\*). | Names containing any of these characters: `~'!()*` | |
| 70 | +| `URL_FRIENDLY` | Package name must only contain URL-friendly characters. | Names with non-URL-friendly characters | |
| 71 | +| `BLACK_LISTED` | Package name cannot be on the blacklist of prohibited names. | Names that are explicitly prohibited | |
0 commit comments