@lionad/port-key 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,6 +8,11 @@
8
8
  <strong>PortKey:A Simple, Practical Port Naming Strategy</strong>
9
9
  </p>
10
10
 
11
+ <p align="center">
12
+ <!-- LANGUAGES=("cn" "es" "fr" "de" "ja" "ko" "ru" "ar" "pt" "it") -->
13
+ <a href="./docs/README.cn.md">中文</a> | <a href="./docs/README.es.md">Español</a> | <a href="./docs/README.fr.md">Français</a> | <a href="./docs/README.de.md">Deutsch</a> | <a href="./docs/README.ja.md">日本語</a> | <a href="./docs/README.ko.md">한국어</a> | <a href="./docs/README.ru.md">Русский</a> | <a href="./docs/README.ar.md">العربية</a> | <a href="./docs/README.pt.md">Português</a> | <a href="./docs/README.it.md">Italiano</a>
14
+ </p>
15
+
11
16
  ## Brief
12
17
 
13
18
  Generate ports with a letter-to-number keyboard mapping
@@ -25,7 +30,7 @@ For example, I have more than ten Nuxt apps on my machine. If they all default t
25
30
 
26
31
  Instead of picking random numbers, map the **project name to numbers based on the keyboard**, so the port is *readable* and *memorable*.
27
32
 
28
- As long as the result is within the valid port range (**0–65535**) and doesn’t hit reserved/system ports, you can just use it.
33
+ As long as the result is within the valid port range (**1024–65535**) and doesn’t hit reserved/system ports, you can just use it.
29
34
 
30
35
  More specifically: using a standard QWERTY keyboard, map each letter to a single digit based on its **row/column position**.
31
36
 
@@ -53,18 +58,39 @@ If a project needs multiple ports (frontend, backend, database, etc.), pick **on
53
58
 
54
59
  ### Valid port range
55
60
 
56
- - Ports must be within **0–65535**.
57
- - For custom services, it’s usually best to use **1024–49151** (non-reserved) or **49152–65535** (private/dynamic).
58
- - As long as the mapped number stays under the limit, it’s valid.
61
+ - Ports must be within **1024–65535** (System ports 0-1023 are blocked).
62
+ - **System Ports (0-1023)**: Assigned by IETF. Strictly blocked.
63
+ - **User Ports (1024-49151)**: Assigned by IANA. Use with caution as they might conflict with registered services.
64
+ - **Dynamic/Private Ports (49152-65535)**: Not assigned. Safest for private or dynamic use.
59
65
 
60
66
  ---
61
67
 
62
68
  ## How to use
63
69
 
70
+ Simple command:
71
+
72
+ ```sh
73
+ npx -y @lionad/port-key <your-project-name>
74
+ ```
75
+
76
+ Or you want a stdio MCP server:
77
+
78
+ ```sh
79
+ npx -y @lionad/port-key-mcp
64
80
  ```
65
- npx @lionad/port-key <your-project-name>
81
+
82
+ ```json
83
+ {
84
+ "mcpServers": {
85
+ "port-key": {
86
+ "command": "npx",
87
+ "args": ["@lionad/port-key-mcp"]
88
+ }
89
+ }
90
+ }
66
91
  ```
67
92
 
93
+
68
94
  ### CLI options
69
95
 
70
96
  - `-m, --map <object>`: custom mapping (JSON or JS-like object literal)
package/bin/port-key.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@lionad/port-key",
3
- "version": "0.1.5",
3
+ "version": "0.2.0",
4
4
  "description": "A simple, practical port naming strategy",
5
5
  "type": "module",
6
+ "types": "./src/port-key.d.ts",
6
7
  "exports": {
7
- ".": "./src/port-key.js"
8
+ ".": {
9
+ "types": "./src/port-key.d.ts",
10
+ "default": "./src/port-key.js"
11
+ }
8
12
  },
