@wry-smile/lexid 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 wry-smile
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,179 @@
1
- # Temporary Holding Version
1
+ # LexID
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Composable human-readable identifiers.
4
+
5
+ Semantic dictionaries. Composable patterns. Secure randomness.
6
+
7
+ ```ts
8
+ import { lexid } from '@wry-smile/lexid'
9
+
10
+ lexid()
11
+ // silent-cloud-engine-a7k2m9
12
+ ```
13
+
14
+ [简体中文](README.zh-CN.md)
15
+
16
+ LexID is a TypeScript and JavaScript library for Node.js 22+ and modern browsers.
17
+ It creates public-facing resource IDs, service names, workspace slugs, and test
18
+ names from real words, with zero third-party runtime dependencies.
19
+
20
+ Use the same ESM import in Node.js and in ES2022-capable browsers. Browser
21
+ projects can resolve the package with a bundler or an import map. LexID uses
22
+ `crypto.getRandomValues()` on both platforms, including browsers on plain HTTP.
23
+ Generation reports an error if the runtime lacks this secure random source.
24
+
25
+ ## Install
26
+
27
+ After the npm release, run `pnpm add @wry-smile/lexid` or `npm install @wry-smile/lexid`. For local
28
+ development, build and install the tarball produced by `pnpm pack`.
29
+
30
+ ## CommonJS
31
+
32
+ Use `require` to load the CommonJS build.
33
+
34
+ ```cjs
35
+ const { lexid } = require('@wry-smile/lexid')
36
+ ```
37
+
38
+ ## Generate identifiers
39
+
40
+ By default, `lexid()` selects one of 39 templates uniformly. Identifiers have
41
+ four or five total segments, ending in six lowercase alphanumeric characters.
42
+ The default separator is `-` and the complete identifier can contain up to
43
+ 63 characters. These defaults fit ordinary DNS labels.
44
+
45
+ ```ts
46
+ import { isLexid, lexid, lexids } from '@wry-smile/lexid'
47
+ import { fiveSegmentPatterns, pickPattern } from '@wry-smile/lexid/patterns'
48
+
49
+ const id = lexid({ segments: pickPattern(fiveSegmentPatterns) })
50
+ isLexid(id) // true
51
+ const names = lexids(20)
52
+ ```
53
+
54
+ Use `fourSegmentPatterns` for four total segments. `defaultPatterns` combines
55
+ both collections. A custom template is an ordered array of dictionaries, and
56
+ `pickPattern` selects among templates with nonempty dictionaries.
57
+
58
+ Define a custom template set with ordinary arrays.
59
+
60
+ ```ts
61
+ import {
62
+ adjectives,
63
+ animals,
64
+ colors,
65
+ domains,
66
+ lexid,
67
+ pickPattern,
68
+ technologies,
69
+ } from '@wry-smile/lexid'
70
+
71
+ const patterns = [
72
+ [adjectives, technologies, domains],
73
+ [adjectives, colors, animals],
74
+ ]
75
+ lexid({ segments: pickPattern(patterns) })
76
+ ```
77
+
78
+ ## Compose dictionaries and customize output
79
+
80
+ Use the 28 [built-in dictionaries](skills/lexid/references/dictionaries.md)
81
+ from the root entry or `@wry-smile/lexid/dictionaries`. Mix them with your own arrays
82
+ using `filter` and spread. Each dictionary must contain at least one word.
83
+ Use a single-item dictionary to fix a segment. The suffix adds one segment
84
+ to any number of word segments.
85
+
86
+ ```ts
87
+ import { adjectives, domains, isLexid, lexid, technologies } from '@wry-smile/lexid'
88
+
89
+ const id = lexid({
90
+ segments: [
91
+ adjectives.filter((word) => word.startsWith('s')),
92
+ [...technologies, 'iot'],
93
+ domains.filter((word) => word.length <= 8),
94
+ ['prime'],
95
+ ],
96
+ separator: '_',
97
+ maxLength: 63,
98
+ suffix: ({ words, random }) => words[0].charAt(0) + random.alphanumeric(7),
99
+ })
100
+
101
+ isLexid(id, { separator: '_' }) // true
102
+ ```
103
+
104
+ The allowed separators are `-`, `_`, `.`, and `~`. Use lowercase ASCII
105
+ letters for words and lowercase ASCII letters or digits for the synchronous
106
+ suffix. Overlong results throw. To ensure every result fits, bound the length
107
+ of each dictionary candidate and the suffix before generating.
108
+
109
+ `isLexid` checks structure and length. Match its separator and maximum length
110
+ to the generation settings. See the [API reference](skills/lexid/references/api.md)
111
+ for the public types, defaults, and errors.
112
+
113
+ ## Use secure random tools directly
114
+
115
+ ```ts
116
+ import { random } from '@wry-smile/lexid/random'
117
+
118
+ random.int(100)
119
+ random.pick(['cloud', 'mesh'])
120
+ random.alphanumeric(8)
121
+ random.string('23456789abcdef', 8)
122
+ ```
123
+
124
+ `random` also offers `numeric`, `alphabetic`, and `hexadecimal`. The
125
+ `@wry-smile/lexid/random` and `@wry-smile/lexid/dictionaries` entries load without the generator
126
+ or default templates. Bundlers can tree-shake unused exports. Default
127
+ generation still needs every dictionary referenced by the default templates.
128
+
129
+ ## Agent Integration Skill
130
+
131
+ The [Integration Skill](skills/lexid/SKILL.md) teaches coding agents how to
132
+ import and compose the library. Once the Skill is available in the GitHub
133
+ repository, install it with the [Skills installer](https://github.com/vercel-labs/skills).
134
+
135
+ ```bash
136
+ pnpm dlx skills add wry-smile/lexid --skill lexid
137
+ ```
138
+
139
+ For a local checkout, run `pnpm dlx skills add /path/to/lexid --skill lexid`
140
+ from the application project. The current Skills installer requires Node.js
141
+ 22.20 or later. Install the npm library separately.
142
+
143
+ ## Uniqueness and security
144
+
145
+ Treat generated values as public names. Keep secrets and sensitive data out
146
+ of identifiers, and enforce authorization independently. For uniqueness,
147
+ use a database UNIQUE constraint and bounded retries on collisions.
148
+ Custom suffix security depends on the callback.
149
+
150
+ ## Development
151
+
152
+ Use Node.js 22+ and the pnpm version in `package.json`.
153
+
154
+ ```bash
155
+ pnpm install --frozen-lockfile
156
+ pnpm format:check
157
+ pnpm lint
158
+ pnpm typecheck
159
+ pnpm test
160
+ pnpm build
161
+ pnpm pack
162
+ pnpm test:package ./wry-smile-lexid-0.1.0.tgz
163
+ ```
164
+
165
+ Run `pnpm format` to apply formatting with Oxfmt.
166
+
167
+ Keep dictionaries sorted and frozen. Add or update tests when changing a
168
+ public contract. Keep the Skill examples aligned with the exported API.
169
+
170
+ ## Publishing
171
+
172
+ From a clean, up-to-date checkout, use `pnpm release:publish` to build, check,
173
+ and publish the current version to npm as a public scoped package. Add
174
+ `--dry-run` to preview the publish. For later releases, first run `pnpm release`
175
+ to select a version and create a local commit and tag with Bumpp.
176
+
177
+ ## License
178
+
179
+ [MIT](LICENSE)
@@ -0,0 +1,145 @@
1
+ # LexID
2
+
3
+ 可组合、易读的语义化标识符。
4
+
5
+ 分类词库,可组合模板,密码学安全随机数。
6
+
7
+ ```ts
8
+ import { lexid } from '@wry-smile/lexid'
9
+
10
+ lexid()
11
+ // silent-cloud-engine-a7k2m9
12
+ ```
13
+
14
+ [English](README.md)
15
+
16
+ LexID 是适用于 Node.js 22+ 和现代浏览器的 TypeScript / JavaScript 库。它使用真实英文词汇生成资源 ID、容器和服务名称、工作空间 URL 标识及测试数据,第三方运行时依赖为零。
17
+
18
+ Node.js 和支持 ES2022 的浏览器使用相同的 ESM 入口。浏览器项目可以通过打包器或导入映射解析包名。两个平台都使用 `crypto.getRandomValues()`,普通 HTTP 页面也可使用。若运行环境缺少该安全随机源,生成时会抛出明确错误。
19
+
20
+ ## 安装
21
+
22
+ 库发布到 npm 后,可运行 `pnpm add @wry-smile/lexid` 或 `npm install @wry-smile/lexid`。本地开发时,可先构建,再安装 `pnpm pack` 生成的压缩包。
23
+
24
+ ## CommonJS
25
+
26
+ 使用 `require` 加载 CommonJS 构建。
27
+
28
+ ```cjs
29
+ const { lexid } = require('@wry-smile/lexid')
30
+ ```
31
+
32
+ ## 默认生成与语义模板
33
+
34
+ `lexid()` 从 39 套默认模板中等概率选择一套,生成四段或五段标识符。最后一段为六位小写字母数字后缀。默认用 `-` 连接,总长度上限为 63 个字符,符合普通 DNS 标签格式。
35
+
36
+ ```ts
37
+ import { isLexid, lexid, lexids } from '@wry-smile/lexid'
38
+ import { fourSegmentPatterns, pickPattern } from '@wry-smile/lexid/patterns'
39
+
40
+ const id = lexid({ segments: pickPattern(fourSegmentPatterns) })
41
+ isLexid(id) // true
42
+ const names = lexids(20)
43
+ ```
44
+
45
+ 使用 `fiveSegmentPatterns` 可固定为五段。`defaultPatterns` 包含两组默认模板。自定义模板是有序词库数组,`pickPattern` 会跳过空模板和包含空词库的模板。
46
+
47
+ 用普通数组定义自己的模板集合。
48
+
49
+ ```ts
50
+ import {
51
+ adjectives,
52
+ animals,
53
+ colors,
54
+ domains,
55
+ lexid,
56
+ pickPattern,
57
+ technologies,
58
+ } from '@wry-smile/lexid'
59
+
60
+ const patterns = [
61
+ [adjectives, technologies, domains],
62
+ [adjectives, colors, animals],
63
+ ]
64
+ lexid({ segments: pickPattern(patterns) })
65
+ ```
66
+
67
+ ## 组合词库与自定义规则
68
+
69
+ 从根入口或 `@wry-smile/lexid/dictionaries` 导入 28 个[内置词库](skills/lexid/references/dictionaries.md)。可以用 `filter` 根据字符位置或长度筛选,用展开运算符合并词库,也可以直接传入自己的数组。词库至少包含一个单词。单元素数组可固定一段,总段数等于词库数加一。
70
+
71
+ ```ts
72
+ import { adjectives, domains, isLexid, lexid, technologies } from '@wry-smile/lexid'
73
+
74
+ const id = lexid({
75
+ segments: [
76
+ adjectives.filter((word) => word.startsWith('s')),
77
+ [...technologies, 'iot'],
78
+ domains.filter((word) => word.length <= 8),
79
+ ['prime'],
80
+ ],
81
+ separator: '_',
82
+ maxLength: 63,
83
+ suffix: ({ words, random }) => words[0].charAt(0) + random.alphanumeric(7),
84
+ })
85
+
86
+ isLexid(id, { separator: '_' }) // true
87
+ ```
88
+
89
+ 连接符支持 `-`、`_`、`.` 和 `~`。单词段只允许小写 ASCII 字母,后缀回调须同步返回小写 ASCII 字母数字。结果超长会抛出错误。若所有结果都必须满足上限,请提前限制每段单词和后缀长度。
90
+
91
+ `isLexid` 校验结构和长度。使用自定义格式时,请传入与生成时相同的连接符和上限。[API 参考](skills/lexid/references/api.md)列出了导出类型、默认值和错误行为。
92
+
93
+ ## 独立随机工具
94
+
95
+ ```ts
96
+ import { random } from '@wry-smile/lexid/random'
97
+
98
+ random.int(100)
99
+ random.pick(['cloud', 'mesh'])
100
+ random.alphanumeric(8)
101
+ random.string('23456789abcdef', 8)
102
+ ```
103
+
104
+ `random` 还提供 `numeric`、`alphabetic` 和 `hexadecimal`。随机工具和词库子入口可独立加载。支持 Tree Shaking 的打包器可以移除未使用的导出,默认生成仍依赖默认模板引用的所有词库。
105
+
106
+ ## Agent 集成 Skill
107
+
108
+ [集成 Skill](skills/lexid/SKILL.md)为编码 Agent 提供安装、API 选择和 TypeScript 集成示例。Skill 提交到 GitHub 仓库后,可通过 [Skills 安装工具](https://github.com/vercel-labs/skills)安装。
109
+
110
+ ```bash
111
+ pnpm dlx skills add wry-smile/lexid --skill lexid
112
+ ```
113
+
114
+ 使用本地检出时,在应用项目中运行 `pnpm dlx skills add /path/to/lexid --skill lexid`。当前 Skills 安装工具需要 Node.js 22.20 或更高版本。应用项目中的 LexID 依赖需要独立安装。
115
+
116
+ ## 唯一性与安全
117
+
118
+ 把生成结果视作公开名称。凭证和敏感信息应独立存储,资源权限应独立校验。业务需要唯一标识时,使用数据库 UNIQUE 约束,并在标识冲突时有界重试。自定义后缀的随机安全性取决于回调实现。
119
+
120
+ ## 开发与贡献
121
+
122
+ 使用 Node.js 22+ 和 `package.json` 指定的 pnpm 版本。
123
+
124
+ ```bash
125
+ pnpm install --frozen-lockfile
126
+ pnpm format:check
127
+ pnpm lint
128
+ pnpm typecheck
129
+ pnpm test
130
+ pnpm build
131
+ pnpm pack
132
+ pnpm test:package ./wry-smile-lexid-0.1.0.tgz
133
+ ```
134
+
135
+ 运行 `pnpm format` 可用 Oxfmt 格式化代码。
136
+
137
+ 维护词库时保持排序、去重和不可变。修改公共契约时同步更新测试和 Skill 示例。
138
+
139
+ ## 发布
140
+
141
+ 在工作区干净且与远端同步后,运行 `pnpm release:publish`。命令会执行检查和构建,并把当前版本作为公开 scoped 包发布到 npm。附加 `--dry-run` 可预览发布。后续版本先运行 `pnpm release`,通过 Bumpp 选择版本,并在本地创建版本提交和标签。
142
+
143
+ ## 许可证
144
+
145
+ [MIT](LICENSE)