@wry-smile/lexid 0.1.0 → 0.1.1
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 +38 -5
- package/README.zh-CN.md +37 -4
- package/dist/dictionaries.d.cts +1 -1
- package/dist/dictionaries.d.mts +1 -1
- package/dist/index-BGuJLQZS.d.mts +19 -0
- package/dist/{index-BYKbOu0-.d.mts → index-CBG7Ua1f.d.mts} +1 -1
- package/dist/{index-vEdKNRFE.d.cts → index-CvKRlqot.d.cts} +1 -1
- package/dist/index-kBjONiKH.d.cts +19 -0
- package/dist/index.cjs +19 -9
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +18 -10
- package/dist/{patterns-QE6RAPxp.cjs → patterns-DC47BwpJ.cjs} +21 -5
- package/dist/{patterns-DUQti-VI.mjs → patterns-H0XRwCVB.mjs} +10 -6
- package/dist/patterns.cjs +3 -1
- package/dist/patterns.d.cts +2 -2
- package/dist/patterns.d.mts +2 -2
- package/dist/patterns.mjs +2 -2
- package/dist/random.d.cts +1 -1
- package/dist/random.d.mts +1 -1
- package/dist/{types-BMRtYBrz.d.mts → types-BsCTggdZ.d.mts} +4 -2
- package/dist/{types-CHH8wNDe.d.cts → types-DKjF96ZA.d.cts} +4 -2
- package/package.json +1 -1
- package/skills/lexid/SKILL.md +14 -14
- package/skills/lexid/references/api.md +17 -12
- package/skills/lexid/references/customization.md +35 -1
- package/skills/lexid/references/patterns.md +20 -7
- package/dist/index-Bd4TyP0I.d.mts +0 -15
- package/dist/index-D0Yd4QNB.d.cts +0 -15
package/README.md
CHANGED
|
@@ -44,15 +44,15 @@ The default separator is `-` and the complete identifier can contain up to
|
|
|
44
44
|
|
|
45
45
|
```ts
|
|
46
46
|
import { isLexid, lexid, lexids } from '@wry-smile/lexid'
|
|
47
|
-
import {
|
|
47
|
+
import { fourWordPatterns, pickPattern } from '@wry-smile/lexid/patterns'
|
|
48
48
|
|
|
49
|
-
const id = lexid({ segments: pickPattern(
|
|
49
|
+
const id = lexid({ segments: pickPattern(fourWordPatterns) })
|
|
50
50
|
isLexid(id) // true
|
|
51
51
|
const names = lexids(20)
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
Use `
|
|
55
|
-
both collections. A custom template is an ordered array of dictionaries, and
|
|
54
|
+
Use `threeWordPatterns` for three word segments or `fourWordPatterns` for four.
|
|
55
|
+
The default suffix adds one segment. `defaultPatterns` combines both collections. A custom template is an ordered array of dictionaries, and
|
|
56
56
|
`pickPattern` selects among templates with nonempty dictionaries.
|
|
57
57
|
|
|
58
58
|
Define a custom template set with ordinary arrays.
|
|
@@ -80,7 +80,7 @@ lexid({ segments: pickPattern(patterns) })
|
|
|
80
80
|
Use the 28 [built-in dictionaries](skills/lexid/references/dictionaries.md)
|
|
81
81
|
from the root entry or `@wry-smile/lexid/dictionaries`. Mix them with your own arrays
|
|
82
82
|
using `filter` and spread. Each dictionary must contain at least one word.
|
|
83
|
-
Use a single-item dictionary to fix a segment.
|
|
83
|
+
Use a single-item dictionary to fix a segment. By default, the suffix adds one segment
|
|
84
84
|
to any number of word segments.
|
|
85
85
|
|
|
86
86
|
```ts
|
|
@@ -110,6 +110,39 @@ of each dictionary candidate and the suffix before generating.
|
|
|
110
110
|
to the generation settings. See the [API reference](skills/lexid/references/api.md)
|
|
111
111
|
for the public types, defaults, and errors.
|
|
112
112
|
|
|
113
|
+
## Arrange word segments
|
|
114
|
+
|
|
115
|
+
For English-style names, put broad descriptors first and the object being
|
|
116
|
+
named last. For operational names, put the field you scan or sort by first,
|
|
117
|
+
such as the environment or service.
|
|
118
|
+
|
|
119
|
+
| Goal | Dictionary order | Example |
|
|
120
|
+
| ---------------------- | --------------------------------------- | ---------------------- |
|
|
121
|
+
| Readable resource name | `adjectives`, `technologies`, `domains` | `silent-cloud-engine` |
|
|
122
|
+
| Nature-inspired name | `colors`, `nature`, `animals` | `silver-forest-wolf` |
|
|
123
|
+
| Group by environment | `['staging']`, `domains`, `modifiers` | `staging-worker-prime` |
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { domains, lexid, modifiers } from '@wry-smile/lexid'
|
|
127
|
+
|
|
128
|
+
lexid({
|
|
129
|
+
segments: [['staging'], domains.filter((word) => word.length <= 6), modifiers],
|
|
130
|
+
suffix: false,
|
|
131
|
+
})
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Omit the suffix
|
|
135
|
+
|
|
136
|
+
Set `suffix: false` to generate only the word segments. Use `hasSuffix: false` to validate names in this format.
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
import { isLexid, lexid } from '@wry-smile/lexid'
|
|
140
|
+
|
|
141
|
+
const id = lexid({ segments: [['cloud'], ['engine']], suffix: false })
|
|
142
|
+
// cloud-engine
|
|
143
|
+
isLexid(id, { hasSuffix: false }) // true
|
|
144
|
+
```
|
|
145
|
+
|
|
113
146
|
## Use secure random tools directly
|
|
114
147
|
|
|
115
148
|
```ts
|
package/README.zh-CN.md
CHANGED
|
@@ -35,14 +35,14 @@ const { lexid } = require('@wry-smile/lexid')
|
|
|
35
35
|
|
|
36
36
|
```ts
|
|
37
37
|
import { isLexid, lexid, lexids } from '@wry-smile/lexid'
|
|
38
|
-
import {
|
|
38
|
+
import { threeWordPatterns, pickPattern } from '@wry-smile/lexid/patterns'
|
|
39
39
|
|
|
40
|
-
const id = lexid({ segments: pickPattern(
|
|
40
|
+
const id = lexid({ segments: pickPattern(threeWordPatterns) })
|
|
41
41
|
isLexid(id) // true
|
|
42
42
|
const names = lexids(20)
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
`threeWordPatterns` 和 `fourWordPatterns` 分别提供三个和四个单词段。启用后缀时,总段数加一。`defaultPatterns` 包含两组默认模板。自定义模板是有序词库数组,`pickPattern` 会跳过空模板和包含空词库的模板。
|
|
46
46
|
|
|
47
47
|
用普通数组定义自己的模板集合。
|
|
48
48
|
|
|
@@ -66,7 +66,7 @@ lexid({ segments: pickPattern(patterns) })
|
|
|
66
66
|
|
|
67
67
|
## 组合词库与自定义规则
|
|
68
68
|
|
|
69
|
-
从根入口或 `@wry-smile/lexid/dictionaries` 导入 28 个[内置词库](skills/lexid/references/dictionaries.md)。可以用 `filter`
|
|
69
|
+
从根入口或 `@wry-smile/lexid/dictionaries` 导入 28 个[内置词库](skills/lexid/references/dictionaries.md)。可以用 `filter` 根据字符位置或长度筛选,用展开运算符合并词库,也可以直接传入自己的数组。`segments[i]` 是第 `i + 1` 段的候选词库,每段独立抽词。词库至少包含一个单词。单元素数组可固定一段,启用后缀时,总段数等于词库数加一。
|
|
70
70
|
|
|
71
71
|
```ts
|
|
72
72
|
import { adjectives, domains, isLexid, lexid, technologies } from '@wry-smile/lexid'
|
|
@@ -86,10 +86,43 @@ const id = lexid({
|
|
|
86
86
|
isLexid(id, { separator: '_' }) // true
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
+
保留内置语义模板时,可以先对模板集合 `map`,逐段 `filter` 候选词,再调用 `pickPattern`。例如给 `fourWordPatterns` 的四个单词段分别设置长度上限。后缀独立配置。参见[逐段筛选内置模板](skills/lexid/references/customization.md#filter-built-in-templates-by-position)。
|
|
90
|
+
|
|
89
91
|
连接符支持 `-`、`_`、`.` 和 `~`。单词段只允许小写 ASCII 字母,后缀回调须同步返回小写 ASCII 字母数字。结果超长会抛出错误。若所有结果都必须满足上限,请提前限制每段单词和后缀长度。
|
|
90
92
|
|
|
91
93
|
`isLexid` 校验结构和长度。使用自定义格式时,请传入与生成时相同的连接符和上限。[API 参考](skills/lexid/references/api.md)列出了导出类型、默认值和错误行为。
|
|
92
94
|
|
|
95
|
+
## 单词段怎么排列
|
|
96
|
+
|
|
97
|
+
想让名字读起来像英文短语,可以先放修饰词或背景词,最后放要描述的对象。如果主要在列表里查找或排序,就把最常用的筛选字段放在第一段,比如环境或服务名。
|
|
98
|
+
|
|
99
|
+
| 用途 | 词库顺序 | 示例 |
|
|
100
|
+
| ------------ | ----------------------------------------- | ---------------------- |
|
|
101
|
+
| 易读的资源名 | `adjectives` → `technologies` → `domains` | `silent-cloud-engine` |
|
|
102
|
+
| 自然风格 | `colors` → `nature` → `animals` | `silver-forest-wolf` |
|
|
103
|
+
| 按环境归类 | `['staging']` → `domains` → `modifiers` | `staging-worker-prime` |
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import { domains, lexid, modifiers } from '@wry-smile/lexid'
|
|
107
|
+
|
|
108
|
+
lexid({
|
|
109
|
+
segments: [['staging'], domains.filter((word) => word.length <= 6), modifiers],
|
|
110
|
+
suffix: false,
|
|
111
|
+
})
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## 省略后缀
|
|
115
|
+
|
|
116
|
+
设置 `suffix: false` 可只生成单词段。校验这类名称时,传入 `hasSuffix: false`。
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { isLexid, lexid } from '@wry-smile/lexid'
|
|
120
|
+
|
|
121
|
+
const id = lexid({ segments: [['cloud'], ['engine']], suffix: false })
|
|
122
|
+
// cloud-engine
|
|
123
|
+
isLexid(id, { hasSuffix: false }) // true
|
|
124
|
+
```
|
|
125
|
+
|
|
93
126
|
## 独立随机工具
|
|
94
127
|
|
|
95
128
|
```ts
|
package/dist/dictionaries.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as categories, D as adverbs, E as animals, O as adjectives, S as colors, T as architecture, _ as gemstones, a as space, b as domains, c as nouns, d as music, f as modifiers, g as geography, h as insects, i as technologies, l as nature, m as instruments, n as verbs, o as seasons, p as materials, r as trees, s as plants, t as weather, u as mythology, v as flowers, w as birds, x as directions, y as elements } from "./index-
|
|
1
|
+
import { C as categories, D as adverbs, E as animals, O as adjectives, S as colors, T as architecture, _ as gemstones, a as space, b as domains, c as nouns, d as music, f as modifiers, g as geography, h as insects, i as technologies, l as nature, m as instruments, n as verbs, o as seasons, p as materials, r as trees, s as plants, t as weather, u as mythology, v as flowers, w as birds, x as directions, y as elements } from "./index-CvKRlqot.cjs";
|
|
2
2
|
export { adjectives, adverbs, animals, architecture, birds, categories, colors, directions, domains, elements, flowers, gemstones, geography, insects, instruments, materials, modifiers, music, mythology, nature, nouns, plants, seasons, space, technologies, trees, verbs, weather };
|
package/dist/dictionaries.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as categories, D as adverbs, E as animals, O as adjectives, S as colors, T as architecture, _ as gemstones, a as space, b as domains, c as nouns, d as music, f as modifiers, g as geography, h as insects, i as technologies, l as nature, m as instruments, n as verbs, o as seasons, p as materials, r as trees, s as plants, t as weather, u as mythology, v as flowers, w as birds, x as directions, y as elements } from "./index-
|
|
1
|
+
import { C as categories, D as adverbs, E as animals, O as adjectives, S as colors, T as architecture, _ as gemstones, a as space, b as domains, c as nouns, d as music, f as modifiers, g as geography, h as insects, i as technologies, l as nature, m as instruments, n as verbs, o as seasons, p as materials, r as trees, s as plants, t as weather, u as mythology, v as flowers, w as birds, x as directions, y as elements } from "./index-CBG7Ua1f.mjs";
|
|
2
2
|
export { adjectives, adverbs, animals, architecture, birds, categories, colors, directions, domains, elements, flowers, gemstones, geography, insects, instruments, materials, modifiers, music, mythology, nature, nouns, plants, seasons, space, technologies, trees, verbs, weather };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { a as Patterns, i as Pattern } from "./types-BsCTggdZ.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/patterns/four-word.d.ts
|
|
4
|
+
declare const fourWordPatterns: Patterns;
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/patterns/three-word.d.ts
|
|
7
|
+
declare const threeWordPatterns: Patterns;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/patterns/pick-pattern.d.ts
|
|
10
|
+
declare function pickPattern(patterns: Patterns): Pattern;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/patterns/index.d.ts
|
|
13
|
+
/** @deprecated Use threeWordPatterns. */
|
|
14
|
+
declare const fourSegmentPatterns: Patterns;
|
|
15
|
+
/** @deprecated Use fourWordPatterns. */
|
|
16
|
+
declare const fiveSegmentPatterns: Patterns;
|
|
17
|
+
declare const defaultPatterns: Patterns;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { threeWordPatterns as a, pickPattern as i, fiveSegmentPatterns as n, fourWordPatterns as o, fourSegmentPatterns as r, defaultPatterns as t };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { a as Patterns, i as Pattern } from "./types-DKjF96ZA.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/patterns/four-word.d.ts
|
|
4
|
+
declare const fourWordPatterns: Patterns;
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/patterns/three-word.d.ts
|
|
7
|
+
declare const threeWordPatterns: Patterns;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/patterns/pick-pattern.d.ts
|
|
10
|
+
declare function pickPattern(patterns: Patterns): Pattern;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/patterns/index.d.ts
|
|
13
|
+
/** @deprecated Use threeWordPatterns. */
|
|
14
|
+
declare const fourSegmentPatterns: Patterns;
|
|
15
|
+
/** @deprecated Use fourWordPatterns. */
|
|
16
|
+
declare const fiveSegmentPatterns: Patterns;
|
|
17
|
+
declare const defaultPatterns: Patterns;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { threeWordPatterns as a, pickPattern as i, fiveSegmentPatterns as n, fourWordPatterns as o, fourSegmentPatterns as r, defaultPatterns as t };
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_dictionaries = require("./dictionaries-DwfVfnJX.cjs");
|
|
3
|
-
const require_patterns = require("./patterns-
|
|
3
|
+
const require_patterns = require("./patterns-DC47BwpJ.cjs");
|
|
4
4
|
const require_random = require("./random.cjs");
|
|
5
5
|
//#region src/suffix.ts
|
|
6
6
|
const defaultSuffix = ({ random }) => random.alphanumeric(6);
|
|
@@ -40,8 +40,11 @@ function validateSegments(segments) {
|
|
|
40
40
|
}
|
|
41
41
|
function isLexid(value, options = {}) {
|
|
42
42
|
const { separator, maxLength } = formatOptions(options);
|
|
43
|
+
const { hasSuffix = true } = options;
|
|
44
|
+
if (typeof hasSuffix !== "boolean") throw new TypeError("hasSuffix must be a boolean");
|
|
43
45
|
if (typeof value !== "string" || value.length > maxLength) return false;
|
|
44
46
|
const parts = value.split(separator);
|
|
47
|
+
if (!hasSuffix) return parts.every(isWord);
|
|
45
48
|
const suffix = parts.pop();
|
|
46
49
|
return parts.length > 0 && isSuffix(suffix) && parts.every(isWord);
|
|
47
50
|
}
|
|
@@ -50,7 +53,7 @@ function isLexid(value, options = {}) {
|
|
|
50
53
|
function lexid(options = {}) {
|
|
51
54
|
const { separator, maxLength } = formatOptions(options);
|
|
52
55
|
const { suffix = defaultSuffix } = options;
|
|
53
|
-
if (typeof suffix !== "function") throw new TypeError("suffix must be a function");
|
|
56
|
+
if (suffix !== false && typeof suffix !== "function") throw new TypeError("suffix must be false or a function");
|
|
54
57
|
const { segments = require_patterns.pickPattern(require_patterns.defaultPatterns) } = options;
|
|
55
58
|
validateSegments(segments);
|
|
56
59
|
const words = [];
|
|
@@ -58,16 +61,21 @@ function lexid(options = {}) {
|
|
|
58
61
|
const dictionary = segments[index];
|
|
59
62
|
words.push(dictionary[require_random.random.int(dictionary.length)]);
|
|
60
63
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
let parts = words;
|
|
65
|
+
if (suffix !== false) {
|
|
66
|
+
const tail = suffix(Object.freeze({
|
|
67
|
+
words: Object.freeze(words),
|
|
68
|
+
random: require_random.random
|
|
69
|
+
}));
|
|
70
|
+
if (!isSuffix(tail)) throw new TypeError("suffix must return a nonempty string containing lowercase ASCII letters and digits only");
|
|
71
|
+
parts = [...words, tail];
|
|
72
|
+
}
|
|
73
|
+
const value = parts.join(separator);
|
|
67
74
|
if (value.length > maxLength) throw new RangeError(`Generated identifier length ${value.length} exceeds maxLength ${maxLength}`);
|
|
68
75
|
if (!isLexid(value, {
|
|
69
76
|
separator,
|
|
70
|
-
maxLength
|
|
77
|
+
maxLength,
|
|
78
|
+
hasSuffix: suffix !== false
|
|
71
79
|
})) throw new TypeError("Generated identifier contains an invalid segment");
|
|
72
80
|
return value;
|
|
73
81
|
}
|
|
@@ -92,6 +100,7 @@ exports.elements = require_dictionaries.elements;
|
|
|
92
100
|
exports.fiveSegmentPatterns = require_patterns.fiveSegmentPatterns;
|
|
93
101
|
exports.flowers = require_dictionaries.flowers;
|
|
94
102
|
exports.fourSegmentPatterns = require_patterns.fourSegmentPatterns;
|
|
103
|
+
exports.fourWordPatterns = require_patterns.fourWordPatterns;
|
|
95
104
|
exports.gemstones = require_dictionaries.gemstones;
|
|
96
105
|
exports.geography = require_dictionaries.geography;
|
|
97
106
|
exports.insects = require_dictionaries.insects;
|
|
@@ -111,6 +120,7 @@ exports.random = require_random.random;
|
|
|
111
120
|
exports.seasons = require_dictionaries.seasons;
|
|
112
121
|
exports.space = require_dictionaries.space;
|
|
113
122
|
exports.technologies = require_dictionaries.technologies;
|
|
123
|
+
exports.threeWordPatterns = require_patterns.threeWordPatterns;
|
|
114
124
|
exports.trees = require_dictionaries.trees;
|
|
115
125
|
exports.verbs = require_dictionaries.verbs;
|
|
116
126
|
exports.weather = require_dictionaries.weather;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { a as Patterns, c as SuffixContext, i as Pattern, l as SuffixGenerator, n as LexidOptions, o as RandomUtils, r as LexidValidateOptions, s as Segments, t as Dictionary } from "./types-
|
|
2
|
-
import { C as categories, D as adverbs, E as animals, O as adjectives, S as colors, T as architecture, _ as gemstones, a as space, b as domains, c as nouns, d as music, f as modifiers, g as geography, h as insects, i as technologies, l as nature, m as instruments, n as verbs, o as seasons, p as materials, r as trees, s as plants, t as weather, u as mythology, v as flowers, w as birds, x as directions, y as elements } from "./index-
|
|
1
|
+
import { a as Patterns, c as SuffixContext, i as Pattern, l as SuffixGenerator, n as LexidOptions, o as RandomUtils, r as LexidValidateOptions, s as Segments, t as Dictionary } from "./types-DKjF96ZA.cjs";
|
|
2
|
+
import { C as categories, D as adverbs, E as animals, O as adjectives, S as colors, T as architecture, _ as gemstones, a as space, b as domains, c as nouns, d as music, f as modifiers, g as geography, h as insects, i as technologies, l as nature, m as instruments, n as verbs, o as seasons, p as materials, r as trees, s as plants, t as weather, u as mythology, v as flowers, w as birds, x as directions, y as elements } from "./index-CvKRlqot.cjs";
|
|
3
3
|
import { random } from "./random.cjs";
|
|
4
|
-
import { i as
|
|
4
|
+
import { a as threeWordPatterns, i as pickPattern, n as fiveSegmentPatterns, o as fourWordPatterns, r as fourSegmentPatterns, t as defaultPatterns } from "./index-kBjONiKH.cjs";
|
|
5
5
|
|
|
6
6
|
//#region src/lexid.d.ts
|
|
7
7
|
declare function lexid(options?: LexidOptions): string;
|
|
@@ -13,4 +13,4 @@ declare function isLexid(value: string, options?: LexidValidateOptions): boolean
|
|
|
13
13
|
//#region src/suffix.d.ts
|
|
14
14
|
declare const defaultSuffix: SuffixGenerator;
|
|
15
15
|
//#endregion
|
|
16
|
-
export { type Dictionary, type LexidOptions, type LexidValidateOptions, type Pattern, type Patterns, type RandomUtils, type Segments, type SuffixContext, type SuffixGenerator, adjectives, adverbs, animals, architecture, birds, categories, colors, defaultPatterns, defaultSuffix, directions, domains, elements, fiveSegmentPatterns, flowers, fourSegmentPatterns, gemstones, geography, insects, instruments, isLexid, lexid, lexids, materials, modifiers, music, mythology, nature, nouns, pickPattern, plants, random, seasons, space, technologies, trees, verbs, weather };
|
|
16
|
+
export { type Dictionary, type LexidOptions, type LexidValidateOptions, type Pattern, type Patterns, type RandomUtils, type Segments, type SuffixContext, type SuffixGenerator, adjectives, adverbs, animals, architecture, birds, categories, colors, defaultPatterns, defaultSuffix, directions, domains, elements, fiveSegmentPatterns, flowers, fourSegmentPatterns, fourWordPatterns, gemstones, geography, insects, instruments, isLexid, lexid, lexids, materials, modifiers, music, mythology, nature, nouns, pickPattern, plants, random, seasons, space, technologies, threeWordPatterns, trees, verbs, weather };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { a as Patterns, c as SuffixContext, i as Pattern, l as SuffixGenerator, n as LexidOptions, o as RandomUtils, r as LexidValidateOptions, s as Segments, t as Dictionary } from "./types-
|
|
2
|
-
import { C as categories, D as adverbs, E as animals, O as adjectives, S as colors, T as architecture, _ as gemstones, a as space, b as domains, c as nouns, d as music, f as modifiers, g as geography, h as insects, i as technologies, l as nature, m as instruments, n as verbs, o as seasons, p as materials, r as trees, s as plants, t as weather, u as mythology, v as flowers, w as birds, x as directions, y as elements } from "./index-
|
|
1
|
+
import { a as Patterns, c as SuffixContext, i as Pattern, l as SuffixGenerator, n as LexidOptions, o as RandomUtils, r as LexidValidateOptions, s as Segments, t as Dictionary } from "./types-BsCTggdZ.mjs";
|
|
2
|
+
import { C as categories, D as adverbs, E as animals, O as adjectives, S as colors, T as architecture, _ as gemstones, a as space, b as domains, c as nouns, d as music, f as modifiers, g as geography, h as insects, i as technologies, l as nature, m as instruments, n as verbs, o as seasons, p as materials, r as trees, s as plants, t as weather, u as mythology, v as flowers, w as birds, x as directions, y as elements } from "./index-CBG7Ua1f.mjs";
|
|
3
3
|
import { random } from "./random.mjs";
|
|
4
|
-
import { i as
|
|
4
|
+
import { a as threeWordPatterns, i as pickPattern, n as fiveSegmentPatterns, o as fourWordPatterns, r as fourSegmentPatterns, t as defaultPatterns } from "./index-BGuJLQZS.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/lexid.d.ts
|
|
7
7
|
declare function lexid(options?: LexidOptions): string;
|
|
@@ -13,4 +13,4 @@ declare function isLexid(value: string, options?: LexidValidateOptions): boolean
|
|
|
13
13
|
//#region src/suffix.d.ts
|
|
14
14
|
declare const defaultSuffix: SuffixGenerator;
|
|
15
15
|
//#endregion
|
|
16
|
-
export { type Dictionary, type LexidOptions, type LexidValidateOptions, type Pattern, type Patterns, type RandomUtils, type Segments, type SuffixContext, type SuffixGenerator, adjectives, adverbs, animals, architecture, birds, categories, colors, defaultPatterns, defaultSuffix, directions, domains, elements, fiveSegmentPatterns, flowers, fourSegmentPatterns, gemstones, geography, insects, instruments, isLexid, lexid, lexids, materials, modifiers, music, mythology, nature, nouns, pickPattern, plants, random, seasons, space, technologies, trees, verbs, weather };
|
|
16
|
+
export { type Dictionary, type LexidOptions, type LexidValidateOptions, type Pattern, type Patterns, type RandomUtils, type Segments, type SuffixContext, type SuffixGenerator, adjectives, adverbs, animals, architecture, birds, categories, colors, defaultPatterns, defaultSuffix, directions, domains, elements, fiveSegmentPatterns, flowers, fourSegmentPatterns, fourWordPatterns, gemstones, geography, insects, instruments, isLexid, lexid, lexids, materials, modifiers, music, mythology, nature, nouns, pickPattern, plants, random, seasons, space, technologies, threeWordPatterns, trees, verbs, weather };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { C as categories, D as adverbs, E as animals, O as adjectives, S as colors, T as architecture, _ as gemstones, a as space, b as domains, c as nouns, d as music, f as modifiers, g as geography, h as insects, i as technologies, l as nature, m as instruments, n as verbs, o as seasons, p as materials, r as trees, s as plants, t as weather, u as mythology, v as flowers, w as birds, x as directions, y as elements } from "./dictionaries-DqOja3dc.mjs";
|
|
2
|
-
import { i as
|
|
2
|
+
import { a as threeWordPatterns, i as pickPattern, n as fiveSegmentPatterns, o as fourWordPatterns, r as fourSegmentPatterns, t as defaultPatterns } from "./patterns-H0XRwCVB.mjs";
|
|
3
3
|
import { random } from "./random.mjs";
|
|
4
4
|
//#region src/suffix.ts
|
|
5
5
|
const defaultSuffix = ({ random }) => random.alphanumeric(6);
|
|
@@ -39,8 +39,11 @@ function validateSegments(segments) {
|
|
|
39
39
|
}
|
|
40
40
|
function isLexid(value, options = {}) {
|
|
41
41
|
const { separator, maxLength } = formatOptions(options);
|
|
42
|
+
const { hasSuffix = true } = options;
|
|
43
|
+
if (typeof hasSuffix !== "boolean") throw new TypeError("hasSuffix must be a boolean");
|
|
42
44
|
if (typeof value !== "string" || value.length > maxLength) return false;
|
|
43
45
|
const parts = value.split(separator);
|
|
46
|
+
if (!hasSuffix) return parts.every(isWord);
|
|
44
47
|
const suffix = parts.pop();
|
|
45
48
|
return parts.length > 0 && isSuffix(suffix) && parts.every(isWord);
|
|
46
49
|
}
|
|
@@ -49,7 +52,7 @@ function isLexid(value, options = {}) {
|
|
|
49
52
|
function lexid(options = {}) {
|
|
50
53
|
const { separator, maxLength } = formatOptions(options);
|
|
51
54
|
const { suffix = defaultSuffix } = options;
|
|
52
|
-
if (typeof suffix !== "function") throw new TypeError("suffix must be a function");
|
|
55
|
+
if (suffix !== false && typeof suffix !== "function") throw new TypeError("suffix must be false or a function");
|
|
53
56
|
const { segments = pickPattern(defaultPatterns) } = options;
|
|
54
57
|
validateSegments(segments);
|
|
55
58
|
const words = [];
|
|
@@ -57,16 +60,21 @@ function lexid(options = {}) {
|
|
|
57
60
|
const dictionary = segments[index];
|
|
58
61
|
words.push(dictionary[random.int(dictionary.length)]);
|
|
59
62
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
let parts = words;
|
|
64
|
+
if (suffix !== false) {
|
|
65
|
+
const tail = suffix(Object.freeze({
|
|
66
|
+
words: Object.freeze(words),
|
|
67
|
+
random
|
|
68
|
+
}));
|
|
69
|
+
if (!isSuffix(tail)) throw new TypeError("suffix must return a nonempty string containing lowercase ASCII letters and digits only");
|
|
70
|
+
parts = [...words, tail];
|
|
71
|
+
}
|
|
72
|
+
const value = parts.join(separator);
|
|
66
73
|
if (value.length > maxLength) throw new RangeError(`Generated identifier length ${value.length} exceeds maxLength ${maxLength}`);
|
|
67
74
|
if (!isLexid(value, {
|
|
68
75
|
separator,
|
|
69
|
-
maxLength
|
|
76
|
+
maxLength,
|
|
77
|
+
hasSuffix: suffix !== false
|
|
70
78
|
})) throw new TypeError("Generated identifier contains an invalid segment");
|
|
71
79
|
return value;
|
|
72
80
|
}
|
|
@@ -76,4 +84,4 @@ function lexids(count, options) {
|
|
|
76
84
|
return Array.from({ length: count }, () => lexid(options));
|
|
77
85
|
}
|
|
78
86
|
//#endregion
|
|
79
|
-
export { adjectives, adverbs, animals, architecture, birds, categories, colors, defaultPatterns, defaultSuffix, directions, domains, elements, fiveSegmentPatterns, flowers, fourSegmentPatterns, gemstones, geography, insects, instruments, isLexid, lexid, lexids, materials, modifiers, music, mythology, nature, nouns, pickPattern, plants, random, seasons, space, technologies, trees, verbs, weather };
|
|
87
|
+
export { adjectives, adverbs, animals, architecture, birds, categories, colors, defaultPatterns, defaultSuffix, directions, domains, elements, fiveSegmentPatterns, flowers, fourSegmentPatterns, fourWordPatterns, gemstones, geography, insects, instruments, isLexid, lexid, lexids, materials, modifiers, music, mythology, nature, nouns, pickPattern, plants, random, seasons, space, technologies, threeWordPatterns, trees, verbs, weather };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_dictionaries = require("./dictionaries-DwfVfnJX.cjs");
|
|
2
2
|
const require_random = require("./random.cjs");
|
|
3
|
-
//#region src/patterns/
|
|
4
|
-
const
|
|
3
|
+
//#region src/patterns/four-word.ts
|
|
4
|
+
const fourWordPatterns = /* @__PURE__ */ Object.freeze([
|
|
5
5
|
/* @__PURE__ */ Object.freeze([
|
|
6
6
|
require_dictionaries.adjectives,
|
|
7
7
|
require_dictionaries.colors,
|
|
@@ -94,8 +94,8 @@ const fiveSegmentPatterns = /* @__PURE__ */ Object.freeze([
|
|
|
94
94
|
])
|
|
95
95
|
]);
|
|
96
96
|
//#endregion
|
|
97
|
-
//#region src/patterns/
|
|
98
|
-
const
|
|
97
|
+
//#region src/patterns/three-word.ts
|
|
98
|
+
const threeWordPatterns = /* @__PURE__ */ Object.freeze([
|
|
99
99
|
/* @__PURE__ */ Object.freeze([
|
|
100
100
|
require_dictionaries.adjectives,
|
|
101
101
|
require_dictionaries.colors,
|
|
@@ -241,7 +241,11 @@ function pickPattern(patterns) {
|
|
|
241
241
|
}
|
|
242
242
|
//#endregion
|
|
243
243
|
//#region src/patterns/index.ts
|
|
244
|
-
|
|
244
|
+
/** @deprecated Use threeWordPatterns. */
|
|
245
|
+
const fourSegmentPatterns = threeWordPatterns;
|
|
246
|
+
/** @deprecated Use fourWordPatterns. */
|
|
247
|
+
const fiveSegmentPatterns = fourWordPatterns;
|
|
248
|
+
const defaultPatterns = /* @__PURE__ */ Object.freeze([...threeWordPatterns, ...fourWordPatterns]);
|
|
245
249
|
//#endregion
|
|
246
250
|
Object.defineProperty(exports, "defaultPatterns", {
|
|
247
251
|
enumerable: true,
|
|
@@ -261,9 +265,21 @@ Object.defineProperty(exports, "fourSegmentPatterns", {
|
|
|
261
265
|
return fourSegmentPatterns;
|
|
262
266
|
}
|
|
263
267
|
});
|
|
268
|
+
Object.defineProperty(exports, "fourWordPatterns", {
|
|
269
|
+
enumerable: true,
|
|
270
|
+
get: function() {
|
|
271
|
+
return fourWordPatterns;
|
|
272
|
+
}
|
|
273
|
+
});
|
|
264
274
|
Object.defineProperty(exports, "pickPattern", {
|
|
265
275
|
enumerable: true,
|
|
266
276
|
get: function() {
|
|
267
277
|
return pickPattern;
|
|
268
278
|
}
|
|
269
279
|
});
|
|
280
|
+
Object.defineProperty(exports, "threeWordPatterns", {
|
|
281
|
+
enumerable: true,
|
|
282
|
+
get: function() {
|
|
283
|
+
return threeWordPatterns;
|
|
284
|
+
}
|
|
285
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as categories, E as animals, O as adjectives, S as colors, T as architecture, _ as gemstones, a as space, b as domains, c as nouns, f as modifiers, i as technologies, l as nature, o as seasons, p as materials, s as plants, t as weather, u as mythology, v as flowers, w as birds, y as elements } from "./dictionaries-DqOja3dc.mjs";
|
|
2
2
|
import { random } from "./random.mjs";
|
|
3
|
-
//#region src/patterns/
|
|
4
|
-
const
|
|
3
|
+
//#region src/patterns/four-word.ts
|
|
4
|
+
const fourWordPatterns = /* @__PURE__ */ Object.freeze([
|
|
5
5
|
/* @__PURE__ */ Object.freeze([
|
|
6
6
|
adjectives,
|
|
7
7
|
colors,
|
|
@@ -94,8 +94,8 @@ const fiveSegmentPatterns = /* @__PURE__ */ Object.freeze([
|
|
|
94
94
|
])
|
|
95
95
|
]);
|
|
96
96
|
//#endregion
|
|
97
|
-
//#region src/patterns/
|
|
98
|
-
const
|
|
97
|
+
//#region src/patterns/three-word.ts
|
|
98
|
+
const threeWordPatterns = /* @__PURE__ */ Object.freeze([
|
|
99
99
|
/* @__PURE__ */ Object.freeze([
|
|
100
100
|
adjectives,
|
|
101
101
|
colors,
|
|
@@ -241,6 +241,10 @@ function pickPattern(patterns) {
|
|
|
241
241
|
}
|
|
242
242
|
//#endregion
|
|
243
243
|
//#region src/patterns/index.ts
|
|
244
|
-
|
|
244
|
+
/** @deprecated Use threeWordPatterns. */
|
|
245
|
+
const fourSegmentPatterns = threeWordPatterns;
|
|
246
|
+
/** @deprecated Use fourWordPatterns. */
|
|
247
|
+
const fiveSegmentPatterns = fourWordPatterns;
|
|
248
|
+
const defaultPatterns = /* @__PURE__ */ Object.freeze([...threeWordPatterns, ...fourWordPatterns]);
|
|
245
249
|
//#endregion
|
|
246
|
-
export {
|
|
250
|
+
export { threeWordPatterns as a, pickPattern as i, fiveSegmentPatterns as n, fourWordPatterns as o, fourSegmentPatterns as r, defaultPatterns as t };
|
package/dist/patterns.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_patterns = require("./patterns-
|
|
2
|
+
const require_patterns = require("./patterns-DC47BwpJ.cjs");
|
|
3
3
|
exports.defaultPatterns = require_patterns.defaultPatterns;
|
|
4
4
|
exports.fiveSegmentPatterns = require_patterns.fiveSegmentPatterns;
|
|
5
5
|
exports.fourSegmentPatterns = require_patterns.fourSegmentPatterns;
|
|
6
|
+
exports.fourWordPatterns = require_patterns.fourWordPatterns;
|
|
6
7
|
exports.pickPattern = require_patterns.pickPattern;
|
|
8
|
+
exports.threeWordPatterns = require_patterns.threeWordPatterns;
|
package/dist/patterns.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as
|
|
2
|
-
export { defaultPatterns, fiveSegmentPatterns, fourSegmentPatterns, pickPattern };
|
|
1
|
+
import { a as threeWordPatterns, i as pickPattern, n as fiveSegmentPatterns, o as fourWordPatterns, r as fourSegmentPatterns, t as defaultPatterns } from "./index-kBjONiKH.cjs";
|
|
2
|
+
export { defaultPatterns, fiveSegmentPatterns, fourSegmentPatterns, fourWordPatterns, pickPattern, threeWordPatterns };
|
package/dist/patterns.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as
|
|
2
|
-
export { defaultPatterns, fiveSegmentPatterns, fourSegmentPatterns, pickPattern };
|
|
1
|
+
import { a as threeWordPatterns, i as pickPattern, n as fiveSegmentPatterns, o as fourWordPatterns, r as fourSegmentPatterns, t as defaultPatterns } from "./index-BGuJLQZS.mjs";
|
|
2
|
+
export { defaultPatterns, fiveSegmentPatterns, fourSegmentPatterns, fourWordPatterns, pickPattern, threeWordPatterns };
|
package/dist/patterns.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as
|
|
2
|
-
export { defaultPatterns, fiveSegmentPatterns, fourSegmentPatterns, pickPattern };
|
|
1
|
+
import { a as threeWordPatterns, i as pickPattern, n as fiveSegmentPatterns, o as fourWordPatterns, r as fourSegmentPatterns, t as defaultPatterns } from "./patterns-H0XRwCVB.mjs";
|
|
2
|
+
export { defaultPatterns, fiveSegmentPatterns, fourSegmentPatterns, fourWordPatterns, pickPattern, threeWordPatterns };
|
package/dist/random.d.cts
CHANGED
package/dist/random.d.mts
CHANGED
|
@@ -22,14 +22,16 @@ interface LexidOptions {
|
|
|
22
22
|
segments?: Segments;
|
|
23
23
|
/** Separator between all segments. Defaults to '-'. */
|
|
24
24
|
separator?: string;
|
|
25
|
-
/**
|
|
26
|
-
suffix?: SuffixGenerator;
|
|
25
|
+
/** Set to false to omit the suffix, or pass a callback. Defaults to six lowercase alphanumeric characters. */
|
|
26
|
+
suffix?: SuffixGenerator | false;
|
|
27
27
|
/** Maximum length including separators and suffix. Defaults to 63. */
|
|
28
28
|
maxLength?: number;
|
|
29
29
|
}
|
|
30
30
|
interface LexidValidateOptions {
|
|
31
31
|
separator?: string;
|
|
32
32
|
maxLength?: number;
|
|
33
|
+
/** Whether to expect a final suffix segment. Defaults to true. */
|
|
34
|
+
hasSuffix?: boolean;
|
|
33
35
|
}
|
|
34
36
|
//#endregion
|
|
35
37
|
export { Patterns as a, SuffixContext as c, Pattern as i, SuffixGenerator as l, LexidOptions as n, RandomUtils as o, LexidValidateOptions as r, Segments as s, Dictionary as t };
|
|
@@ -22,14 +22,16 @@ interface LexidOptions {
|
|
|
22
22
|
segments?: Segments;
|
|
23
23
|
/** Separator between all segments. Defaults to '-'. */
|
|
24
24
|
separator?: string;
|
|
25
|
-
/**
|
|
26
|
-
suffix?: SuffixGenerator;
|
|
25
|
+
/** Set to false to omit the suffix, or pass a callback. Defaults to six lowercase alphanumeric characters. */
|
|
26
|
+
suffix?: SuffixGenerator | false;
|
|
27
27
|
/** Maximum length including separators and suffix. Defaults to 63. */
|
|
28
28
|
maxLength?: number;
|
|
29
29
|
}
|
|
30
30
|
interface LexidValidateOptions {
|
|
31
31
|
separator?: string;
|
|
32
32
|
maxLength?: number;
|
|
33
|
+
/** Whether to expect a final suffix segment. Defaults to true. */
|
|
34
|
+
hasSuffix?: boolean;
|
|
33
35
|
}
|
|
34
36
|
//#endregion
|
|
35
37
|
export { Patterns as a, SuffixContext as c, Pattern as i, SuffixGenerator as l, LexidOptions as n, RandomUtils as o, LexidValidateOptions as r, Segments as s, Dictionary as t };
|
package/package.json
CHANGED
package/skills/lexid/SKILL.md
CHANGED
|
@@ -22,29 +22,29 @@ const instanceName = lexid()
|
|
|
22
22
|
|
|
23
23
|
## Choose an API
|
|
24
24
|
|
|
25
|
-
| Need | API or composition
|
|
26
|
-
| ------------------------------------------------------ |
|
|
27
|
-
| Default semantic identifier | `lexid()`
|
|
28
|
-
| Fixed order or custom segment count | `lexid({ segments })`
|
|
29
|
-
|
|
|
30
|
-
| Fixed word, positional constraint, or mixed dictionary | Single-element array, `Array.filter`, or array spread
|
|
31
|
-
| Custom templates | `pickPattern(patterns)` as `segments`
|
|
32
|
-
| Custom separator or suffix | `separator` or a synchronous `suffix` callback
|
|
33
|
-
| Batch or format check | `lexids(count, options)` or `isLexid(value, options)`
|
|
34
|
-
| Standalone secure sampling | `random` from `@wry-smile/lexid/random`
|
|
25
|
+
| Need | API or composition |
|
|
26
|
+
| ------------------------------------------------------ | --------------------------------------------------------------------------------- |
|
|
27
|
+
| Default semantic identifier | `lexid()` |
|
|
28
|
+
| Fixed order or custom segment count | `lexid({ segments })` |
|
|
29
|
+
| Three or four word segments | `pickPattern(threeWordPatterns)` or `pickPattern(fourWordPatterns)` as `segments` |
|
|
30
|
+
| Fixed word, positional constraint, or mixed dictionary | Single-element array, `Array.filter`, or array spread |
|
|
31
|
+
| Custom templates | `pickPattern(patterns)` as `segments` |
|
|
32
|
+
| Custom separator or suffix | `separator` or a synchronous `suffix` callback |
|
|
33
|
+
| Batch or format check | `lexids(count, options)` or `isLexid(value, options)` |
|
|
34
|
+
| Standalone secure sampling | `random` from `@wry-smile/lexid/random` |
|
|
35
35
|
|
|
36
36
|
## Customize with arrays and functions
|
|
37
37
|
|
|
38
|
-
Pass ordered arrays of candidate words to `segments`. The suffix adds one
|
|
39
|
-
segment. Compose frozen built-in dictionaries using filtering and spreading.
|
|
38
|
+
Pass ordered arrays of candidate words to `segments`. The default suffix adds one
|
|
39
|
+
segment. Set `suffix: false` to omit it and validate with `hasSuffix: false`. Compose frozen built-in dictionaries using filtering and spreading.
|
|
40
40
|
Check that filtered dictionaries have candidates, or use `pickPattern` to skip
|
|
41
41
|
templates containing empty dictionaries. Supply fixed words in single-element
|
|
42
42
|
arrays and keep each candidate intact.
|
|
43
43
|
|
|
44
44
|
## Common mistakes
|
|
45
45
|
|
|
46
|
-
`segments: 5` is invalid. Pass `pickPattern(
|
|
47
|
-
|
|
46
|
+
`segments: 5` is invalid. Pass `pickPattern(fourWordPatterns)` to obtain
|
|
47
|
+
four word segments plus the default suffix. Apply filters directly to the dictionary arrays. Supply
|
|
48
48
|
a callback such as `({ random }) => random.numeric(8)` for a numeric suffix.
|
|
49
49
|
For a custom separator or length limit, use matching options in `isLexid`.
|
|
50
50
|
|
|
@@ -4,15 +4,15 @@ The root entry exports the functions, data, and types below. Use
|
|
|
4
4
|
`@wry-smile/lexid/dictionaries`, `@wry-smile/lexid/patterns`, and `@wry-smile/lexid/random` to import those
|
|
5
5
|
modules independently. Both ESM and CommonJS are supported.
|
|
6
6
|
|
|
7
|
-
| Export | Contract
|
|
8
|
-
| ----------------------------------------------------------------- |
|
|
9
|
-
| `lexid(options?: LexidOptions): string` | Samples an ordered set of word dictionaries and appends a suffix. Defaults to a uniformly chosen built-in template.
|
|
10
|
-
| `lexids(count: number, options?: LexidOptions): string[]` | Generates independently per entry, with a fresh default pattern and suffix invocation per entry. Count must be a nonnegative safe integer and fit in a JavaScript array. Zero returns an empty array. Duplicates are possible. |
|
|
11
|
-
| `isLexid(value: string, options?: LexidValidateOptions): boolean` | Checks at least one lowercase ASCII word, one lowercase ASCII alphanumeric suffix, separators
|
|
12
|
-
| `pickPattern(patterns: Patterns): Pattern` | Uniformly selects an original nonempty template with nonempty dictionary arrays. Throws if no eligible pattern exists. The generator validates the words.
|
|
13
|
-
| `defaultSuffix: SuffixGenerator` | Generates six lowercase alphanumeric characters with the context's random tools.
|
|
14
|
-
| `defaultPatterns`, `
|
|
15
|
-
| Dictionary exports | Frozen arrays of lowercase ASCII words. See [dictionary categories](dictionaries.md).
|
|
7
|
+
| Export | Contract |
|
|
8
|
+
| ----------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
9
|
+
| `lexid(options?: LexidOptions): string` | Samples an ordered set of word dictionaries and appends a suffix by default. Defaults to a uniformly chosen built-in template. |
|
|
10
|
+
| `lexids(count: number, options?: LexidOptions): string[]` | Generates independently per entry, with a fresh default pattern and one suffix invocation per entry when enabled. Count must be a nonnegative safe integer and fit in a JavaScript array. Zero returns an empty array. Duplicates are possible. |
|
|
11
|
+
| `isLexid(value: string, options?: LexidValidateOptions): boolean` | Checks at least one lowercase ASCII word, one lowercase ASCII alphanumeric suffix by default, plus separators and total length. Invalid values return false. Invalid options throw. |
|
|
12
|
+
| `pickPattern(patterns: Patterns): Pattern` | Uniformly selects an original nonempty template with nonempty dictionary arrays. Throws if no eligible pattern exists. The generator validates the words. |
|
|
13
|
+
| `defaultSuffix: SuffixGenerator` | Generates six lowercase alphanumeric characters with the context's random tools. |
|
|
14
|
+
| `defaultPatterns`, `threeWordPatterns`, `fourWordPatterns` | Frozen collections of frozen dictionary combinations. |
|
|
15
|
+
| Dictionary exports | Frozen arrays of lowercase ASCII words. See [dictionary categories](dictionaries.md). |
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
import type {
|
|
@@ -42,10 +42,15 @@ void [patterns, options, sampleDigit]
|
|
|
42
42
|
`readonly Dictionary[]`. `Patterns` is `readonly Pattern[]`. Both options
|
|
43
43
|
types accept a separator (default `-`, also accepts `_`, `.`, and `~`)
|
|
44
44
|
and a positive safe integer maximum length (default 63). Generation options
|
|
45
|
-
also accept `segments` and a synchronous `suffix` callback.
|
|
45
|
+
also accept `segments` and a synchronous `suffix` callback. Set `suffix: false`
|
|
46
|
+
to omit the suffix. For validation, set `hasSuffix: false` to require only
|
|
47
|
+
word segments.
|
|
46
48
|
|
|
47
|
-
The
|
|
48
|
-
|
|
49
|
+
The deprecated names `fourSegmentPatterns` and `fiveSegmentPatterns` are aliases
|
|
50
|
+
for `threeWordPatterns` and `fourWordPatterns`, respectively.
|
|
51
|
+
|
|
52
|
+
The generator checks every candidate, including holes in arrays. When enabled,
|
|
53
|
+
it invokes the suffix once after selecting words, passing a frozen context with a frozen word
|
|
49
54
|
snapshot and the public `random` object. Empty or malformed suffixes and
|
|
50
55
|
oversized results throw. Callback exceptions propagate directly.
|
|
51
56
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Customization
|
|
2
2
|
|
|
3
|
-
Use one or more dictionaries and expect `segments.length + 1` total segments.
|
|
3
|
+
Use one or more dictionaries and expect `segments.length + 1` total segments by default.
|
|
4
|
+
With `suffix: false`, the result contains exactly `segments.length` word segments.
|
|
5
|
+
Validate it with `isLexid(value, { hasSuffix: false })`.
|
|
4
6
|
A one-word dictionary fixes that segment. Filter words by position or length
|
|
5
7
|
using normal array methods. Restrict the longest allowed candidate per segment
|
|
6
8
|
and budget for the separators and suffix when every result must fit.
|
|
@@ -30,3 +32,35 @@ Choose `-` for ordinary DNS-label-compatible identifiers with the default
|
|
|
30
32
|
length cap. The other supported separators are `_`, `.`, and `~`. Custom
|
|
31
33
|
suffixes can combine fixed characters, initials, and random characters. Return
|
|
32
34
|
a nonempty lowercase ASCII alphanumeric string synchronously.
|
|
35
|
+
|
|
36
|
+
## Replace one dictionary in a preset
|
|
37
|
+
|
|
38
|
+
Select a preset, then copy its dictionaries while replacing the target position.
|
|
39
|
+
The other positions retain the candidate dictionaries from that preset.
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { threeWordPatterns, lexid, pickPattern } from '@wry-smile/lexid'
|
|
43
|
+
|
|
44
|
+
const [first, , third] = pickPattern(threeWordPatterns)
|
|
45
|
+
lexid({ segments: [first, ['worker', 'gateway'], third] })
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Filter built-in templates by position
|
|
49
|
+
|
|
50
|
+
Filter every candidate template before calling `pickPattern`. It skips templates
|
|
51
|
+
where filtering empties a dictionary and throws if no template remains. For three word segments, use `threeWordPatterns` and three word limits.
|
|
52
|
+
The suffix is generated separately.
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { fourWordPatterns, lexid, pickPattern } from '@wry-smile/lexid'
|
|
56
|
+
|
|
57
|
+
const limits = [6, 5, 7, 8]
|
|
58
|
+
const candidates = fourWordPatterns.map((pattern) =>
|
|
59
|
+
pattern.map((dictionary, index) => dictionary.filter((word) => word.length <= limits[index])),
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
const id = lexid({ segments: pickPattern(candidates) })
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Reuse the filtered candidates when generating multiple names with the same
|
|
66
|
+
limits. Call `pickPattern(candidates)` again for each name to vary the template.
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
# Semantic patterns
|
|
2
2
|
|
|
3
|
-
A pattern is an ordered array of dictionaries. `
|
|
4
|
-
three dictionaries per pattern and `
|
|
5
|
-
completes the identifier.
|
|
3
|
+
A pattern is an ordered array of dictionaries. `threeWordPatterns` has
|
|
4
|
+
three dictionaries per pattern and `fourWordPatterns` has four. The suffix
|
|
5
|
+
completes the identifier by default. With `suffix: false`, the same templates
|
|
6
|
+
produce exactly three or four word segments. The older names
|
|
7
|
+
`fourSegmentPatterns` and `fiveSegmentPatterns` remain as deprecated aliases
|
|
8
|
+
that count the default suffix. Default styles include colors and wildlife,
|
|
6
9
|
materials and objects, and technologies and domains. `defaultPatterns`
|
|
7
10
|
combines both sets. Selection is uniform across eligible patterns.
|
|
8
11
|
|
|
9
12
|
```ts
|
|
10
13
|
import { adjectives, domains, lexid } from '@wry-smile/lexid'
|
|
11
|
-
import {
|
|
14
|
+
import { fourWordPatterns, threeWordPatterns, pickPattern } from '@wry-smile/lexid/patterns'
|
|
12
15
|
|
|
13
|
-
lexid({ segments: pickPattern(
|
|
14
|
-
lexid({ segments: pickPattern(
|
|
16
|
+
lexid({ segments: pickPattern(threeWordPatterns) })
|
|
17
|
+
lexid({ segments: pickPattern(fourWordPatterns) })
|
|
15
18
|
lexid({
|
|
16
19
|
segments: pickPattern([
|
|
17
20
|
[adjectives, domains],
|
|
@@ -19,7 +22,7 @@ lexid({
|
|
|
19
22
|
]),
|
|
20
23
|
})
|
|
21
24
|
|
|
22
|
-
const candidates =
|
|
25
|
+
const candidates = fourWordPatterns.map((pattern) =>
|
|
23
26
|
pattern.map((dictionary, index) =>
|
|
24
27
|
index === 0 ? dictionary.filter((word) => word.startsWith('s')) : dictionary,
|
|
25
28
|
),
|
|
@@ -30,3 +33,13 @@ lexid({ segments: pickPattern(candidates) })
|
|
|
30
33
|
Filter before choosing a template. `pickPattern` skips empty templates and
|
|
31
34
|
templates containing empty dictionaries. Handle its error if all candidates
|
|
32
35
|
are eliminated.
|
|
36
|
+
|
|
37
|
+
## Order custom word segments
|
|
38
|
+
|
|
39
|
+
For a readable English-style name, move from descriptors to the object being
|
|
40
|
+
named. For example, use `[adjectives, technologies, domains]` for service names
|
|
41
|
+
or `[colors, nature, animals]` for nature-inspired names.
|
|
42
|
+
|
|
43
|
+
For names scanned in a resource list, put the primary grouping key first.
|
|
44
|
+
Use a single-word dictionary for a fixed key, and apply length filters only
|
|
45
|
+
to the positions that need them.
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { a as Patterns, i as Pattern } from "./types-BMRtYBrz.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/patterns/five-segment.d.ts
|
|
4
|
-
declare const fiveSegmentPatterns: Patterns;
|
|
5
|
-
//#endregion
|
|
6
|
-
//#region src/patterns/four-segment.d.ts
|
|
7
|
-
declare const fourSegmentPatterns: Patterns;
|
|
8
|
-
//#endregion
|
|
9
|
-
//#region src/patterns/pick-pattern.d.ts
|
|
10
|
-
declare function pickPattern(patterns: Patterns): Pattern;
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/patterns/index.d.ts
|
|
13
|
-
declare const defaultPatterns: Patterns;
|
|
14
|
-
//#endregion
|
|
15
|
-
export { fiveSegmentPatterns as i, pickPattern as n, fourSegmentPatterns as r, defaultPatterns as t };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { a as Patterns, i as Pattern } from "./types-CHH8wNDe.cjs";
|
|
2
|
-
|
|
3
|
-
//#region src/patterns/five-segment.d.ts
|
|
4
|
-
declare const fiveSegmentPatterns: Patterns;
|
|
5
|
-
//#endregion
|
|
6
|
-
//#region src/patterns/four-segment.d.ts
|
|
7
|
-
declare const fourSegmentPatterns: Patterns;
|
|
8
|
-
//#endregion
|
|
9
|
-
//#region src/patterns/pick-pattern.d.ts
|
|
10
|
-
declare function pickPattern(patterns: Patterns): Pattern;
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/patterns/index.d.ts
|
|
13
|
-
declare const defaultPatterns: Patterns;
|
|
14
|
-
//#endregion
|
|
15
|
-
export { fiveSegmentPatterns as i, pickPattern as n, fourSegmentPatterns as r, defaultPatterns as t };
|