@wry-smile/lexid 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +211 -2
- package/README.zh-CN.md +178 -0
- package/dist/dictionaries-DqOja3dc.mjs +6574 -0
- package/dist/dictionaries-DwfVfnJX.cjs +6741 -0
- package/dist/dictionaries.cjs +30 -0
- package/dist/dictionaries.d.cts +2 -0
- package/dist/dictionaries.d.mts +2 -0
- package/dist/dictionaries.mjs +2 -0
- package/dist/index-BGuJLQZS.d.mts +19 -0
- package/dist/index-CBG7Ua1f.d.mts +87 -0
- package/dist/index-CvKRlqot.d.cts +87 -0
- package/dist/index-kBjONiKH.d.cts +19 -0
- package/dist/index.cjs +126 -0
- package/dist/index.d.cts +16 -0
- package/dist/index.d.mts +16 -0
- package/dist/index.mjs +87 -0
- package/dist/patterns-DC47BwpJ.cjs +285 -0
- package/dist/patterns-H0XRwCVB.mjs +250 -0
- package/dist/patterns.cjs +8 -0
- package/dist/patterns.d.cts +2 -0
- package/dist/patterns.d.mts +2 -0
- package/dist/patterns.mjs +2 -0
- package/dist/random.cjs +43 -0
- package/dist/random.d.cts +6 -0
- package/dist/random.d.mts +6 -0
- package/dist/random.mjs +42 -0
- package/dist/types-BsCTggdZ.d.mts +37 -0
- package/dist/types-DKjF96ZA.d.cts +37 -0
- package/package.json +97 -3
- package/skills/lexid/SKILL.md +65 -0
- package/skills/lexid/references/api.md +69 -0
- package/skills/lexid/references/customization.md +66 -0
- package/skills/lexid/references/dictionaries.md +33 -0
- package/skills/lexid/references/examples.md +54 -0
- package/skills/lexid/references/patterns.md +45 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_dictionaries = require("./dictionaries-DwfVfnJX.cjs");
|
|
3
|
+
exports.adjectives = require_dictionaries.adjectives;
|
|
4
|
+
exports.adverbs = require_dictionaries.adverbs;
|
|
5
|
+
exports.animals = require_dictionaries.animals;
|
|
6
|
+
exports.architecture = require_dictionaries.architecture;
|
|
7
|
+
exports.birds = require_dictionaries.birds;
|
|
8
|
+
exports.categories = require_dictionaries.categories;
|
|
9
|
+
exports.colors = require_dictionaries.colors;
|
|
10
|
+
exports.directions = require_dictionaries.directions;
|
|
11
|
+
exports.domains = require_dictionaries.domains;
|
|
12
|
+
exports.elements = require_dictionaries.elements;
|
|
13
|
+
exports.flowers = require_dictionaries.flowers;
|
|
14
|
+
exports.gemstones = require_dictionaries.gemstones;
|
|
15
|
+
exports.geography = require_dictionaries.geography;
|
|
16
|
+
exports.insects = require_dictionaries.insects;
|
|
17
|
+
exports.instruments = require_dictionaries.instruments;
|
|
18
|
+
exports.materials = require_dictionaries.materials;
|
|
19
|
+
exports.modifiers = require_dictionaries.modifiers;
|
|
20
|
+
exports.music = require_dictionaries.music;
|
|
21
|
+
exports.mythology = require_dictionaries.mythology;
|
|
22
|
+
exports.nature = require_dictionaries.nature;
|
|
23
|
+
exports.nouns = require_dictionaries.nouns;
|
|
24
|
+
exports.plants = require_dictionaries.plants;
|
|
25
|
+
exports.seasons = require_dictionaries.seasons;
|
|
26
|
+
exports.space = require_dictionaries.space;
|
|
27
|
+
exports.technologies = require_dictionaries.technologies;
|
|
28
|
+
exports.trees = require_dictionaries.trees;
|
|
29
|
+
exports.verbs = require_dictionaries.verbs;
|
|
30
|
+
exports.weather = require_dictionaries.weather;
|
|
@@ -0,0 +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-CvKRlqot.cjs";
|
|
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,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-CBG7Ua1f.mjs";
|
|
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,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 "./dictionaries-DqOja3dc.mjs";
|
|
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,87 @@
|
|
|
1
|
+
import { t as Dictionary } from "./types-BsCTggdZ.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/dictionaries/adjectives.d.ts
|
|
4
|
+
declare const adjectives: Dictionary;
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/dictionaries/adverbs.d.ts
|
|
7
|
+
declare const adverbs: Dictionary;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/dictionaries/animals.d.ts
|
|
10
|
+
declare const animals: Dictionary;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/dictionaries/architecture.d.ts
|
|
13
|
+
declare const architecture: Dictionary;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/dictionaries/birds.d.ts
|
|
16
|
+
declare const birds: Dictionary;
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/dictionaries/categories.d.ts
|
|
19
|
+
declare const categories: Dictionary;
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/dictionaries/colors.d.ts
|
|
22
|
+
declare const colors: Dictionary;
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/dictionaries/directions.d.ts
|
|
25
|
+
declare const directions: Dictionary;
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/dictionaries/domains.d.ts
|
|
28
|
+
declare const domains: Dictionary;
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/dictionaries/elements.d.ts
|
|
31
|
+
declare const elements: Dictionary;
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/dictionaries/flowers.d.ts
|
|
34
|
+
declare const flowers: Dictionary;
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/dictionaries/gemstones.d.ts
|
|
37
|
+
declare const gemstones: Dictionary;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/dictionaries/geography.d.ts
|
|
40
|
+
declare const geography: Dictionary;
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/dictionaries/insects.d.ts
|
|
43
|
+
declare const insects: Dictionary;
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/dictionaries/instruments.d.ts
|
|
46
|
+
declare const instruments: Dictionary;
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/dictionaries/materials.d.ts
|
|
49
|
+
declare const materials: Dictionary;
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/dictionaries/modifiers.d.ts
|
|
52
|
+
declare const modifiers: Dictionary;
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/dictionaries/music.d.ts
|
|
55
|
+
declare const music: Dictionary;
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/dictionaries/mythology.d.ts
|
|
58
|
+
declare const mythology: Dictionary;
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/dictionaries/nature.d.ts
|
|
61
|
+
declare const nature: Dictionary;
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/dictionaries/nouns.d.ts
|
|
64
|
+
declare const nouns: Dictionary;
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/dictionaries/plants.d.ts
|
|
67
|
+
declare const plants: Dictionary;
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/dictionaries/seasons.d.ts
|
|
70
|
+
declare const seasons: Dictionary;
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/dictionaries/space.d.ts
|
|
73
|
+
declare const space: Dictionary;
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/dictionaries/technologies.d.ts
|
|
76
|
+
declare const technologies: Dictionary;
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/dictionaries/trees.d.ts
|
|
79
|
+
declare const trees: Dictionary;
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/dictionaries/verbs.d.ts
|
|
82
|
+
declare const verbs: Dictionary;
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/dictionaries/weather.d.ts
|
|
85
|
+
declare const weather: Dictionary;
|
|
86
|
+
//#endregion
|
|
87
|
+
export { categories as C, adverbs as D, animals as E, adjectives as O, colors as S, architecture as T, gemstones as _, space as a, domains as b, nouns as c, music as d, modifiers as f, geography as g, insects as h, technologies as i, nature as l, instruments as m, verbs as n, seasons as o, materials as p, trees as r, plants as s, weather as t, mythology as u, flowers as v, birds as w, directions as x, elements as y };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { t as Dictionary } from "./types-DKjF96ZA.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/dictionaries/adjectives.d.ts
|
|
4
|
+
declare const adjectives: Dictionary;
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/dictionaries/adverbs.d.ts
|
|
7
|
+
declare const adverbs: Dictionary;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/dictionaries/animals.d.ts
|
|
10
|
+
declare const animals: Dictionary;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/dictionaries/architecture.d.ts
|
|
13
|
+
declare const architecture: Dictionary;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/dictionaries/birds.d.ts
|
|
16
|
+
declare const birds: Dictionary;
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/dictionaries/categories.d.ts
|
|
19
|
+
declare const categories: Dictionary;
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/dictionaries/colors.d.ts
|
|
22
|
+
declare const colors: Dictionary;
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/dictionaries/directions.d.ts
|
|
25
|
+
declare const directions: Dictionary;
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/dictionaries/domains.d.ts
|
|
28
|
+
declare const domains: Dictionary;
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/dictionaries/elements.d.ts
|
|
31
|
+
declare const elements: Dictionary;
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/dictionaries/flowers.d.ts
|
|
34
|
+
declare const flowers: Dictionary;
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/dictionaries/gemstones.d.ts
|
|
37
|
+
declare const gemstones: Dictionary;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/dictionaries/geography.d.ts
|
|
40
|
+
declare const geography: Dictionary;
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/dictionaries/insects.d.ts
|
|
43
|
+
declare const insects: Dictionary;
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/dictionaries/instruments.d.ts
|
|
46
|
+
declare const instruments: Dictionary;
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/dictionaries/materials.d.ts
|
|
49
|
+
declare const materials: Dictionary;
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/dictionaries/modifiers.d.ts
|
|
52
|
+
declare const modifiers: Dictionary;
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/dictionaries/music.d.ts
|
|
55
|
+
declare const music: Dictionary;
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/dictionaries/mythology.d.ts
|
|
58
|
+
declare const mythology: Dictionary;
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/dictionaries/nature.d.ts
|
|
61
|
+
declare const nature: Dictionary;
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/dictionaries/nouns.d.ts
|
|
64
|
+
declare const nouns: Dictionary;
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/dictionaries/plants.d.ts
|
|
67
|
+
declare const plants: Dictionary;
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/dictionaries/seasons.d.ts
|
|
70
|
+
declare const seasons: Dictionary;
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/dictionaries/space.d.ts
|
|
73
|
+
declare const space: Dictionary;
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/dictionaries/technologies.d.ts
|
|
76
|
+
declare const technologies: Dictionary;
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/dictionaries/trees.d.ts
|
|
79
|
+
declare const trees: Dictionary;
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/dictionaries/verbs.d.ts
|
|
82
|
+
declare const verbs: Dictionary;
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/dictionaries/weather.d.ts
|
|
85
|
+
declare const weather: Dictionary;
|
|
86
|
+
//#endregion
|
|
87
|
+
export { categories as C, adverbs as D, animals as E, adjectives as O, colors as S, architecture as T, gemstones as _, space as a, domains as b, nouns as c, music as d, modifiers as f, geography as g, insects as h, technologies as i, nature as l, instruments as m, verbs as n, seasons as o, materials as p, trees as r, plants as s, weather as t, mythology as u, flowers as v, birds as w, directions as x, elements as y };
|
|
@@ -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
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_dictionaries = require("./dictionaries-DwfVfnJX.cjs");
|
|
3
|
+
const require_patterns = require("./patterns-DC47BwpJ.cjs");
|
|
4
|
+
const require_random = require("./random.cjs");
|
|
5
|
+
//#region src/suffix.ts
|
|
6
|
+
const defaultSuffix = ({ random }) => random.alphanumeric(6);
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/validation.ts
|
|
9
|
+
const separators = [
|
|
10
|
+
"-",
|
|
11
|
+
"_",
|
|
12
|
+
".",
|
|
13
|
+
"~"
|
|
14
|
+
];
|
|
15
|
+
const invalidWordCharacter = /[^a-z]/;
|
|
16
|
+
const invalidSuffixCharacter = /[^a-z0-9]/;
|
|
17
|
+
function isWord(value) {
|
|
18
|
+
return typeof value === "string" && value.length > 0 && !invalidWordCharacter.test(value);
|
|
19
|
+
}
|
|
20
|
+
function isSuffix(value) {
|
|
21
|
+
return typeof value === "string" && value.length > 0 && !invalidSuffixCharacter.test(value);
|
|
22
|
+
}
|
|
23
|
+
function formatOptions(options) {
|
|
24
|
+
if (options === null || typeof options !== "object" || Array.isArray(options)) throw new TypeError("options must be an object");
|
|
25
|
+
const { separator = "-", maxLength = 63 } = options;
|
|
26
|
+
if (!separators.includes(separator)) throw new TypeError("separator must be one of \"-\", \"_\", \".\", or \"~\"");
|
|
27
|
+
if (!Number.isSafeInteger(maxLength) || maxLength <= 0) throw new RangeError("maxLength must be a positive safe integer");
|
|
28
|
+
return {
|
|
29
|
+
separator,
|
|
30
|
+
maxLength
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function validateSegments(segments) {
|
|
34
|
+
if (!Array.isArray(segments) || segments.length === 0) throw new TypeError("segments must be a nonempty array of dictionaries");
|
|
35
|
+
for (let index = 0; index < segments.length; index++) {
|
|
36
|
+
const dictionary = segments[index];
|
|
37
|
+
if (!Object.hasOwn(segments, index) || !Array.isArray(dictionary) || dictionary.length === 0) throw new TypeError(`segments[${index}] must be a nonempty dictionary array`);
|
|
38
|
+
for (let wordIndex = 0; wordIndex < dictionary.length; wordIndex++) if (!Object.hasOwn(dictionary, wordIndex) || !isWord(dictionary[wordIndex])) throw new TypeError(`segments[${index}][${wordIndex}] must contain lowercase ASCII letters only`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function isLexid(value, options = {}) {
|
|
42
|
+
const { separator, maxLength } = formatOptions(options);
|
|
43
|
+
const { hasSuffix = true } = options;
|
|
44
|
+
if (typeof hasSuffix !== "boolean") throw new TypeError("hasSuffix must be a boolean");
|
|
45
|
+
if (typeof value !== "string" || value.length > maxLength) return false;
|
|
46
|
+
const parts = value.split(separator);
|
|
47
|
+
if (!hasSuffix) return parts.every(isWord);
|
|
48
|
+
const suffix = parts.pop();
|
|
49
|
+
return parts.length > 0 && isSuffix(suffix) && parts.every(isWord);
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/lexid.ts
|
|
53
|
+
function lexid(options = {}) {
|
|
54
|
+
const { separator, maxLength } = formatOptions(options);
|
|
55
|
+
const { suffix = defaultSuffix } = options;
|
|
56
|
+
if (suffix !== false && typeof suffix !== "function") throw new TypeError("suffix must be false or a function");
|
|
57
|
+
const { segments = require_patterns.pickPattern(require_patterns.defaultPatterns) } = options;
|
|
58
|
+
validateSegments(segments);
|
|
59
|
+
const words = [];
|
|
60
|
+
for (let index = 0; index < segments.length; index++) {
|
|
61
|
+
const dictionary = segments[index];
|
|
62
|
+
words.push(dictionary[require_random.random.int(dictionary.length)]);
|
|
63
|
+
}
|
|
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);
|
|
74
|
+
if (value.length > maxLength) throw new RangeError(`Generated identifier length ${value.length} exceeds maxLength ${maxLength}`);
|
|
75
|
+
if (!isLexid(value, {
|
|
76
|
+
separator,
|
|
77
|
+
maxLength,
|
|
78
|
+
hasSuffix: suffix !== false
|
|
79
|
+
})) throw new TypeError("Generated identifier contains an invalid segment");
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
function lexids(count, options) {
|
|
83
|
+
if (!Number.isSafeInteger(count) || count < 0) throw new RangeError("count must be a nonnegative safe integer");
|
|
84
|
+
if (count > 4294967295) throw new RangeError("count exceeds the maximum JavaScript array length");
|
|
85
|
+
return Array.from({ length: count }, () => lexid(options));
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
exports.adjectives = require_dictionaries.adjectives;
|
|
89
|
+
exports.adverbs = require_dictionaries.adverbs;
|
|
90
|
+
exports.animals = require_dictionaries.animals;
|
|
91
|
+
exports.architecture = require_dictionaries.architecture;
|
|
92
|
+
exports.birds = require_dictionaries.birds;
|
|
93
|
+
exports.categories = require_dictionaries.categories;
|
|
94
|
+
exports.colors = require_dictionaries.colors;
|
|
95
|
+
exports.defaultPatterns = require_patterns.defaultPatterns;
|
|
96
|
+
exports.defaultSuffix = defaultSuffix;
|
|
97
|
+
exports.directions = require_dictionaries.directions;
|
|
98
|
+
exports.domains = require_dictionaries.domains;
|
|
99
|
+
exports.elements = require_dictionaries.elements;
|
|
100
|
+
exports.fiveSegmentPatterns = require_patterns.fiveSegmentPatterns;
|
|
101
|
+
exports.flowers = require_dictionaries.flowers;
|
|
102
|
+
exports.fourSegmentPatterns = require_patterns.fourSegmentPatterns;
|
|
103
|
+
exports.fourWordPatterns = require_patterns.fourWordPatterns;
|
|
104
|
+
exports.gemstones = require_dictionaries.gemstones;
|
|
105
|
+
exports.geography = require_dictionaries.geography;
|
|
106
|
+
exports.insects = require_dictionaries.insects;
|
|
107
|
+
exports.instruments = require_dictionaries.instruments;
|
|
108
|
+
exports.isLexid = isLexid;
|
|
109
|
+
exports.lexid = lexid;
|
|
110
|
+
exports.lexids = lexids;
|
|
111
|
+
exports.materials = require_dictionaries.materials;
|
|
112
|
+
exports.modifiers = require_dictionaries.modifiers;
|
|
113
|
+
exports.music = require_dictionaries.music;
|
|
114
|
+
exports.mythology = require_dictionaries.mythology;
|
|
115
|
+
exports.nature = require_dictionaries.nature;
|
|
116
|
+
exports.nouns = require_dictionaries.nouns;
|
|
117
|
+
exports.pickPattern = require_patterns.pickPattern;
|
|
118
|
+
exports.plants = require_dictionaries.plants;
|
|
119
|
+
exports.random = require_random.random;
|
|
120
|
+
exports.seasons = require_dictionaries.seasons;
|
|
121
|
+
exports.space = require_dictionaries.space;
|
|
122
|
+
exports.technologies = require_dictionaries.technologies;
|
|
123
|
+
exports.threeWordPatterns = require_patterns.threeWordPatterns;
|
|
124
|
+
exports.trees = require_dictionaries.trees;
|
|
125
|
+
exports.verbs = require_dictionaries.verbs;
|
|
126
|
+
exports.weather = require_dictionaries.weather;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
import { random } from "./random.cjs";
|
|
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
|
+
|
|
6
|
+
//#region src/lexid.d.ts
|
|
7
|
+
declare function lexid(options?: LexidOptions): string;
|
|
8
|
+
declare function lexids(count: number, options?: LexidOptions): string[];
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/validation.d.ts
|
|
11
|
+
declare function isLexid(value: string, options?: LexidValidateOptions): boolean;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/suffix.d.ts
|
|
14
|
+
declare const defaultSuffix: SuffixGenerator;
|
|
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, 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
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
import { random } from "./random.mjs";
|
|
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
|
+
|
|
6
|
+
//#region src/lexid.d.ts
|
|
7
|
+
declare function lexid(options?: LexidOptions): string;
|
|
8
|
+
declare function lexids(count: number, options?: LexidOptions): string[];
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/validation.d.ts
|
|
11
|
+
declare function isLexid(value: string, options?: LexidValidateOptions): boolean;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/suffix.d.ts
|
|
14
|
+
declare const defaultSuffix: SuffixGenerator;
|
|
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, 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
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
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 { a as threeWordPatterns, i as pickPattern, n as fiveSegmentPatterns, o as fourWordPatterns, r as fourSegmentPatterns, t as defaultPatterns } from "./patterns-H0XRwCVB.mjs";
|
|
3
|
+
import { random } from "./random.mjs";
|
|
4
|
+
//#region src/suffix.ts
|
|
5
|
+
const defaultSuffix = ({ random }) => random.alphanumeric(6);
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/validation.ts
|
|
8
|
+
const separators = [
|
|
9
|
+
"-",
|
|
10
|
+
"_",
|
|
11
|
+
".",
|
|
12
|
+
"~"
|
|
13
|
+
];
|
|
14
|
+
const invalidWordCharacter = /[^a-z]/;
|
|
15
|
+
const invalidSuffixCharacter = /[^a-z0-9]/;
|
|
16
|
+
function isWord(value) {
|
|
17
|
+
return typeof value === "string" && value.length > 0 && !invalidWordCharacter.test(value);
|
|
18
|
+
}
|
|
19
|
+
function isSuffix(value) {
|
|
20
|
+
return typeof value === "string" && value.length > 0 && !invalidSuffixCharacter.test(value);
|
|
21
|
+
}
|
|
22
|
+
function formatOptions(options) {
|
|
23
|
+
if (options === null || typeof options !== "object" || Array.isArray(options)) throw new TypeError("options must be an object");
|
|
24
|
+
const { separator = "-", maxLength = 63 } = options;
|
|
25
|
+
if (!separators.includes(separator)) throw new TypeError("separator must be one of \"-\", \"_\", \".\", or \"~\"");
|
|
26
|
+
if (!Number.isSafeInteger(maxLength) || maxLength <= 0) throw new RangeError("maxLength must be a positive safe integer");
|
|
27
|
+
return {
|
|
28
|
+
separator,
|
|
29
|
+
maxLength
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function validateSegments(segments) {
|
|
33
|
+
if (!Array.isArray(segments) || segments.length === 0) throw new TypeError("segments must be a nonempty array of dictionaries");
|
|
34
|
+
for (let index = 0; index < segments.length; index++) {
|
|
35
|
+
const dictionary = segments[index];
|
|
36
|
+
if (!Object.hasOwn(segments, index) || !Array.isArray(dictionary) || dictionary.length === 0) throw new TypeError(`segments[${index}] must be a nonempty dictionary array`);
|
|
37
|
+
for (let wordIndex = 0; wordIndex < dictionary.length; wordIndex++) if (!Object.hasOwn(dictionary, wordIndex) || !isWord(dictionary[wordIndex])) throw new TypeError(`segments[${index}][${wordIndex}] must contain lowercase ASCII letters only`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function isLexid(value, options = {}) {
|
|
41
|
+
const { separator, maxLength } = formatOptions(options);
|
|
42
|
+
const { hasSuffix = true } = options;
|
|
43
|
+
if (typeof hasSuffix !== "boolean") throw new TypeError("hasSuffix must be a boolean");
|
|
44
|
+
if (typeof value !== "string" || value.length > maxLength) return false;
|
|
45
|
+
const parts = value.split(separator);
|
|
46
|
+
if (!hasSuffix) return parts.every(isWord);
|
|
47
|
+
const suffix = parts.pop();
|
|
48
|
+
return parts.length > 0 && isSuffix(suffix) && parts.every(isWord);
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/lexid.ts
|
|
52
|
+
function lexid(options = {}) {
|
|
53
|
+
const { separator, maxLength } = formatOptions(options);
|
|
54
|
+
const { suffix = defaultSuffix } = options;
|
|
55
|
+
if (suffix !== false && typeof suffix !== "function") throw new TypeError("suffix must be false or a function");
|
|
56
|
+
const { segments = pickPattern(defaultPatterns) } = options;
|
|
57
|
+
validateSegments(segments);
|
|
58
|
+
const words = [];
|
|
59
|
+
for (let index = 0; index < segments.length; index++) {
|
|
60
|
+
const dictionary = segments[index];
|
|
61
|
+
words.push(dictionary[random.int(dictionary.length)]);
|
|
62
|
+
}
|
|
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);
|
|
73
|
+
if (value.length > maxLength) throw new RangeError(`Generated identifier length ${value.length} exceeds maxLength ${maxLength}`);
|
|
74
|
+
if (!isLexid(value, {
|
|
75
|
+
separator,
|
|
76
|
+
maxLength,
|
|
77
|
+
hasSuffix: suffix !== false
|
|
78
|
+
})) throw new TypeError("Generated identifier contains an invalid segment");
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
function lexids(count, options) {
|
|
82
|
+
if (!Number.isSafeInteger(count) || count < 0) throw new RangeError("count must be a nonnegative safe integer");
|
|
83
|
+
if (count > 4294967295) throw new RangeError("count exceeds the maximum JavaScript array length");
|
|
84
|
+
return Array.from({ length: count }, () => lexid(options));
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
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 };
|