9
13
  "keywords": [
10
14
  "portkey",
@@ -26,10 +30,6 @@
26
30
  "README.md",
27
31
  "LICENSE"
28
32
  ],
29
- "scripts": {
30
- "test": "vitest run",
31
- "test:watch": "vitest"
32
- },
33
33
  "author": "Lionad",
34
34
  "license": "ISC",
35
35
  "repository": {
@@ -49,5 +49,10 @@
49
49
  "dependencies": {},
50
50
  "publishConfig": {
51
51
  "registry": "https://registry.npmjs.org/"
52
+ },
53
+ "scripts": {
54
+ "build": "echo 'skip build steps in packages/core'",
55
+ "test": "vitest run",
56
+ "test:watch": "vitest"
52
57
  }
53
- }
58
+ }
@@ -0,0 +1,43 @@
1
+ export type DigitKey = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
2
+
3
+ export type DigitLetterMap = Record<DigitKey | `${DigitKey}`, string>;
4
+
5
+ export type RejectedCandidate = {
6
+ candidate: string;
7
+ reason: string;
8
+ };
9
+
10
+ export type PickPortOptions = {
11
+ preferDigitCount?: number;
12
+ minPort?: number;
13
+ maxPort?: number;
14
+ blockedPorts?: ReadonlySet<number> | number[];
15
+ };
16
+
17
+ export const DEFAULT_MAP: Readonly<DigitLetterMap>;
18
+ export const DEFAULT_BLOCKED_PORTS: ReadonlySet<number>;
19
+
20
+ export function buildReverseMap(map: DigitLetterMap): Map<string, string>;
21
+ export function normalizeInput(text: unknown): string;
22
+ export function mapToDigits(text: unknown, map?: DigitLetterMap): string;
23
+ export function isValidPort(port: unknown): port is number;
24
+
25
+ export function pickPortFromDigits(
26
+ digits: unknown,
27
+ options?: PickPortOptions
28
+ ):
29
+ | { port: number; rejectedCandidates?: RejectedCandidate[] }
30
+ | { port: null; reason: string; rejectedCandidates?: RejectedCandidate[] };
31
+
32
+ export function mapToPort(
33
+ text: unknown,
34
+ map?: DigitLetterMap,
35
+ options?: PickPortOptions
36
+ ): {
37
+ digits: string;
38
+ port: number | null;
39
+ rejectedCandidates?: RejectedCandidate[];
40
+ reason?: string;
41
+ };
42
+
43
+ export function parseUserMap(mapString: unknown): DigitLetterMap;
package/src/port-key.js CHANGED
@@ -14,30 +14,8 @@ const DEFAULT_MAP = Object.freeze({
14
14
  });
15
15
 
16
16
  const DEFAULT_BLOCKED_PORTS = Object.freeze(
17
+ // well-known application ports
17
18
  new Set([
18
- 0,
19
- 20,
20
- 21,
21
- 22,
22
- 23,
23
- 25,
24
- 53,
25
- 67,
26
- 68,
27
- 80,
28
- 110,
29
- 123,
30
- 143,
31
- 161,
32
- 162,
33
- 389,
34
- 443,
35
- 445,
36
- 465,
37
- 587,
38
- 636,
39
- 993,
40
- 995,
41
19
  3000,
42
20
  3001,
43
21
  5000,
@@ -105,6 +83,8 @@ function isValidPort(port) {
105
83
  }
106
84
 
107
85
  function isPortBlocked(port, blockedPorts) {
86
+ // System Ports (0-1023) are assigned by IETF and should not be used.
87
+ if (port < 1024) return true;
108
88
  if (blockedPorts && typeof blockedPorts.has === 'function') {
109
89
  return blockedPorts.has(port);
110
90
  }
@@ -219,6 +199,7 @@ export {
219
199
  normalizeInput,
220
200
  mapToDigits,
221
201
  isValidPort,
202
+ isPortBlocked,
222
203
  pickPortFromDigits,
223
204
  mapToPort,
224
205
  parseUserMap,