@fgv/ts-random 5.1.0-8 → 5.1.0-9

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.
Files changed (118) hide show
  1. package/.rush/temp/chunked-rush-logs/ts-random.build.chunks.jsonl +6 -0
  2. package/.rush/temp/f2b77fef5ae7ce9231b50310b3a1f4766e374fe0.tar.log +121 -0
  3. package/.rush/temp/operation/build/all.log +6 -0
  4. package/.rush/temp/operation/build/log-chunks.jsonl +6 -0
  5. package/.rush/temp/operation/build/state.json +3 -0
  6. package/.rush/temp/shrinkwrap-deps.json +610 -0
  7. package/dist/generator/generators.js +207 -0
  8. package/dist/generator/generators.js.map +1 -0
  9. package/dist/generator/index.js +22 -0
  10. package/dist/generator/index.js.map +1 -0
  11. package/dist/generator/randomSource.js +141 -0
  12. package/dist/generator/randomSource.js.map +1 -0
  13. package/dist/generator-data/charClasses.js +95 -0
  14. package/dist/generator-data/charClasses.js.map +1 -0
  15. package/dist/generator-data/index.js +22 -0
  16. package/dist/generator-data/index.js.map +1 -0
  17. package/dist/generator-data/words/adjectives.js +247 -0
  18. package/dist/generator-data/words/adjectives.js.map +1 -0
  19. package/dist/generator-data/words/animals.js +75 -0
  20. package/dist/generator-data/words/animals.js.map +1 -0
  21. package/dist/generator-data/words/cities.js +229 -0
  22. package/dist/generator-data/words/cities.js.map +1 -0
  23. package/dist/generator-data/words/colors.js +56 -0
  24. package/dist/generator-data/words/colors.js.map +1 -0
  25. package/dist/generator-data/words/countries.js +217 -0
  26. package/dist/generator-data/words/countries.js.map +1 -0
  27. package/dist/generator-data/words/domains.js +47 -0
  28. package/dist/generator-data/words/domains.js.map +1 -0
  29. package/dist/generator-data/words/gerunds.js +126 -0
  30. package/dist/generator-data/words/gerunds.js.map +1 -0
  31. package/dist/generator-data/words/index.js +29 -0
  32. package/dist/generator-data/words/index.js.map +1 -0
  33. package/dist/generator-data/words/jobs.js +175 -0
  34. package/dist/generator-data/words/jobs.js.map +1 -0
  35. package/dist/generator-data/words/names.js +714 -0
  36. package/dist/generator-data/words/names.js.map +1 -0
  37. package/dist/index.js +7 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/test/unit/generators.test.js +596 -0
  40. package/dist/test/unit/generators.test.js.map +1 -0
  41. package/dist/test/unit/randomSource.test.js +452 -0
  42. package/dist/test/unit/randomSource.test.js.map +1 -0
  43. package/lib/generator/generators.d.ts +142 -0
  44. package/lib/generator/generators.d.ts.map +1 -0
  45. package/lib/generator/generators.js +211 -0
  46. package/lib/generator/generators.js.map +1 -0
  47. package/lib/generator/index.d.ts +3 -0
  48. package/lib/generator/index.d.ts.map +1 -0
  49. package/lib/generator/index.js +38 -0
  50. package/lib/generator/index.js.map +1 -0
  51. package/lib/generator/randomSource.d.ts +115 -0
  52. package/lib/generator/randomSource.d.ts.map +1 -0
  53. package/lib/generator/randomSource.js +145 -0
  54. package/lib/generator/randomSource.js.map +1 -0
  55. package/lib/generator-data/charClasses.d.ts +76 -0
  56. package/lib/generator-data/charClasses.d.ts.map +1 -0
  57. package/lib/generator-data/charClasses.js +98 -0
  58. package/lib/generator-data/charClasses.js.map +1 -0
  59. package/lib/generator-data/index.d.ts +3 -0
  60. package/lib/generator-data/index.d.ts.map +1 -0
  61. package/lib/generator-data/index.js +58 -0
  62. package/lib/generator-data/index.js.map +1 -0
  63. package/lib/generator-data/words/adjectives.d.ts +2 -0
  64. package/lib/generator-data/words/adjectives.d.ts.map +1 -0
  65. package/lib/generator-data/words/adjectives.js +250 -0
  66. package/lib/generator-data/words/adjectives.js.map +1 -0
  67. package/lib/generator-data/words/animals.d.ts +2 -0
  68. package/lib/generator-data/words/animals.d.ts.map +1 -0
  69. package/lib/generator-data/words/animals.js +78 -0
  70. package/lib/generator-data/words/animals.js.map +1 -0
  71. package/lib/generator-data/words/cities.d.ts +2 -0
  72. package/lib/generator-data/words/cities.d.ts.map +1 -0
  73. package/lib/generator-data/words/cities.js +232 -0
  74. package/lib/generator-data/words/cities.js.map +1 -0
  75. package/lib/generator-data/words/colors.d.ts +2 -0
  76. package/lib/generator-data/words/colors.d.ts.map +1 -0
  77. package/lib/generator-data/words/colors.js +59 -0
  78. package/lib/generator-data/words/colors.js.map +1 -0
  79. package/lib/generator-data/words/countries.d.ts +2 -0
  80. package/lib/generator-data/words/countries.d.ts.map +1 -0
  81. package/lib/generator-data/words/countries.js +220 -0
  82. package/lib/generator-data/words/countries.js.map +1 -0
  83. package/lib/generator-data/words/domains.d.ts +2 -0
  84. package/lib/generator-data/words/domains.d.ts.map +1 -0
  85. package/lib/generator-data/words/domains.js +50 -0
  86. package/lib/generator-data/words/domains.js.map +1 -0
  87. package/lib/generator-data/words/gerunds.d.ts +2 -0
  88. package/lib/generator-data/words/gerunds.d.ts.map +1 -0
  89. package/lib/generator-data/words/gerunds.js +129 -0
  90. package/lib/generator-data/words/gerunds.js.map +1 -0
  91. package/lib/generator-data/words/index.d.ts +10 -0
  92. package/lib/generator-data/words/index.d.ts.map +1 -0
  93. package/lib/generator-data/words/index.js +45 -0
  94. package/lib/generator-data/words/index.js.map +1 -0
  95. package/lib/generator-data/words/jobs.d.ts +2 -0
  96. package/lib/generator-data/words/jobs.d.ts.map +1 -0
  97. package/lib/generator-data/words/jobs.js +178 -0
  98. package/lib/generator-data/words/jobs.js.map +1 -0
  99. package/lib/generator-data/words/names.d.ts +21 -0
  100. package/lib/generator-data/words/names.d.ts.map +1 -0
  101. package/lib/generator-data/words/names.js +717 -0
  102. package/lib/generator-data/words/names.js.map +1 -0
  103. package/lib/index.d.ts +7 -0
  104. package/lib/index.d.ts.map +1 -0
  105. package/lib/index.js +43 -0
  106. package/lib/index.js.map +1 -0
  107. package/lib/test/unit/generators.test.d.ts +2 -0
  108. package/lib/test/unit/generators.test.d.ts.map +1 -0
  109. package/lib/test/unit/generators.test.js +598 -0
  110. package/lib/test/unit/generators.test.js.map +1 -0
  111. package/lib/test/unit/randomSource.test.d.ts +2 -0
  112. package/lib/test/unit/randomSource.test.d.ts.map +1 -0
  113. package/lib/test/unit/randomSource.test.js +454 -0
  114. package/lib/test/unit/randomSource.test.js.map +1 -0
  115. package/package.json +17 -17
  116. package/rush-logs/ts-random.build.cache.log +3 -0
  117. package/rush-logs/ts-random.build.log +6 -0
  118. package/temp/build/typescript/ts_8nwakTlr.json +1 -0
