Skip to content

Commit a8516bc

Browse files
🎉 Feat(@betternpm/validate-npm-package-name): add
ameValidator, isScopedPackage Functions and SCOPED_PACKAGE_PATTERN, MyErrorList, BLACK_LIST to exports!
1 parent e8e444e commit a8516bc

23 files changed

Lines changed: 8497 additions & 797 deletions

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ About packages:
3333
- ♻️ Minified
3434
- ⚠️ Error Handler (Custom - `oh-my-error`, why this?)
3535
- ✅ Support JS/TS & CJS/ESM
36+
- 🐒 Rewriten Test units from tap -> vitest
3637
- 📝 Debug Logging (Only for CLI commands)
3738

3839
## Packages

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030
"pre": "turbo pre",
3131
"pre:husky": "git add . && lint-staged",
3232
"prepare": "husky",
33-
"test": "echo \"Error: no test specified\""
33+
"test": "turbo test"
3434
},
3535
"devDependencies": {
3636
"@changesets/cli": "^2.27.7",
37+
"@types/lint-staged": "~13.3.0",
3738
"commitsmile": "^0.6.1",
3839
"globals": "^15.9.0",
3940
"husky": "^9.1.5",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ESLINT_USE_FLAT_CONFIG = true
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.npmignore
2+
.npmrc
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
2+
registry=https://registry.npmjs.org/
3+
always-auth=true
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# @myutilia/env
2+
3+
## 1.0.0
4+
5+
### Major Changes
6+
7+
- Release!
8+
9+
## 0.1.1
10+
11+
### Patch Changes
12+
13+
- change img in readme
14+
15+
## 0.1.0
16+
17+
### Minor Changes
18+
19+
- add `isPortFree` function!
20+
21+
## 0.1.2
22+
23+
### Patch Changes
24+
25+
- add Readme.MD
26+
27+
## 0.1.1
28+
29+
### Patch Changes
30+
31+
- remove unnecessary files
32+
33+
## 0.1.0
34+
35+
### Minor Changes
36+
37+
- add `os` function!
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
![image](https://github.com/user-attachments/assets/985f8c86-4dad-400f-a5fa-16f57d0546d8)
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 |
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"indent": 4,
3+
"remove": ["devDependencies", "lint-staged", "bin"],
4+
"replace": {
5+
"type": "commonjs",
6+
"scripts": {
7+
"npm:postpack": "clean-package restore"
8+
},
9+
"exports": {
10+
".": {
11+
"types": {
12+
"import": "./index.d.mts",
13+
"require": "./index.d.ts"
14+
},
15+
"import": "./index.mjs",
16+
"require": "./index.js",
17+
"*": "./*"
18+
}
19+
}
20+
}
21+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { defineConfig } from "tsup";
2+
3+
export default defineConfig({
4+
entry: ["src/index.ts"],
5+
target: "es2022",
6+
format: ["esm"],
7+
clean: true,
8+
splitting: false,
9+
platform: "node",
10+
keepNames: true,
11+
12+
dts: true,
13+
tsconfig: "./tsconfig.json",
14+
15+
banner: ({ format }) => {
16+
if (format === "esm") {
17+
const banner = `
18+
import { createRequire } from "node:module";
19+
const require = createRequire(import.meta.url);
20+
`;
21+
22+
return { js: banner };
23+
}
24+
}
25+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import config from "./tsup.base";
2+
import { defineConfig } from "tsup";
3+
4+
export default defineConfig({
5+
...config,
6+
outDir: "lib",
7+
watch: ["src"]
8+
});

0 commit comments

Comments
 (0)