@jsarc/id-generator 0.0.0 → 0.0.1-beta.0.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/id-generator.ts +538 -0
- package/index.ts +20 -7
- package/js/index.js +7 -3
- package/package.json +1 -1
- package/ts/id-generator.ts +538 -0
- package/ts/index.ts +552 -0
- package/web/id-generator.js +14 -1
- package/web/id-generator.min.js +1 -1
package/id-generator.ts
ADDED
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
|
|
3
|
+
interface Window {
|
|
4
|
+
default: typeof defaultElementGF;
|
|
5
|
+
IdentifierGenerator: any;
|
|
6
|
+
IdentifierGeneratorHandlers: any;
|
|
7
|
+
__bundledModules: any;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface RandomOptions {
|
|
11
|
+
size: number;
|
|
12
|
+
type: RandomType;
|
|
13
|
+
variant: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
interface UUIDOptions {
|
|
18
|
+
version: UUIDVersion;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
interface TokenDefinition {
|
|
23
|
+
type: 'string' | 'random' | 'uuid' | 'custom';
|
|
24
|
+
value: string | RandomOptions | UUIDOptions | CustomHandler;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
const globalFunct = (function(global: any) {
|
|
35
|
+
'use strict';
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class IdentifierGenerator {
|
|
50
|
+
private static instance: IdentifierGenerator;
|
|
51
|
+
private cache: Map<string, Map<string, string>> = new Map();
|
|
52
|
+
|
|
53
|
+
private constructor() { }
|
|
54
|
+
|
|
55
|
+
public static getInstance(): IdentifierGenerator {
|
|
56
|
+
if (!IdentifierGenerator.instance) {
|
|
57
|
+
IdentifierGenerator.instance = new IdentifierGenerator();
|
|
58
|
+
}
|
|
59
|
+
return IdentifierGenerator.instance;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public generate(format: string, customHandlers: Record<string, CustomHandler> = {}): string {
|
|
63
|
+
const tokens = this.parseFormat(format);
|
|
64
|
+
return tokens.map(token => this.resolveToken(token, customHandlers)).join('');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private parseFormat(format: string): TokenDefinition[] {
|
|
68
|
+
const tokens: TokenDefinition[] = [];
|
|
69
|
+
let currentIndex = 0;
|
|
70
|
+
|
|
71
|
+
while (currentIndex < format.length) {
|
|
72
|
+
const nextHashIndex = format.indexOf('#', currentIndex);
|
|
73
|
+
|
|
74
|
+
if (nextHashIndex > currentIndex) {
|
|
75
|
+
tokens.push({
|
|
76
|
+
type: 'string',
|
|
77
|
+
value: format.substring(currentIndex, nextHashIndex)
|
|
78
|
+
});
|
|
79
|
+
currentIndex = nextHashIndex;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (format[currentIndex] === '#') {
|
|
83
|
+
const tokenEnd = this.findTokenEnd(format, currentIndex + 1);
|
|
84
|
+
if (tokenEnd === -1) {
|
|
85
|
+
throw new Error(`Format invalide à la position ${currentIndex}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const tokenContent = format.substring(currentIndex + 1, tokenEnd);
|
|
89
|
+
const token = this.parseToken(tokenContent);
|
|
90
|
+
tokens.push(token);
|
|
91
|
+
currentIndex = tokenEnd;
|
|
92
|
+
} else if (nextHashIndex === -1) {
|
|
93
|
+
|
|
94
|
+
tokens.push({
|
|
95
|
+
type: 'string',
|
|
96
|
+
value: format.substring(currentIndex)
|
|
97
|
+
});
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return tokens;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private findTokenEnd(format: string, startIndex: number): number {
|
|
106
|
+
let braceCount = 0;
|
|
107
|
+
let inString = false;
|
|
108
|
+
let escapeNext = false;
|
|
109
|
+
|
|
110
|
+
for (let i = startIndex; i < format.length; i++) {
|
|
111
|
+
const char = format[i];
|
|
112
|
+
|
|
113
|
+
if (escapeNext) {
|
|
114
|
+
escapeNext = false;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (char === '\\') {
|
|
119
|
+
escapeNext = true;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (char === '"' || char === "'") {
|
|
124
|
+
inString = !inString;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (!inString) {
|
|
129
|
+
if (char === '{') {
|
|
130
|
+
braceCount++;
|
|
131
|
+
} else if (char === '}') {
|
|
132
|
+
if (braceCount === 0) {
|
|
133
|
+
return i;
|
|
134
|
+
}
|
|
135
|
+
braceCount--;
|
|
136
|
+
} else if (char === '#' && braceCount === 0) {
|
|
137
|
+
return i;
|
|
138
|
+
} else if (/[a-zA-Z0-9]/.test(char) === false && char !== ',' && char !== ':' && char !== '-' && char !== '_' && braceCount === 0) {
|
|
139
|
+
return i;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return format.length;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Parse un token individuel
|
|
149
|
+
*/
|
|
150
|
+
private parseToken(tokenContent: string): TokenDefinition {
|
|
151
|
+
// Token personnalisé simple
|
|
152
|
+
if (tokenContent.includes('{') === false) {
|
|
153
|
+
return { type: 'string', value: tokenContent };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const [type, optionsStr] = tokenContent.split('{', 2);
|
|
157
|
+
const optionsContent = optionsStr.slice(0, -1); // Retirer le '}'
|
|
158
|
+
|
|
159
|
+
if (type === 'rand') {
|
|
160
|
+
return {
|
|
161
|
+
type: 'random',
|
|
162
|
+
value: this.parseRandomOptions(optionsContent)
|
|
163
|
+
};
|
|
164
|
+
} else if (type === 'uuid') {
|
|
165
|
+
return {
|
|
166
|
+
type: 'uuid',
|
|
167
|
+
value: this.parseUUIDOptions(optionsContent)
|
|
168
|
+
};
|
|
169
|
+
} else if (type === 'custom') {
|
|
170
|
+
return {
|
|
171
|
+
type: 'custom',
|
|
172
|
+
value: optionsContent
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
throw new Error(`Type de token non supporté: ${type}`);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Parse les options pour un random string
|
|
181
|
+
*/
|
|
182
|
+
private parseRandomOptions(optionsStr: string): RandomOptions {
|
|
183
|
+
const defaults: RandomOptions = {
|
|
184
|
+
size: 8,
|
|
185
|
+
type: 'alphanumeric',
|
|
186
|
+
variant: false
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const options = this.parseOptions(optionsStr);
|
|
190
|
+
|
|
191
|
+
return {
|
|
192
|
+
size: options.size ? parseInt(options.size) : defaults.size,
|
|
193
|
+
type: (options.type as RandomType) || defaults.type,
|
|
194
|
+
variant: options.variant === 'true' ? true : defaults.variant
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Parse les options pour un UUID
|
|
200
|
+
*/
|
|
201
|
+
private parseUUIDOptions(optionsStr: string): UUIDOptions {
|
|
202
|
+
const defaults: UUIDOptions = {
|
|
203
|
+
version: 'v4'
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const options = this.parseOptions(optionsStr);
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
version: (options.version as UUIDVersion) || defaults.version
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Parse une chaîne d'options key:value
|
|
215
|
+
*/
|
|
216
|
+
private parseOptions(optionsStr: string): Record<string, string> {
|
|
217
|
+
const options: Record<string, string> = {};
|
|
218
|
+
let currentKey = '';
|
|
219
|
+
let currentValue = '';
|
|
220
|
+
let inString = false;
|
|
221
|
+
let stringChar = '';
|
|
222
|
+
let braceCount = 0;
|
|
223
|
+
|
|
224
|
+
for (let i = 0; i < optionsStr.length; i++) {
|
|
225
|
+
const char = optionsStr[i];
|
|
226
|
+
|
|
227
|
+
if (char === '"' || char === "'") {
|
|
228
|
+
if (!inString) {
|
|
229
|
+
inString = true;
|
|
230
|
+
stringChar = char;
|
|
231
|
+
} else if (stringChar === char) {
|
|
232
|
+
inString = false;
|
|
233
|
+
} else {
|
|
234
|
+
currentValue += char;
|
|
235
|
+
}
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (inString) {
|
|
240
|
+
currentValue += char;
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (char === ':') {
|
|
245
|
+
if (braceCount === 0) {
|
|
246
|
+
currentKey = currentValue.trim();
|
|
247
|
+
currentValue = '';
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
} else if (char === '{') {
|
|
251
|
+
braceCount++;
|
|
252
|
+
} else if (char === '}') {
|
|
253
|
+
braceCount--;
|
|
254
|
+
} else if (char === ',' && braceCount === 0) {
|
|
255
|
+
options[currentKey] = currentValue.trim();
|
|
256
|
+
currentKey = '';
|
|
257
|
+
currentValue = '';
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
currentValue += char;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (currentKey) {
|
|
265
|
+
options[currentKey] = currentValue.trim();
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return options;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
private resolveToken(token: TokenDefinition, customHandlers: Record<string, CustomHandler>): string {
|
|
272
|
+
switch (token.type) {
|
|
273
|
+
case 'string':
|
|
274
|
+
return token.value as string;
|
|
275
|
+
|
|
276
|
+
case 'random':
|
|
277
|
+
return this.generateRandomString(token.value as RandomOptions);
|
|
278
|
+
|
|
279
|
+
case 'uuid':
|
|
280
|
+
return this.generateUUID(token.value as UUIDOptions);
|
|
281
|
+
|
|
282
|
+
case 'custom':
|
|
283
|
+
const handlerName = (token.value as string).split('}').join('').split('{').join('');
|
|
284
|
+
const checker = Object.keys(customHandlers).includes(handlerName);
|
|
285
|
+
if (checker) {
|
|
286
|
+
return customHandlers[handlerName]();
|
|
287
|
+
} else {
|
|
288
|
+
console.log(`[id-generator -> id-generator] IdentifierGenerator | resolveToken - custom - token:: `, token);
|
|
289
|
+
console.log(`[id-generator -> id-generator] IdentifierGenerator | resolveToken - custom - handlerName:: `, handlerName);
|
|
290
|
+
console.log(`[id-generator -> id-generator] IdentifierGenerator | resolveToken - custom - checker:: `, checker);
|
|
291
|
+
console.log(`[id-generator -> id-generator] IdentifierGenerator | resolveToken - custom - Object.keys(customHandlers):: `, Object.keys(customHandlers));
|
|
292
|
+
console.log(`[id-generator -> id-generator] IdentifierGenerator | resolveToken - custom - customHandlers:: `, customHandlers);
|
|
293
|
+
throw new Error(`Handler personnalisé non trouvé: ${handlerName}`);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
default:
|
|
297
|
+
throw new Error(`Type de token inconnu: ${token.type}`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
private generateRandomString(options: RandomOptions): string {
|
|
302
|
+
const cacheKey = this.getRandomCacheKey(options);
|
|
303
|
+
|
|
304
|
+
if (!options.variant) {
|
|
305
|
+
if (!this.cache.has('random')) {
|
|
306
|
+
this.cache.set('random', new Map());
|
|
307
|
+
}
|
|
308
|
+
const randomCache = this.cache.get('random')!;
|
|
309
|
+
|
|
310
|
+
if (randomCache.has(cacheKey)) {
|
|
311
|
+
return randomCache.get(cacheKey)!;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
let charset = '';
|
|
316
|
+
let result = '';
|
|
317
|
+
|
|
318
|
+
switch (options.type) {
|
|
319
|
+
case 'numeric':
|
|
320
|
+
charset = '0123456789';
|
|
321
|
+
break;
|
|
322
|
+
case 'alphabetic':
|
|
323
|
+
charset = 'abcdefghijklmnopqrstuvwxyz';
|
|
324
|
+
break;
|
|
325
|
+
case 'alphabetic-case':
|
|
326
|
+
charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
327
|
+
break;
|
|
328
|
+
case 'alphanumeric':
|
|
329
|
+
charset = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
330
|
+
break;
|
|
331
|
+
case 'alphanumeric-case':
|
|
332
|
+
charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const randomValues = new Uint32Array(options.size);
|
|
337
|
+
crypto.getRandomValues(randomValues);
|
|
338
|
+
|
|
339
|
+
for (let i = 0; i < options.size; i++) {
|
|
340
|
+
result += charset[randomValues[i] % charset.length];
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (!options.variant) {
|
|
344
|
+
this.cache.get('random')!.set(cacheKey, result);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return result;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
private generateUUID(options: UUIDOptions): string {
|
|
351
|
+
const cacheKey = `uuid-${options.version}`;
|
|
352
|
+
|
|
353
|
+
if (!this.cache.has('uuid')) {
|
|
354
|
+
this.cache.set('uuid', new Map());
|
|
355
|
+
}
|
|
356
|
+
const uuidCache = this.cache.get('uuid')!;
|
|
357
|
+
|
|
358
|
+
if (uuidCache.has(cacheKey)) {
|
|
359
|
+
|
|
360
|
+
if (options.version === 'v4') {
|
|
361
|
+
return this.generateUUIDv4();
|
|
362
|
+
}
|
|
363
|
+
return uuidCache.get(cacheKey)!;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
let uuid: string;
|
|
367
|
+
|
|
368
|
+
switch (options.version) {
|
|
369
|
+
case 'v1':
|
|
370
|
+
uuid = this.generateUUIDv1();
|
|
371
|
+
break;
|
|
372
|
+
case 'v2':
|
|
373
|
+
uuid = this.generateUUIDv2();
|
|
374
|
+
break;
|
|
375
|
+
case 'v3':
|
|
376
|
+
uuid = this.generateUUIDv3();
|
|
377
|
+
break;
|
|
378
|
+
case 'v4':
|
|
379
|
+
uuid = this.generateUUIDv4();
|
|
380
|
+
break;
|
|
381
|
+
case 'v5':
|
|
382
|
+
uuid = this.generateUUIDv5();
|
|
383
|
+
break;
|
|
384
|
+
default:
|
|
385
|
+
uuid = this.generateUUIDv4();
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (options.version === 'v3' || options.version === 'v5') {
|
|
389
|
+
uuidCache.set(cacheKey, uuid);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return uuid;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
private generateUUIDv1(): string {
|
|
396
|
+
|
|
397
|
+
const now = Date.now();
|
|
398
|
+
const hexTime = now.toString(16).padStart(12, '0');
|
|
399
|
+
return `${hexTime.slice(0, 8)}-${hexTime.slice(8, 12)}-1000-8000-${this.getRandomHex(12)}`;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
private generateUUIDv2(): string {
|
|
403
|
+
|
|
404
|
+
return this.generateUUIDv1();
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
private generateUUIDv3(): string {
|
|
408
|
+
|
|
409
|
+
const namespace = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
|
|
410
|
+
const name = 'default';
|
|
411
|
+
return 'xxxxxxxx-xxxx-3xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
412
|
+
const r = Math.random() * 16 | 0;
|
|
413
|
+
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
414
|
+
return v.toString(16);
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
private generateUUIDv4(): string {
|
|
419
|
+
|
|
420
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
421
|
+
const r = crypto.getRandomValues(new Uint8Array(1))[0] % 16 | 0;
|
|
422
|
+
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
423
|
+
return v.toString(16);
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
private generateUUIDv5(): string {
|
|
428
|
+
|
|
429
|
+
const namespace = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
|
|
430
|
+
const name = 'default';
|
|
431
|
+
return 'xxxxxxxx-xxxx-5xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
432
|
+
const r = Math.random() * 16 | 0;
|
|
433
|
+
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
434
|
+
return v.toString(16);
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
private getRandomHex(size: number): string {
|
|
439
|
+
const bytes = new Uint8Array(Math.ceil(size / 2));
|
|
440
|
+
crypto.getRandomValues(bytes);
|
|
441
|
+
return Array.from(bytes)
|
|
442
|
+
.map(b => b.toString(16).padStart(2, '0'))
|
|
443
|
+
.join('')
|
|
444
|
+
.slice(0, size);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
private getRandomCacheKey(options: RandomOptions): string {
|
|
448
|
+
return `${options.size}-${options.type}-${options.variant}`;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
public clearCache(): void {
|
|
452
|
+
this.cache.clear();
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
public static generateId(format: string, customHandlers: Record<string, CustomHandler> = {}): string {
|
|
456
|
+
return this.getInstance().generate(format, customHandlers);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
static exposeToGlobal(): void {
|
|
460
|
+
if (typeof window !== 'undefined') {
|
|
461
|
+
(window as any).IdentifierGenerator = IdentifierGenerator;
|
|
462
|
+
(window as any).IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const IdentifierGeneratorHandlers = {
|
|
468
|
+
timestamp: () => Date.now().toString(),
|
|
469
|
+
date: () => new Date().toISOString().slice(0, 10).replace(/-/g, ''),
|
|
470
|
+
time: () => new Date().toISOString().slice(11, 19).replace(/:/g, ''),
|
|
471
|
+
counter: (() => {
|
|
472
|
+
let count = 0;
|
|
473
|
+
return () => (++count).toString().padStart(6, '0');
|
|
474
|
+
})(),
|
|
475
|
+
env: (envVar: string) => process.env[envVar] || ''
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
if (typeof window !== 'undefined') {
|
|
479
|
+
(window as any).IdentifierGenerator = IdentifierGenerator;
|
|
480
|
+
(window as any).IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
const idGen = {
|
|
484
|
+
IdentifierGenerator,
|
|
485
|
+
IdentifierGeneratorHandlers,
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
const globalFunctModule = {
|
|
490
|
+
default: idGen,
|
|
491
|
+
IdentifierGenerator: IdentifierGenerator,
|
|
492
|
+
IdentifierGeneratorHandlers: IdentifierGeneratorHandlers,
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
const __bundledModules = globalFunctModule;
|
|
497
|
+
|
|
498
|
+
if (typeof global !== 'undefined') {
|
|
499
|
+
(global as any).default = idGen;
|
|
500
|
+
(global as any).IdentifierGenerator = IdentifierGenerator;
|
|
501
|
+
(global as any).IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
502
|
+
(global as any).__bundledModules = __bundledModules;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
if (typeof window !== "undefined") {
|
|
506
|
+
(window as any).default = idGen;
|
|
507
|
+
(window as any).IdentifierGenerator = IdentifierGenerator;
|
|
508
|
+
(window as any).IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
509
|
+
(window as any).__bundledModules = __bundledModules;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
if (typeof exports !== 'undefined') {
|
|
513
|
+
exports.default = idGen;
|
|
514
|
+
exports.IdentifierGenerator = IdentifierGenerator;
|
|
515
|
+
exports.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
516
|
+
}
|
|
517
|
+
return globalFunctModule;
|
|
518
|
+
|
|
519
|
+
})(typeof global !== 'undefined' ? global :
|
|
520
|
+
typeof window !== 'undefined' ? window :
|
|
521
|
+
typeof self !== 'undefined' ? self :
|
|
522
|
+
typeof globalThis !== 'undefined' ? globalThis :
|
|
523
|
+
{});
|
|
524
|
+
|
|
525
|
+
type IdentifierGeneratorElementTypeGF = typeof globalFunct.IdentifierGenerator;
|
|
526
|
+
|
|
527
|
+
type IdentifierGeneratorHandlersElementTypeGF = typeof globalFunct.IdentifierGeneratorHandlers;
|
|
528
|
+
|
|
529
|
+
type DefaultElementTypeGF = typeof globalFunct.default;
|
|
530
|
+
|
|
531
|
+
const IdentifierGeneratorElementGF: IdentifierGeneratorElementTypeGF = globalFunct.IdentifierGenerator;
|
|
532
|
+
|
|
533
|
+
const IdentifierGeneratorHandlersElementGF: IdentifierGeneratorHandlersElementTypeGF = globalFunct.IdentifierGeneratorHandlers;
|
|
534
|
+
|
|
535
|
+
const defaultElementGF: DefaultElementTypeGF = globalFunct.default;
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
|
package/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
|
|
3
3
|
interface Window {
|
|
4
|
+
default: typeof defaultElementGF;
|
|
4
5
|
IdentifierGenerator: any;
|
|
5
6
|
IdentifierGeneratorHandlers: any;
|
|
6
7
|
__bundledModules: any;
|
|
@@ -463,8 +464,8 @@ const globalFunct = (function(global: any) {
|
|
|
463
464
|
|
|
464
465
|
static exposeToGlobal(): void {
|
|
465
466
|
if (typeof window !== 'undefined') {
|
|
466
|
-
window.IdentifierGenerator = IdentifierGenerator;
|
|
467
|
-
window.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
467
|
+
(window as any).IdentifierGenerator = IdentifierGenerator;
|
|
468
|
+
(window as any).IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
468
469
|
}
|
|
469
470
|
}
|
|
470
471
|
}
|
|
@@ -481,17 +482,18 @@ const globalFunct = (function(global: any) {
|
|
|
481
482
|
};
|
|
482
483
|
|
|
483
484
|
if (typeof window !== 'undefined') {
|
|
484
|
-
window.IdentifierGenerator = IdentifierGenerator;
|
|
485
|
-
window.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
485
|
+
(window as any).IdentifierGenerator = IdentifierGenerator;
|
|
486
|
+
(window as any).IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
486
487
|
}
|
|
487
488
|
|
|
488
|
-
|
|
489
|
+
const idGen = {
|
|
489
490
|
IdentifierGenerator,
|
|
490
491
|
IdentifierGeneratorHandlers,
|
|
491
|
-
}
|
|
492
|
+
};
|
|
493
|
+
|
|
492
494
|
|
|
493
495
|
const globalFunctModule = {
|
|
494
|
-
default:
|
|
496
|
+
default: idGen,
|
|
495
497
|
IdentifierGenerator: IdentifierGenerator,
|
|
496
498
|
IdentifierGeneratorHandlers: IdentifierGeneratorHandlers,
|
|
497
499
|
};
|
|
@@ -500,18 +502,21 @@ const globalFunct = (function(global: any) {
|
|
|
500
502
|
const __bundledModules = globalFunctModule;
|
|
501
503
|
|
|
502
504
|
if (typeof global !== 'undefined') {
|
|
505
|
+
(global as any).default = idGen;
|
|
503
506
|
(global as any).IdentifierGenerator = IdentifierGenerator;
|
|
504
507
|
(global as any).IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
505
508
|
(global as any).__bundledModules = __bundledModules;
|
|
506
509
|
}
|
|
507
510
|
|
|
508
511
|
if (typeof window !== "undefined") {
|
|
512
|
+
(window as any).default = idGen;
|
|
509
513
|
(window as any).IdentifierGenerator = IdentifierGenerator;
|
|
510
514
|
(window as any).IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
511
515
|
(window as any).__bundledModules = __bundledModules;
|
|
512
516
|
}
|
|
513
517
|
|
|
514
518
|
if (typeof exports !== 'undefined') {
|
|
519
|
+
exports.default = idGen;
|
|
515
520
|
exports.IdentifierGenerator = IdentifierGenerator;
|
|
516
521
|
exports.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
517
522
|
}
|
|
@@ -527,13 +532,21 @@ type IdentifierGeneratorElementTypeGF = typeof globalFunct.IdentifierGenerator;
|
|
|
527
532
|
|
|
528
533
|
type IdentifierGeneratorHandlersElementTypeGF = typeof globalFunct.IdentifierGeneratorHandlers;
|
|
529
534
|
|
|
535
|
+
type DefaultElementTypeGF = typeof globalFunct.default;
|
|
536
|
+
|
|
530
537
|
const IdentifierGeneratorElementGF: IdentifierGeneratorElementTypeGF = globalFunct.IdentifierGenerator;
|
|
531
538
|
|
|
532
539
|
const IdentifierGeneratorHandlersElementGF: IdentifierGeneratorHandlersElementTypeGF = globalFunct.IdentifierGeneratorHandlers;
|
|
533
540
|
|
|
541
|
+
const defaultElementGF: DefaultElementTypeGF = globalFunct.default;
|
|
542
|
+
|
|
534
543
|
export {
|
|
544
|
+
defaultElementGF as default,
|
|
535
545
|
IdentifierGeneratorElementGF as IdentifierGenerator,
|
|
536
546
|
IdentifierGeneratorHandlersElementGF as IdentifierGeneratorHandlers,
|
|
537
547
|
};
|
|
538
548
|
export type {
|
|
549
|
+
DefaultElementTypeGF,
|
|
550
|
+
RandomType,UUIDVersion,CustomHandler,RandomOptions,UUIDOptions,TokenDefinition,
|
|
551
|
+
IdentifierGeneratorElementTypeGF,IdentifierGeneratorHandlersElementTypeGF,
|
|
539
552
|
};
|
package/js/index.js
CHANGED
|
@@ -371,27 +371,30 @@ const globalFunct = (function (global) {
|
|
|
371
371
|
window.IdentifierGenerator = IdentifierGenerator;
|
|
372
372
|
window.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
373
373
|
}
|
|
374
|
-
|
|
374
|
+
const idGen = {
|
|
375
375
|
IdentifierGenerator,
|
|
376
376
|
IdentifierGeneratorHandlers,
|
|
377
377
|
};
|
|
378
378
|
const globalFunctModule = {
|
|
379
|
-
default:
|
|
379
|
+
default: idGen,
|
|
380
380
|
IdentifierGenerator: IdentifierGenerator,
|
|
381
381
|
IdentifierGeneratorHandlers: IdentifierGeneratorHandlers,
|
|
382
382
|
};
|
|
383
383
|
const __bundledModules = globalFunctModule;
|
|
384
384
|
if (typeof global !== 'undefined') {
|
|
385
|
+
global.default = idGen;
|
|
385
386
|
global.IdentifierGenerator = IdentifierGenerator;
|
|
386
387
|
global.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
387
388
|
global.__bundledModules = __bundledModules;
|
|
388
389
|
}
|
|
389
390
|
if (typeof window !== "undefined") {
|
|
391
|
+
window.default = idGen;
|
|
390
392
|
window.IdentifierGenerator = IdentifierGenerator;
|
|
391
393
|
window.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
392
394
|
window.__bundledModules = __bundledModules;
|
|
393
395
|
}
|
|
394
396
|
if (typeof exports !== 'undefined') {
|
|
397
|
+
exports.default = idGen;
|
|
395
398
|
exports.IdentifierGenerator = IdentifierGenerator;
|
|
396
399
|
exports.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
397
400
|
}
|
|
@@ -403,4 +406,5 @@ const globalFunct = (function (global) {
|
|
|
403
406
|
{});
|
|
404
407
|
const IdentifierGeneratorElementGF = globalFunct.IdentifierGenerator;
|
|
405
408
|
const IdentifierGeneratorHandlersElementGF = globalFunct.IdentifierGeneratorHandlers;
|
|
406
|
-
|
|
409
|
+
const defaultElementGF = globalFunct.default;
|
|
410
|
+
export { defaultElementGF as default, IdentifierGeneratorElementGF as IdentifierGenerator, IdentifierGeneratorHandlersElementGF as IdentifierGeneratorHandlers, };
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.0.0",
|
|
6
|
+
"version": "0.0.1-beta.0.1",
|
|
7
7
|
"description": "ID-GENERATOR est une bibliothèque TypeScript robuste pour générer des identifiants uniques avec des formats personnalisables. Elle offre une syntaxe expressive pour créer des identifiants complexes combinant texte, chaînes aléatoires, UUID et fonctions personnalisées.",
|
|
8
8
|
"main": "index.ts",
|
|
9
9
|
"keywords": [],
|