@@ -0,0 +1,207 @@
1
+ // Copyright (c) 2026 Erik Fortune
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in all
11
+ // copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ // SOFTWARE.
20
+ import { captureResult, Success } from '@fgv/ts-utils';
21
+ import { SeededRandomSource } from './randomSource';
22
+ /**
23
+ * A pseudo-random number generator that can be used to generate random values
24
+ * of various shapes.
25
+ * @public
26
+ */
27
+ export class PseudoRandomGenerator {
28
+ constructor(rng) {
29
+ this.rng = rng;
30
+ }
31
+ /**
32
+ * Creates a new pseudo-random number generator.
33
+ * @param params - The parameters for creating the generator.
34
+ * @returns A result containing the new generator or an error.
35
+ */
36
+ static create(params = {}) {
37
+ return SeededRandomSource.create(params)
38
+ .onSuccess((rng) => captureResult(() => new PseudoRandomGenerator(rng)))
39
+ .onSuccess((generator) => {
40
+ if ((params === null || params === void 0 ? void 0 : params.global) === true) {
41
+ PseudoRandomGenerator.setGlobalRng(generator);
42
+ }
43
+ return Success.with(generator);
44
+ });
45
+ }
46
+ /**
47
+ * Creates a clone of this generator.
48
+ * @returns A new generator with the same state.
49
+ */
50
+ clone() {
51
+ return new PseudoRandomGenerator(this.rng.clone());
52
+ }
53
+ /**
54
+ * Creates a child generator with the given label.
55
+ * @param label - The label for the child generator.
56
+ * @returns A new generator with the given label.
57
+ */
58
+ createChild(label) {
59
+ return new PseudoRandomGenerator(this.rng.createChild(label));
60
+ }
61
+ /**
62
+ * Generates a random float between 0 and 1.
63
+ * @returns A random float between 0 and 1.
64
+ */
65
+ nextFloat() {
66
+ return this.rng.next();
67
+ }
68
+ /**
69
+ * Generates a random integer between 0 and the specified extent (positive or negative).
70
+ * @param extent - The maximum (or minimum) value (exclusive).
71
+ * @returns A random integer between 0 and the specified extent.
72
+ */
73
+ nextInt(extent) {
74
+ if (extent !== undefined && Number.isFinite(extent)) {
75
+ if (extent < 0) {
76
+ return Math.ceil(this.rng.next() * extent);
77
+ }
78
+ return Math.floor(this.rng.next() * extent);
79
+ }
80
+ return Math.floor(this.rng.next() * Number.MAX_SAFE_INTEGER);
81
+ }
82
+ /**
83
+ * Generates a random integer between the specified minimum and maximum values.
84
+ * @param min - The minimum value (inclusive).
85
+ * @param max - The maximum value (inclusive).
86
+ * @returns A random integer between the specified minimum and maximum values.
87
+ * @remarks If min is greater than max, the values are swapped.
88
+ */
89
+ nextInRange(min, max) {
90
+ min = min !== null && min !== void 0 ? min : 0;
91
+ max = max !== null && max !== void 0 ? max : Number.MAX_SAFE_INTEGER;
92
+ if (min > max) {
93
+ return Math.ceil(this.rng.next() * (min - max - 1)) + max;
94
+ }
95
+ return Math.floor(this.rng.next() * (max - min + 1)) + min;
96
+ }
97
+ /**
98
+ * Generates a random boolean value.
99
+ * @param trueProbability - The probability of returning true (default is 0.5).
100
+ * @returns A random boolean value.
101
+ */
102
+ nextBoolean(trueProbability = 0.5) {
103
+ return this.rng.next() < trueProbability;
104
+ }
105
+ /**
106
+ * Generates a random string of the specified length using the given characters.
107
+ * @param length - The length of the string to generate.
108
+ * @param chars - The characters to use for the string (default is alphanumeric).
109
+ * @returns A random string of the specified length.
110
+ */
111
+ nextString(length, chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') {
112
+ let result = '';
113
+ for (let i = 0; i < length; i++) {
114
+ result += chars[this.nextInt(chars.length)];
115
+ }
116
+ return result;
117
+ }
118
+ /**
119
+ * Generates a random item from the given array.
120
+ * @param items - The array to select from.
121
+ * @returns A random item from the array or undefined if the array is empty.
122
+ */
123
+ pickNext(items) {
124
+ if (items === undefined || items.length === 0) {
125
+ return undefined;
126
+ }
127
+ return items[this.nextInt(items.length)];
128
+ }
129
+ /**
130
+ * Generates a sequence of values by randomly selecting from the given candidate
131
+ * dictionaries in order.
132
+ * @param params - The parameters for generating the sequence.
133
+ * @returns A sequence of values.
134
+ */
135
+ pickSequential(params) {
136
+ var _a;
137
+ const count = (_a = params.count) !== null && _a !== void 0 ? _a : params.candidates.length;
138
+ const items = [];
139
+ for (let i = 0; i < count; i++) {
140
+ const dIndex = i % params.candidates.length;
141
+ const item = this.pickNext(params.candidates[dIndex]);
142
+ if (item !== undefined) {
143
+ items.push(item);
144
+ }
145
+ }
146
+ return items;
147
+ }
148
+ /**
149
+ * Generates a sequence of values by randomly selecting from the supplied
150
+ * dictionaries in random order.
151
+ * @param params - The parameters for generating the sequence.
152
+ * @returns A sequence of values.
153
+ */
154
+ pickRandom(params) {
155
+ const items = [];
156
+ for (let i = 0; i < params.count; i++) {
157
+ const dIndex = this.nextInt(params.candidates.length);
158
+ const item = this.pickNext(params.candidates[dIndex]);
159
+ if (item !== undefined) {
160
+ items.push(item);
161
+ }
162
+ }
163
+ return items;
164
+ }
165
+ /**
166
+ * Generates a sequence of values by randomly selecting from the given candidates.
167
+ * @param params - The parameters for generating the sequence.
168
+ * @returns A sequence of values.
169
+ */
170
+ pickSequence(params) {
171
+ if (params.how === 'sequence') {
172
+ return this.pickSequential(params);
173
+ }
174
+ else {
175
+ return this.pickRandom(params);
176
+ }
177
+ }
178
+ /**
179
+ * Sets this generator as the global random number generator.
180
+ * @returns A result containing this generator or an error.
181
+ */
182
+ static setGlobalRng(rng) {
183
+ PseudoRandomGenerator._globalRng = rng;
184
+ return rng;
185
+ }
186
+ /**
187
+ * Gets the global random number generator.
188
+ * @returns The global random number generator or undefined if not set.
189
+ */
190
+ static getGlobalRng() {
191
+ return PseudoRandomGenerator._globalRng;
192
+ }
193
+ /**
194
+ * Ensures a random number generator is available, using the global generator if available
195
+ * or creating a new one if not.
196
+ * @param rng - The random number generator to use, or undefined to use the global one.
197
+ * @returns A random number generator.
198
+ */
199
+ static ensureRng(rng) {
200
+ rng = rng !== null && rng !== void 0 ? rng : PseudoRandomGenerator.getGlobalRng();
201
+ if (rng) {
202
+ return Success.with(rng);
203
+ }
204
+ return PseudoRandomGenerator.create();
205
+ }
206
+ }
207
+ //# sourceMappingURL=generators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generators.js","sourceRoot":"","sources":["../../src/generator/generators.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,EAAE;AACF,iFAAiF;AACjF,kDAAkD;AAClD,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY;AAEZ,OAAO,EAAE,aAAa,EAAU,OAAO,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAsB,kBAAkB,EAAE,MAAM,gBAAg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;YACtD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACvB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnB,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;OAIG;IACI,YAAY,CAAI,MAA6B;QAClD,IAAI,MAAM,CAAC,GAAG,KAAK,UAAU,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QACrC,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,YAAY,CAAC,GAA2B;QACpD,qBAAqB,CAAC,UAAU,GAAG,GAAG,CAAC;QACvC,OAAO,GAAG,CAAC;IACb,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,YAAY;QACxB,OAAO,qBAAqB,CAAC,UAAU,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,SAAS,CAAC,GAA2B;QACjD,GAAG,GAAG,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,qBAAqB,CAAC,YAAY,EAAE,CAAC;QAClD,IAAI,GAAG,EAAE,CAAC;YACR,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC;QACD,OAAO,qBAAqB,CAAC,MAAM,EAAE,CAAC;IACxC,CAAC;CACF","sourcesContent":["// Copyright (c) 2026 Erik Fortune\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\nimport { captureResult, Result, Success } from '@fgv/ts-utils';\nimport { RandomStepFunction, SeededRandomSource } from './randomSource';\n\n/**\n * Parameters for creating a generator.\n * @public\n */\nexport interface IPseudoRandomGeneratorCreateParams {\n seed?: number | string;\n step?: RandomStepFunction;\n global?: boolean;\n}\n\n/**\n * Parameters for generating a sequence of values\n * from each dictionary in a supplied set, in turn.\n * @public\n */\nexport interface ISequentialPickParams<T> {\n how: 'sequence';\n count?: number;\n candidates: ReadonlyArray<ReadonlyArray<T>>;\n}\n\n/**\n * Parameters for generating a sequence of values\n * by randomly selecting from dictionaries in a supplied set.\n * @public\n */\nexport interface IRandomSequencePickParams<T> {\n how: 'random';\n count: number;\n candidates: ReadonlyArray<ReadonlyArray<T>>;\n}\n\n/**\n * Type representing parameters for generating a sequence of values.\n * @public\n */\nexport type SequencePickParams<T> = ISequentialPickParams<T> | IRandomSequencePickParams<T>;\n\n/**\n * A pseudo-random number generator that can be used to generate random values\n * of various shapes.\n * @public\n */\nexport class PseudoRandomGenerator {\n private static _globalRng: PseudoRandomGenerator | undefined;\n\n /**\n * The underlying random number generator.\n */\n public readonly rng: SeededRandomSource;\n\n private constructor(rng: SeededRandomSource) {\n this.rng = rng;\n }\n\n /**\n * Creates a new pseudo-random number generator.\n * @param params - The parameters for creating the generator.\n * @returns A result containing the new generator or an error.\n */\n public static create(params: IPseudoRandomGeneratorCreateParams = {}): Result<PseudoRandomGenerator> {\n return SeededRandomSource.create(params)\n .onSuccess((rng) => captureResult(() => new PseudoRandomGenerator(rng)))\n .onSuccess((generator) => {\n if (params?.global === true) {\n PseudoRandomGenerator.setGlobalRng(generator);\n }\n return Success.with(generator);\n });\n }\n\n /**\n * Creates a clone of this generator.\n * @returns A new generator with the same state.\n */\n public clone(): PseudoRandomGenerator {\n return new PseudoRandomGenerator(this.rng.clone());\n }\n\n /**\n * Creates a child generator with the given label.\n * @param label - The label for the child generator.\n * @returns A new generator with the given label.\n */\n public createChild(label: string): PseudoRandomGenerator {\n return new PseudoRandomGenerator(this.rng.createChild(label));\n }\n\n /**\n * Generates a random float between 0 and 1.\n * @returns A random float between 0 and 1.\n */\n public nextFloat(): number {\n return this.rng.next();\n }\n\n /**\n * Generates a random integer between 0 and the specified extent (positive or negative).\n * @param extent - The maximum (or minimum) value (exclusive).\n * @returns A random integer between 0 and the specified extent.\n */\n public nextInt(extent?: number): number {\n if (extent !== undefined && Number.isFinite(extent)) {\n if (extent < 0) {\n return Math.ceil(this.rng.next() * extent);\n }\n return Math.floor(this.rng.next() * extent);\n }\n return Math.floor(this.rng.next() * Number.MAX_SAFE_INTEGER);\n }\n\n /**\n * Generates a random integer between the specified minimum and maximum values.\n * @param min - The minimum value (inclusive).\n * @param max - The maximum value (inclusive).\n * @returns A random integer between the specified minimum and maximum values.\n * @remarks If min is greater than max, the values are swapped.\n */\n public nextInRange(min: number | undefined, max: number | undefined): number {\n min = min ?? 0;\n max = max ?? Number.MAX_SAFE_INTEGER;\n if (min > max) {\n return Math.ceil(this.rng.next() * (min - max - 1)) + max;\n }\n return Math.floor(this.rng.next() * (max - min + 1)) + min;\n }\n\n /**\n * Generates a random boolean value.\n * @param trueProbability - The probability of returning true (default is 0.5).\n * @returns A random boolean value.\n */\n public nextBoolean(trueProbability: number = 0.5): boolean {\n return this.rng.next() < trueProbability;\n }\n\n /**\n * Generates a random string of the specified length using the given characters.\n * @param length - The length of the string to generate.\n * @param chars - The characters to use for the string (default is alphanumeric).\n * @returns A random string of the specified length.\n */\n public nextString(\n length: number,\n chars: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'\n ): string {\n let result = '';\n for (let i = 0; i < length; i++) {\n result += chars[this.nextInt(chars.length)];\n }\n return result;\n }\n\n /**\n * Generates a random item from the given array.\n * @param items - The array to select from.\n * @returns A random item from the array or undefined if the array is empty.\n */\n public pickNext<T>(items?: ReadonlyArray<T>): T | undefined {\n if (items === undefined || items.length === 0) {\n return undefined;\n }\n return items[this.nextInt(items.length)];\n }\n\n /**\n * Generates a sequence of values by randomly selecting from the given candidate\n * dictionaries in order.\n * @param params - The parameters for generating the sequence.\n * @returns A sequence of values.\n */\n public pickSequential<T>(params: ISequentialPickParams<T>): ReadonlyArray<T> {\n const count = params.count ?? params.candidates.length;\n const items: T[] = [];\n\n for (let i = 0; i < count; i++) {\n const dIndex = i % params.candidates.length;\n const item = this.pickNext(params.candidates[dIndex]);\n if (item !== undefined) {\n items.push(item);\n }\n }\n\n return items;\n }\n\n /**\n * Generates a sequence of values by randomly selecting from the supplied\n * dictionaries in random order.\n * @param params - The parameters for generating the sequence.\n * @returns A sequence of values.\n */\n public pickRandom<T>(params: IRandomSequencePickParams<T>): ReadonlyArray<T> {\n const items: T[] = [];\n\n for (let i = 0; i < params.count; i++) {\n const dIndex = this.nextInt(params.candidates.length);\n const item = this.pickNext(params.candidates[dIndex]);\n if (item !== undefined) {\n items.push(item);\n }\n }\n\n return items;\n }\n\n /**\n * Generates a sequence of values by randomly selecting from the given candidates.\n * @param params - The parameters for generating the sequence.\n * @returns A sequence of values.\n */\n public pickSequence<T>(params: SequencePickParams<T>): ReadonlyArray<T> {\n if (params.how === 'sequence') {\n return this.pickSequential(params);\n } else {\n return this.pickRandom(params);\n }\n }\n\n /**\n * Sets this generator as the global random number generator.\n * @returns A result containing this generator or an error.\n */\n public static setGlobalRng(rng?: PseudoRandomGenerator): PseudoRandomGenerator | undefined {\n PseudoRandomGenerator._globalRng = rng;\n return rng;\n }\n\n /**\n * Gets the global random number generator.\n * @returns The global random number generator or undefined if not set.\n */\n public static getGlobalRng(): PseudoRandomGenerator | undefined {\n return PseudoRandomGenerator._globalRng;\n }\n\n /**\n * Ensures a random number generator is available, using the global generator if available\n * or creating a new one if not.\n * @param rng - The random number generator to use, or undefined to use the global one.\n * @returns A random number generator.\n */\n public static ensureRng(rng?: PseudoRandomGenerator): Result<PseudoRandomGenerator> {\n rng = rng ?? PseudoRandomGenerator.getGlobalRng();\n if (rng) {\n return Success.with(rng);\n }\n return PseudoRandomGenerator.create();\n }\n}\n"]}
@@ -0,0 +1,22 @@
1
+ // Copyright (c) 2026 Erik Fortune
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in all
11
+ // copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ // SOFTWARE.
20
+ export * from './randomSource';
21
+ export * from './generators';
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,EAAE;AACF,iFAAiF;AACjF,kDAAkD;AAClD,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY;AAEZ,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC","sourcesContent":["// Copyright (c) 2026 Erik Fortune\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\nexport * from './randomSource';\nexport * from './generators';\n"]}
@@ -0,0 +1,141 @@
1
+ // Copyright (c) 2026 Erik Fortune
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in all
11
+ // copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ // SOFTWARE.
20
+ import { captureResult } from '@fgv/ts-utils';
21
+ /**
22
+ * Seeded random number generator that can be cloned and used for deterministic generation.
23
+ * @public
24
+ */
25
+ export class SeededRandomSource {
26
+ /**
27
+ * Gets the current counter value.
28
+ */
29
+ get counter() {
30
+ return this._counter;
31
+ }
32
+ /**
33
+ * Creates a new seeded random source.
34
+ * @param seed - The seed value.
35
+ */
36
+ constructor(init) {
37
+ this.currentState = init.state;
38
+ this.seed = init.seed;
39
+ this._counter = init.counter;
40
+ this._step = init.step;
41
+ this.lineage = init.lineage;
42
+ }
43
+ static create(seedOrInit) {
44
+ var _a, _b;
45
+ const init = typeof seedOrInit === 'object' ? seedOrInit : { seed: seedOrInit };
46
+ const step = (_a = init === null || init === void 0 ? void 0 : init.step) !== null && _a !== void 0 ? _a : SeededRandomSource.mulberryStep;
47
+ const { seed, state } = SeededRandomSource.hashSeed((_b = init === null || init === void 0 ? void 0 : init.seed) !== null && _b !== void 0 ? _b : Date.now());
48
+ return captureResult(() => new SeededRandomSource({
49
+ state,
50
+ seed,
51
+ counter: 0,
52
+ lineage: [],
53
+ step
54
+ }));
55
+ }
56
+ /**
57
+ * Generates the next random number.
58
+ * @returns A random number between 0 and 1.
59
+ */
60
+ next() {
61
+ this._counter += 1;
62
+ const { value, nextState } = this._step(this.currentState);
63
+ this.currentState = nextState;
64
+ return value;
65
+ }
66
+ /**
67
+ * Creates a clone of this random source.
68
+ * @returns A new seeded random source with the same state.
69
+ */
70
+ clone() {
71
+ return new SeededRandomSource({
72
+ state: this.currentState,
73
+ seed: this.seed,
74
+ counter: this._counter,
75
+ lineage: this.lineage,
76
+ step: this._step
77
+ });
78
+ }
79
+ /**
80
+ * Creates a child random source with a label.
81
+ * @param label - The label for the child.
82
+ * @returns A new seeded random source with a hashed state and label.
83
+ */
84
+ createChild(label) {
85
+ const { seed, state } = SeededRandomSource.hashStateAndLabel(this.currentState, label);
86
+ const lineage = [...this.lineage, `${this._counter}:${label}`];
87
+ return new SeededRandomSource({ state, seed, counter: 0, lineage, step: this._step });
88
+ }
89
+ /**
90
+ * Steps a mulberry32 random number generator state and returns the next value.
91
+ * @param currentState - The current state of the generator.
92
+ * @returns The next random number and the next state.
93
+ */
94
+ static mulberryStep(currentState) {
95
+ const nextState = (currentState + 0x6d2b79f5) >>> 0;
96
+ let t = nextState;
97
+ t = Math.imul(t ^ (t >>> 15), t | 1);
98
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
99
+ const value = ((t ^ (t >>> 14)) >>> 0) / 4294967296;
100
+ return { value, nextState };
101
+ }
102
+ /**
103
+ * Hashes a seed value.
104
+ * @param seed - The seed value.
105
+ * @returns A hashed seed value.
106
+ */
107
+ static hashSeed(seed) {
108
+ if (typeof seed === 'number') {
109
+ return { seed: seed.toString(), state: seed };
110
+ }
111
+ const parsedSeed = Number(seed);
112
+ if (!isNaN(parsedSeed) && isFinite(parsedSeed)) {
113
+ return { seed, state: parsedSeed };
114
+ }
115
+ return { seed, state: SeededRandomSource.hashString(seed) };
116
+ }
117
+ /**
118
+ * Hashes a state and label.
119
+ * @param state - The state value.
120
+ * @param label - The label value.
121
+ * @returns A hashed state and label value.
122
+ */
123
+ static hashStateAndLabel(state, label) {
124
+ const seed = `${state >>> 0}:${label}`;
125
+ return { seed, state: SeededRandomSource.hashString(seed) };
126
+ }
127
+ /**
128
+ * Hashes a string value.
129
+ * @param value - The string value.
130
+ * @returns A hashed string value.
131
+ */
132
+ static hashString(value) {
133
+ let hash = 0x811c9dc5;
134
+ for (let index = 0; index < value.length; index++) {
135
+ hash ^= value.charCodeAt(index);
136
+ hash = Math.imul(hash, 0x01000193);
137
+ }
138
+ return hash >>> 0;
139
+ }
140
+ }
141
+ //# sourceMappingURL=randomSource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"randomSource.js","sourceRoot":"","sources":["../../src/generator/randomSource.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,EAAE;AACF,iFAAiF;AACjF,kDAAkD;AAClD,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY;AAEZ,OAAO,EAAE,aAAa,EAAU,MAAM,eAAe,CAAC;AA+CtD;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IAO7B;;OAEG;IACH,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;;OAGG;IACH,YAAsB,IAA0C;QAC9D,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,O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I,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YAC/C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;QACrC,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,kBAAkB,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;IAC9D,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,iBAAiB,CAAC,KAAa,EAAE,KAAa;QAC1D,MAAM,IAAI,GAAG,GAAG,KAAK,KAAK,CAAC,IAAI,KAAK,EAAE,CAAC;QACvC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,kBAAkB,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;IAC9D,CAAC;IAED;;;;OAIG;IACK,MAAM,CAAC,UAAU,CAAC,KAAa;QACrC,IAAI,IAAI,GAAG,UAAU,CAAC;QAEtB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;YAClD,IAAI,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YAChC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACrC,CAAC;QAED,OAAO,IAAI,KAAK,CAAC,CAAC;IACpB,CAAC;CACF","sourcesContent":["// Copyright (c) 2026 Erik Fortune\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\nimport { captureResult, Result } from '@fgv/ts-utils';\n\n/**\n * Represents a seed as both a string and a number.\n * @public\n */\nexport interface ISeedPair {\n seed: string;\n state: number;\n}\n\n/**\n * Result of an internal next() operation.\n * @public\n */\nexport interface INextResult {\n value: number;\n nextState: number;\n}\n\n/**\n * Function that steps a random number generator state and returns the next value.\n * @public\n */\nexport type RandomStepFunction = (state: number) => INextResult;\n\n/**\n * Constructor params for a {@link Generator.SeededRandomSource | SeededRandomSource}.\n * @public\n */\nexport interface ISeededRandomSourceConstructorParams {\n state: number;\n seed: string;\n counter: number;\n lineage: ReadonlyArray<string>;\n step: RandomStepFunction;\n}\n\n/**\n * Static create parameters for a {@link Generator.SeededRandomSource | SeededRandomSource}.\n * @public\n */\nexport interface ISeededRandomSourceCreateParams {\n seed?: number | string;\n step?: RandomStepFunction;\n}\n\n/**\n * Seeded random number generator that can be cloned and used for deterministic generation.\n * @public\n */\nexport class SeededRandomSource {\n private currentState: number;\n public readonly seed: string;\n public readonly lineage: ReadonlyArray<string>;\n private _counter: number;\n private _step: RandomStepFunction;\n\n /**\n * Gets the current counter value.\n */\n public get counter(): number {\n return this._counter;\n }\n\n /**\n * Creates a new seeded random source.\n * @param seed - The seed value.\n */\n protected constructor(init: ISeededRandomSourceConstructorParams) {\n this.currentState = init.state;\n this.seed = init.seed;\n this._counter = init.counter;\n this._step = init.step;\n this.lineage = init.lineage;\n }\n\n /**\n * Creates a new seeded random source from an optional seed.\n * @param seed - The optional seed value.\n * @returns A new seeded random source.\n */\n public static create(seed?: number | string): Result<SeededRandomSource>;\n\n /**\n * Creates a new seeded random source from {@link Generator.ISeededRandomSourceCreateParams | ISeededRandomSourceCreateParams}.\n * @param init - The initialization parameters.\n * @returns A new seeded random source.\n */\n public static create(init: ISeededRandomSourceCreateParams): Result<SeededRandomSource>;\n\n public static create(\n seedOrInit?: number | string | ISeededRandomSourceCreateParams\n ): Result<SeededRandomSource> {\n const init = typeof seedOrInit === 'object' ? seedOrInit : { seed: seedOrInit };\n const step = init?.step ?? SeededRandomSource.mulberryStep;\n const { seed, state } = SeededRandomSource.hashSeed(init?.seed ?? Date.now());\n return captureResult(\n () =>\n new SeededRandomSource({\n state,\n seed,\n counter: 0,\n lineage: [],\n step\n })\n );\n }\n\n /**\n * Generates the next random number.\n * @returns A random number between 0 and 1.\n */\n public next(): number {\n this._counter += 1;\n const { value, nextState } = this._step(this.currentState);\n this.currentState = nextState;\n return value;\n }\n\n /**\n * Creates a clone of this random source.\n * @returns A new seeded random source with the same state.\n */\n public clone(): SeededRandomSource {\n return new SeededRandomSource({\n state: this.currentState,\n seed: this.seed,\n counter: this._counter,\n lineage: this.lineage,\n step: this._step\n });\n }\n\n /**\n * Creates a child random source with a label.\n * @param label - The label for the child.\n * @returns A new seeded random source with a hashed state and label.\n */\n public createChild(label: string): SeededRandomSource {\n const { seed, state } = SeededRandomSource.hashStateAndLabel(this.currentState, label);\n const lineage = [...this.lineage, `${this._counter}:${label}`];\n return new SeededRandomSource({ state, seed, counter: 0, lineage, step: this._step });\n }\n\n /**\n * Steps a mulberry32 random number generator state and returns the next value.\n * @param currentState - The current state of the generator.\n * @returns The next random number and the next state.\n */\n public static mulberryStep(currentState: number): INextResult {\n const nextState = (currentState + 0x6d2b79f5) >>> 0;\n\n let t = nextState;\n t = Math.imul(t ^ (t >>> 15), t | 1);\n t ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n\n const value = ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n return { value, nextState };\n }\n\n /**\n * Hashes a seed value.\n * @param seed - The seed value.\n * @returns A hashed seed value.\n */\n public static hashSeed(seed: number | string): ISeedPair {\n if (typeof seed === 'number') {\n return { seed: seed.toString(), state: seed };\n }\n const parsedSeed = Number(seed);\n if (!isNaN(parsedSeed) && isFinite(parsedSeed)) {\n return { seed, state: parsedSeed };\n }\n return { seed, state: SeededRandomSource.hashString(seed) };\n }\n\n /**\n * Hashes a state and label.\n * @param state - The state value.\n * @param label - The label value.\n * @returns A hashed state and label value.\n */\n public static hashStateAndLabel(state: number, label: string): ISeedPair {\n const seed = `${state >>> 0}:${label}`;\n return { seed, state: SeededRandomSource.hashString(seed) };\n }\n\n /**\n * Hashes a string value.\n * @param value - The string value.\n * @returns A hashed string value.\n */\n private static hashString(value: string): number {\n let hash = 0x811c9dc5;\n\n for (let index = 0; index < value.length; index++) {\n hash ^= value.charCodeAt(index);\n hash = Math.imul(hash, 0x01000193);\n }\n\n return hash >>> 0;\n }\n}\n"]}
@@ -0,0 +1,95 @@
1
+ // Copyright (c) 2026 Erik Fortune
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in all
11
+ // copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ // SOFTWARE.
20
+ /**
21
+ * Lowercase letters
22
+ * @public
23
+ */
24
+ export const lowerCase = 'abcdefghijklmnopqrstuvwxyz';
25
+ /**
26
+ * Uppercase letters
27
+ * @public
28
+ */
29
+ export const upperCase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
30
+ /**
31
+ * Digits
32
+ * @public
33
+ */
34
+ export const digits = '0123456789';
35
+ /**
36
+ * Letters
37
+ * @public
38
+ */
39
+ export const letters = lowerCase + upperCase;
40
+ /**
41
+ * Alphanumeric
42
+ * @public
43
+ */
44
+ export const alphanumeric = letters + digits;
45
+ /**
46
+ * Symbols
47
+ * @public
48
+ */
49
+ export const symbols = '!@#$%^&*()_+-=[]{}|;:,.<>?';
50
+ /**
51
+ * Whitespace
52
+ * @public
53
+ */
54
+ export const whitespace = ' \t\n\r';
55
+ /**
56
+ * Printable
57
+ * @public
58
+ */
59
+ export const printable = letters + digits + symbols + whitespace;
60
+ /**
61
+ * All
62
+ * @public
63
+ */
64
+ export const all = printable;
65
+ /**
66
+ * Hex digits
67
+ * @public
68
+ */
69
+ export const hexDigits = '0123456789abcdef';
70
+ /**
71
+ * Hex digits upper
72
+ * @public
73
+ */
74
+ export const hexDigitsUpper = '0123456789ABCDEF';
75
+ /**
76
+ * Hex
77
+ * @public
78
+ */
79
+ export const hex = hexDigits + hexDigitsUpper;
80
+ /**
81
+ * Base64
82
+ * @public
83
+ */
84
+ export const base64 = letters + digits + '+/';
85
+ /**
86
+ * Base64 URL
87
+ * @public
88
+ */
89
+ export const base64Url = letters + digits + '-_';
90
+ /**
91
+ * Base64 URL no padding
92
+ * @public
93
+ */
94
+ export const base64UrlNoPadding = base64Url + '=';
95
+ //# sourceMappingURL=charClasses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"charClasses.js","sourceR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D;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAW,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC;AACzD;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAW,SAAS,GAAG,GAAG,CAAC","sourcesContent":["// Copyright (c) 2026 Erik Fortune\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\n/**\n * Lowercase letters\n * @public\n */\nexport const lowerCase: string = 'abcdefghijklmnopqrstuvwxyz';\n/**\n * Uppercase letters\n * @public\n */\nexport const upperCase: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\n/**\n * Digits\n * @public\n */\nexport const digits: string = '0123456789';\n/**\n * Letters\n * @public\n */\nexport const letters: string = lowerCase + upperCase;\n/**\n * Alphanumeric\n * @public\n */\nexport const alphanumeric: string = letters + digits;\n/**\n * Symbols\n * @public\n */\nexport const symbols: string = '!@#$%^&*()_+-=[]{}|;:,.<>?';\n/**\n * Whitespace\n * @public\n */\nexport const whitespace: string = ' \\t\\n\\r';\n/**\n * Printable\n * @public\n */\nexport const printable: string = letters + digits + symbols + whitespace;\n/**\n * All\n * @public\n */\nexport const all: string = printable;\n/**\n * Hex digits\n * @public\n */\nexport const hexDigits: string = '0123456789abcdef';\n/**\n * Hex digits upper\n * @public\n */\nexport const hexDigitsUpper: string = '0123456789ABCDEF';\n/**\n * Hex\n * @public\n */\nexport const hex: string = hexDigits + hexDigitsUpper;\n/**\n * Base64\n * @public\n */\nexport const base64: string = letters + digits + '+/';\n/**\n * Base64 URL\n * @public\n */\nexport const base64Url: string = letters + digits + '-_';\n/**\n * Base64 URL no padding\n * @public\n */\nexport const base64UrlNoPadding: string = base64Url + '=';\n"]}
@@ -0,0 +1,22 @@
1
+ // Copyright (c) 2026 Erik Fortune
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in all
11
+ // copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ // SOFTWARE.
20
+ export * as Chars from './charClasses';
21
+ export * as Words from './words';
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generator-data/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,EAAE;AACF,iFAAiF;AACjF,kDAAkD;AAClD,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY;AAEZ,OAAO,KAAK,KAAK,MAAM,eAAe,CAAC;AACvC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC","sourcesContent":["// Copyright (c) 2026 Erik Fortune\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\nexport * as Chars from './charClasses';\nexport * as Words from './words';\n"]}