@arc-js/id-generator 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +547 -0
- package/index.ts +560 -0
- package/js/index.js +422 -0
- package/package.json +18 -0
- package/tsconfig.json +27 -0
- package/web/id-generator.js +412 -0
- package/web/id-generator.min.js +1 -0
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
const globalFunct = (function (global) {
|
|
2
|
+
'use strict';
|
|
3
|
+
class IdentifierGenerator {
|
|
4
|
+
static instance;
|
|
5
|
+
cache = new Map();
|
|
6
|
+
constructor() { }
|
|
7
|
+
static getInstance() {
|
|
8
|
+
if (!IdentifierGenerator.instance) {
|
|
9
|
+
IdentifierGenerator.instance = new IdentifierGenerator();
|
|
10
|
+
}
|
|
11
|
+
return IdentifierGenerator.instance;
|
|
12
|
+
}
|
|
13
|
+
generate(format, customHandlers = {}) {
|
|
14
|
+
const tokens = this.parseFormat(format);
|
|
15
|
+
return tokens.map(token => this.resolveToken(token, customHandlers)).join('');
|
|
16
|
+
}
|
|
17
|
+
parseFormat(format) {
|
|
18
|
+
const tokens = [];
|
|
19
|
+
let currentIndex = 0;
|
|
20
|
+
while (currentIndex < format.length) {
|
|
21
|
+
const nextHashIndex = format.indexOf('#', currentIndex);
|
|
22
|
+
if (nextHashIndex > currentIndex) {
|
|
23
|
+
tokens.push({
|
|
24
|
+
type: 'string',
|
|
25
|
+
value: format.substring(currentIndex, nextHashIndex)
|
|
26
|
+
});
|
|
27
|
+
currentIndex = nextHashIndex;
|
|
28
|
+
}
|
|
29
|
+
if (format[currentIndex] === '#') {
|
|
30
|
+
const tokenEnd = this.findTokenEnd(format, currentIndex + 1);
|
|
31
|
+
if (tokenEnd === -1) {
|
|
32
|
+
throw new Error(`Format invalide à la position ${currentIndex}`);
|
|
33
|
+
}
|
|
34
|
+
const tokenContent = format.substring(currentIndex + 1, tokenEnd);
|
|
35
|
+
const token = this.parseToken(tokenContent);
|
|
36
|
+
tokens.push(token);
|
|
37
|
+
currentIndex = tokenEnd;
|
|
38
|
+
}
|
|
39
|
+
else if (nextHashIndex === -1) {
|
|
40
|
+
tokens.push({
|
|
41
|
+
type: 'string',
|
|
42
|
+
value: format.substring(currentIndex)
|
|
43
|
+
});
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return tokens;
|
|
48
|
+
}
|
|
49
|
+
findTokenEnd(format, startIndex) {
|
|
50
|
+
let braceCount = 0;
|
|
51
|
+
let inString = false;
|
|
52
|
+
let escapeNext = false;
|
|
53
|
+
for (let i = startIndex; i < format.length; i++) {
|
|
54
|
+
const char = format[i];
|
|
55
|
+
if (escapeNext) {
|
|
56
|
+
escapeNext = false;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (char === '\\') {
|
|
60
|
+
escapeNext = true;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (char === '"' || char === "'") {
|
|
64
|
+
inString = !inString;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (!inString) {
|
|
68
|
+
if (char === '{') {
|
|
69
|
+
braceCount++;
|
|
70
|
+
}
|
|
71
|
+
else if (char === '}') {
|
|
72
|
+
if (braceCount === 0) {
|
|
73
|
+
return i;
|
|
74
|
+
}
|
|
75
|
+
braceCount--;
|
|
76
|
+
}
|
|
77
|
+
else if (char === '#' && braceCount === 0) {
|
|
78
|
+
return i;
|
|
79
|
+
}
|
|
80
|
+
else if (/[a-zA-Z0-9]/.test(char) === false && char !== ',' && char !== ':' && char !== '-' && char !== '_' && braceCount === 0) {
|
|
81
|
+
return i;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return format.length;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Parse un token individuel
|
|
89
|
+
*/
|
|
90
|
+
parseToken(tokenContent) {
|
|
91
|
+
// Token personnalisé simple
|
|
92
|
+
if (tokenContent.includes('{') === false) {
|
|
93
|
+
return { type: 'string', value: tokenContent };
|
|
94
|
+
}
|
|
95
|
+
const [type, optionsStr] = tokenContent.split('{', 2);
|
|
96
|
+
const optionsContent = optionsStr.slice(0, -1); // Retirer le '}'
|
|
97
|
+
if (type === 'rand') {
|
|
98
|
+
return {
|
|
99
|
+
type: 'random',
|
|
100
|
+
value: this.parseRandomOptions(optionsContent)
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
else if (type === 'uuid') {
|
|
104
|
+
return {
|
|
105
|
+
type: 'uuid',
|
|
106
|
+
value: this.parseUUIDOptions(optionsContent)
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
else if (type === 'custom') {
|
|
110
|
+
return {
|
|
111
|
+
type: 'custom',
|
|
112
|
+
value: optionsContent
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
throw new Error(`Type de token non supporté: ${type}`);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Parse les options pour un random string
|
|
119
|
+
*/
|
|
120
|
+
parseRandomOptions(optionsStr) {
|
|
121
|
+
const defaults = {
|
|
122
|
+
size: 8,
|
|
123
|
+
type: 'alphanumeric',
|
|
124
|
+
variant: false
|
|
125
|
+
};
|
|
126
|
+
const options = this.parseOptions(optionsStr);
|
|
127
|
+
return {
|
|
128
|
+
size: options.size ? parseInt(options.size) : defaults.size,
|
|
129
|
+
type: options.type || defaults.type,
|
|
130
|
+
variant: options.variant === 'true' ? true : defaults.variant
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Parse les options pour un UUID
|
|
135
|
+
*/
|
|
136
|
+
parseUUIDOptions(optionsStr) {
|
|
137
|
+
const defaults = {
|
|
138
|
+
version: 'v4'
|
|
139
|
+
};
|
|
140
|
+
const options = this.parseOptions(optionsStr);
|
|
141
|
+
return {
|
|
142
|
+
version: options.version || defaults.version
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Parse une chaîne d'options key:value
|
|
147
|
+
*/
|
|
148
|
+
parseOptions(optionsStr) {
|
|
149
|
+
const options = {};
|
|
150
|
+
let currentKey = '';
|
|
151
|
+
let currentValue = '';
|
|
152
|
+
let inString = false;
|
|
153
|
+
let stringChar = '';
|
|
154
|
+
let braceCount = 0;
|
|
155
|
+
for (let i = 0; i < optionsStr.length; i++) {
|
|
156
|
+
const char = optionsStr[i];
|
|
157
|
+
if (char === '"' || char === "'") {
|
|
158
|
+
if (!inString) {
|
|
159
|
+
inString = true;
|
|
160
|
+
stringChar = char;
|
|
161
|
+
}
|
|
162
|
+
else if (stringChar === char) {
|
|
163
|
+
inString = false;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
currentValue += char;
|
|
167
|
+
}
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (inString) {
|
|
171
|
+
currentValue += char;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (char === ':') {
|
|
175
|
+
if (braceCount === 0) {
|
|
176
|
+
currentKey = currentValue.trim();
|
|
177
|
+
currentValue = '';
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else if (char === '{') {
|
|
182
|
+
braceCount++;
|
|
183
|
+
}
|
|
184
|
+
else if (char === '}') {
|
|
185
|
+
braceCount--;
|
|
186
|
+
}
|
|
187
|
+
else if (char === ',' && braceCount === 0) {
|
|
188
|
+
options[currentKey] = currentValue.trim();
|
|
189
|
+
currentKey = '';
|
|
190
|
+
currentValue = '';
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
currentValue += char;
|
|
194
|
+
}
|
|
195
|
+
if (currentKey) {
|
|
196
|
+
options[currentKey] = currentValue.trim();
|
|
197
|
+
}
|
|
198
|
+
return options;
|
|
199
|
+
}
|
|
200
|
+
resolveToken(token, customHandlers) {
|
|
201
|
+
switch (token.type) {
|
|
202
|
+
case 'string':
|
|
203
|
+
return token.value;
|
|
204
|
+
case 'random':
|
|
205
|
+
return this.generateRandomString(token.value);
|
|
206
|
+
case 'uuid':
|
|
207
|
+
return this.generateUUID(token.value);
|
|
208
|
+
case 'custom':
|
|
209
|
+
const handlerName = token.value.split('}').join('').split('{').join('');
|
|
210
|
+
const checker = Object.keys(customHandlers).includes(handlerName);
|
|
211
|
+
if (checker) {
|
|
212
|
+
return customHandlers[handlerName]();
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
console.log(`[id-generator -> id-generator] IdentifierGenerator | resolveToken - custom - token:: `, token);
|
|
216
|
+
console.log(`[id-generator -> id-generator] IdentifierGenerator | resolveToken - custom - handlerName:: `, handlerName);
|
|
217
|
+
console.log(`[id-generator -> id-generator] IdentifierGenerator | resolveToken - custom - checker:: `, checker);
|
|
218
|
+
console.log(`[id-generator -> id-generator] IdentifierGenerator | resolveToken - custom - Object.keys(customHandlers):: `, Object.keys(customHandlers));
|
|
219
|
+
console.log(`[id-generator -> id-generator] IdentifierGenerator | resolveToken - custom - customHandlers:: `, customHandlers);
|
|
220
|
+
throw new Error(`Handler personnalisé non trouvé: ${handlerName}`);
|
|
221
|
+
}
|
|
222
|
+
default:
|
|
223
|
+
throw new Error(`Type de token inconnu: ${token.type}`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
generateRandomString(options) {
|
|
227
|
+
const cacheKey = this.getRandomCacheKey(options);
|
|
228
|
+
if (!options.variant) {
|
|
229
|
+
if (!this.cache.has('random')) {
|
|
230
|
+
this.cache.set('random', new Map());
|
|
231
|
+
}
|
|
232
|
+
const randomCache = this.cache.get('random');
|
|
233
|
+
if (randomCache.has(cacheKey)) {
|
|
234
|
+
return randomCache.get(cacheKey);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
let charset = '';
|
|
238
|
+
let result = '';
|
|
239
|
+
switch (options.type) {
|
|
240
|
+
case 'numeric':
|
|
241
|
+
charset = '0123456789';
|
|
242
|
+
break;
|
|
243
|
+
case 'alphabetic':
|
|
244
|
+
charset = 'abcdefghijklmnopqrstuvwxyz';
|
|
245
|
+
break;
|
|
246
|
+
case 'alphabetic-case':
|
|
247
|
+
charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
248
|
+
break;
|
|
249
|
+
case 'alphanumeric':
|
|
250
|
+
charset = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
251
|
+
break;
|
|
252
|
+
case 'alphanumeric-case':
|
|
253
|
+
charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
const randomValues = new Uint32Array(options.size);
|
|
257
|
+
crypto.getRandomValues(randomValues);
|
|
258
|
+
for (let i = 0; i < options.size; i++) {
|
|
259
|
+
result += charset[randomValues[i] % charset.length];
|
|
260
|
+
}
|
|
261
|
+
if (!options.variant) {
|
|
262
|
+
this.cache.get('random').set(cacheKey, result);
|
|
263
|
+
}
|
|
264
|
+
return result;
|
|
265
|
+
}
|
|
266
|
+
generateUUID(options) {
|
|
267
|
+
const cacheKey = `uuid-${options.version}`;
|
|
268
|
+
if (!this.cache.has('uuid')) {
|
|
269
|
+
this.cache.set('uuid', new Map());
|
|
270
|
+
}
|
|
271
|
+
const uuidCache = this.cache.get('uuid');
|
|
272
|
+
if (uuidCache.has(cacheKey)) {
|
|
273
|
+
if (options.version === 'v4') {
|
|
274
|
+
return this.generateUUIDv4();
|
|
275
|
+
}
|
|
276
|
+
return uuidCache.get(cacheKey);
|
|
277
|
+
}
|
|
278
|
+
let uuid;
|
|
279
|
+
switch (options.version) {
|
|
280
|
+
case 'v1':
|
|
281
|
+
uuid = this.generateUUIDv1();
|
|
282
|
+
break;
|
|
283
|
+
case 'v2':
|
|
284
|
+
uuid = this.generateUUIDv2();
|
|
285
|
+
break;
|
|
286
|
+
case 'v3':
|
|
287
|
+
uuid = this.generateUUIDv3();
|
|
288
|
+
break;
|
|
289
|
+
case 'v4':
|
|
290
|
+
uuid = this.generateUUIDv4();
|
|
291
|
+
break;
|
|
292
|
+
case 'v5':
|
|
293
|
+
uuid = this.generateUUIDv5();
|
|
294
|
+
break;
|
|
295
|
+
default:
|
|
296
|
+
uuid = this.generateUUIDv4();
|
|
297
|
+
}
|
|
298
|
+
if (options.version === 'v3' || options.version === 'v5') {
|
|
299
|
+
uuidCache.set(cacheKey, uuid);
|
|
300
|
+
}
|
|
301
|
+
return uuid;
|
|
302
|
+
}
|
|
303
|
+
generateUUIDv1() {
|
|
304
|
+
const now = Date.now();
|
|
305
|
+
const hexTime = now.toString(16).padStart(12, '0');
|
|
306
|
+
return `${hexTime.slice(0, 8)}-${hexTime.slice(8, 12)}-1000-8000-${this.getRandomHex(12)}`;
|
|
307
|
+
}
|
|
308
|
+
generateUUIDv2() {
|
|
309
|
+
return this.generateUUIDv1();
|
|
310
|
+
}
|
|
311
|
+
generateUUIDv3() {
|
|
312
|
+
const namespace = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
|
|
313
|
+
const name = 'default';
|
|
314
|
+
return 'xxxxxxxx-xxxx-3xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
315
|
+
const r = Math.random() * 16 | 0;
|
|
316
|
+
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
317
|
+
return v.toString(16);
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
generateUUIDv4() {
|
|
321
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
322
|
+
const r = crypto.getRandomValues(new Uint8Array(1))[0] % 16 | 0;
|
|
323
|
+
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
324
|
+
return v.toString(16);
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
generateUUIDv5() {
|
|
328
|
+
const namespace = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
|
|
329
|
+
const name = 'default';
|
|
330
|
+
return 'xxxxxxxx-xxxx-5xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
331
|
+
const r = Math.random() * 16 | 0;
|
|
332
|
+
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
333
|
+
return v.toString(16);
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
getRandomHex(size) {
|
|
337
|
+
const bytes = new Uint8Array(Math.ceil(size / 2));
|
|
338
|
+
crypto.getRandomValues(bytes);
|
|
339
|
+
return Array.from(bytes)
|
|
340
|
+
.map(b => b.toString(16).padStart(2, '0'))
|
|
341
|
+
.join('')
|
|
342
|
+
.slice(0, size);
|
|
343
|
+
}
|
|
344
|
+
getRandomCacheKey(options) {
|
|
345
|
+
return `${options.size}-${options.type}-${options.variant}`;
|
|
346
|
+
}
|
|
347
|
+
clearCache() {
|
|
348
|
+
this.cache.clear();
|
|
349
|
+
}
|
|
350
|
+
static generateId(format, customHandlers = {}) {
|
|
351
|
+
return this.getInstance().generate(format, customHandlers);
|
|
352
|
+
}
|
|
353
|
+
static exposeToGlobal() {
|
|
354
|
+
if (typeof window !== 'undefined') {
|
|
355
|
+
window.IdentifierGenerator = IdentifierGenerator;
|
|
356
|
+
window.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
const IdentifierGeneratorHandlers = {
|
|
361
|
+
timestamp: () => Date.now().toString(),
|
|
362
|
+
date: () => new Date().toISOString().slice(0, 10).replace(/-/g, ''),
|
|
363
|
+
time: () => new Date().toISOString().slice(11, 19).replace(/:/g, ''),
|
|
364
|
+
counter: (() => {
|
|
365
|
+
let count = 0;
|
|
366
|
+
return () => (++count).toString().padStart(6, '0');
|
|
367
|
+
})(),
|
|
368
|
+
env: (envVar) => process.env[envVar] || ''
|
|
369
|
+
};
|
|
370
|
+
if (typeof window !== 'undefined') {
|
|
371
|
+
window.IdentifierGenerator = IdentifierGenerator;
|
|
372
|
+
window.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
373
|
+
}
|
|
374
|
+
globalFunctModule.default = { ...(globalFunctModule?.default || {}), IdentifierGenerator: IdentifierGenerator };
|
|
375
|
+
globalFunctModule.default = { ...(globalFunctModule?.default || {}), IdentifierGeneratorHandlers: IdentifierGeneratorHandlers };
|
|
376
|
+
const __bundledModules = globalFunctModule;
|
|
377
|
+
if (typeof global !== 'undefined') {
|
|
378
|
+
global.IdentifierGenerator = IdentifierGenerator;
|
|
379
|
+
global.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
380
|
+
global.__bundledModules = __bundledModules;
|
|
381
|
+
}
|
|
382
|
+
if (typeof window !== "undefined") {
|
|
383
|
+
window.IdentifierGenerator = IdentifierGenerator;
|
|
384
|
+
window.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
385
|
+
window.__bundledModules = __bundledModules;
|
|
386
|
+
}
|
|
387
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
388
|
+
module.exports = __bundledModules;
|
|
389
|
+
module.exports.IdentifierGenerator = IdentifierGenerator;
|
|
390
|
+
module.exports.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
391
|
+
}
|
|
392
|
+
if (typeof exports !== 'undefined') {
|
|
393
|
+
exports.IdentifierGenerator = IdentifierGenerator;
|
|
394
|
+
exports.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
395
|
+
}
|
|
396
|
+
return __bundledModules;
|
|
397
|
+
})(typeof global !== 'undefined' ? global :
|
|
398
|
+
typeof window !== 'undefined' ? window :
|
|
399
|
+
typeof self !== 'undefined' ? self :
|
|
400
|
+
typeof globalThis !== 'undefined' ? globalThis :
|
|
401
|
+
{});
|
|
402
|
+
const IdentifierGeneratorElementGF = globalFunct.IdentifierGenerator;
|
|
403
|
+
const IdentifierGeneratorHandlersElementGF = globalFunct.IdentifierGeneratorHandlers;
|
|
404
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
405
|
+
module.exports = {
|
|
406
|
+
IdentifierGenerator: IdentifierGeneratorElementGF,
|
|
407
|
+
IdentifierGeneratorHandlers: IdentifierGeneratorHandlersElementGF,
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
411
|
+
module.exports.default = globalFunct?.default;
|
|
412
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let globalFunct=(e=>{class r{static instance;cache=new Map;constructor(){}static getInstance(){return r.instance||(r.instance=new r),r.instance}generate(e,r={}){return this.parseFormat(e).map(e=>this.resolveToken(e,r)).join("")}parseFormat(e){var r=[];let t=0;for(;t<e.length;){var n=e.indexOf("#",t);if(n>t&&(r.push({type:"string",value:e.substring(t,n)}),t=n),"#"===e[t]){var a=this.findTokenEnd(e,t+1);if(-1===a)throw new Error("Format invalide à la position "+t);var i=e.substring(t+1,a),i=this.parseToken(i);r.push(i),t=a}else if(-1===n){r.push({type:"string",value:e.substring(t)});break}}return r}findTokenEnd(r,t){let n=0,a=!1,i=!1;for(let e=t;e<r.length;e++){var o=r[e];if(i)i=!1;else if("\\"===o)i=!0;else if('"'===o||"'"===o)a=!a;else if(!a)if("{"===o)n++;else if("}"===o){if(0===n)return e;n--}else{if("#"===o&&0===n)return e;if(!1===/[a-zA-Z0-9]/.test(o)&&","!==o&&":"!==o&&"-"!==o&&"_"!==o&&0===n)return e}}return r.length}parseToken(e){if(!1===e.includes("{"))return{type:"string",value:e};var[e,r]=e.split("{",2),r=r.slice(0,-1);if("rand"===e)return{type:"random",value:this.parseRandomOptions(r)};if("uuid"===e)return{type:"uuid",value:this.parseUUIDOptions(r)};if("custom"===e)return{type:"custom",value:r};throw new Error("Type de token non supporté: "+e)}parseRandomOptions(e){const r=8,t="alphanumeric",n=!1;e=this.parseOptions(e);return{size:e.size?parseInt(e.size):r,type:e.type||t,variant:"true"===e.variant||n}}parseUUIDOptions(e){return{version:this.parseOptions(e).version||"v4"}}parseOptions(r){var t={};let n="",a="",i=!1,o="",s=0;for(let e=0;e<r.length;e++){var l=r[e];if('"'===l||"'"===l)i?o===l?i=!1:a+=l:(i=!0,o=l);else{if(!i)if(":"===l){if(0===s){n=a.trim(),a="";continue}}else if("{"===l)s++;else if("}"===l)s--;else if(","===l&&0===s){t[n]=a.trim(),n="",a="";continue}a+=l}}return n&&(t[n]=a.trim()),t}resolveToken(e,r){switch(e.type){case"string":return e.value;case"random":return this.generateRandomString(e.value);case"uuid":return this.generateUUID(e.value);case"custom":var t=e.value.split("}").join("").split("{").join(""),n=Object.keys(r).includes(t);if(n)return r[t]();throw console.log("[id-generator -> id-generator] IdentifierGenerator | resolveToken - custom - token:: ",e),console.log("[id-generator -> id-generator] IdentifierGenerator | resolveToken - custom - handlerName:: ",t),console.log("[id-generator -> id-generator] IdentifierGenerator | resolveToken - custom - checker:: ",n),console.log("[id-generator -> id-generator] IdentifierGenerator | resolveToken - custom - Object.keys(customHandlers):: ",Object.keys(r)),console.log("[id-generator -> id-generator] IdentifierGenerator | resolveToken - custom - customHandlers:: ",r),new Error("Handler personnalisé non trouvé: "+t);default:throw new Error("Type de token inconnu: "+e.type)}}generateRandomString(r){var e=this.getRandomCacheKey(r);if(!r.variant){this.cache.has("random")||this.cache.set("random",new Map);var t=this.cache.get("random");if(t.has(e))return t.get(e)}let n="",a="";switch(r.type){case"numeric":n="0123456789";break;case"alphabetic":n="abcdefghijklmnopqrstuvwxyz";break;case"alphabetic-case":n="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";break;case"alphanumeric":n="abcdefghijklmnopqrstuvwxyz0123456789";break;case"alphanumeric-case":n="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"}var i=new Uint32Array(r.size);crypto.getRandomValues(i);for(let e=0;e<r.size;e++)a+=n[i[e]%n.length];return r.variant||this.cache.get("random").set(e,a),a}generateUUID(e){var r="uuid-"+e.version,t=(this.cache.has("uuid")||this.cache.set("uuid",new Map),this.cache.get("uuid"));if(t.has(r))return"v4"===e.version?this.generateUUIDv4():t.get(r);let n;switch(e.version){case"v1":n=this.generateUUIDv1();break;case"v2":n=this.generateUUIDv2();break;case"v3":n=this.generateUUIDv3();break;case"v4":n=this.generateUUIDv4();break;case"v5":n=this.generateUUIDv5();break;default:n=this.generateUUIDv4()}return"v3"!==e.version&&"v5"!==e.version||t.set(r,n),n}generateUUIDv1(){var e=Date.now().toString(16).padStart(12,"0");return`${e.slice(0,8)}-${e.slice(8,12)}-1000-8000-`+this.getRandomHex(12)}generateUUIDv2(){return this.generateUUIDv1()}generateUUIDv3(){return"xxxxxxxx-xxxx-3xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{var r=16*Math.random()|0;return("x"===e?r:3&r|8).toString(16)})}generateUUIDv4(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{var r=crypto.getRandomValues(new Uint8Array(1))[0]%16|0;return("x"===e?r:3&r|8).toString(16)})}generateUUIDv5(){return"xxxxxxxx-xxxx-5xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{var r=16*Math.random()|0;return("x"===e?r:3&r|8).toString(16)})}getRandomHex(e){var r=new Uint8Array(Math.ceil(e/2));return crypto.getRandomValues(r),Array.from(r).map(e=>e.toString(16).padStart(2,"0")).join("").slice(0,e)}getRandomCacheKey(e){return e.size+`-${e.type}-`+e.variant}clearCache(){this.cache.clear()}static generateId(e,r={}){return this.getInstance().generate(e,r)}static exposeToGlobal(){"undefined"!=typeof window&&(window.IdentifierGenerator=r,window.IdentifierGeneratorHandlers=t)}}let t={timestamp:()=>Date.now().toString(),date:()=>(new Date).toISOString().slice(0,10).replace(/-/g,""),time:()=>(new Date).toISOString().slice(11,19).replace(/:/g,""),counter:(()=>{let e=0;return()=>(++e).toString().padStart(6,"0")})(),env:e=>process.env[e]||""};"undefined"!=typeof window&&(window.IdentifierGenerator=r,window.IdentifierGeneratorHandlers=t),globalFunctModule.default={...globalFunctModule?.default||{},IdentifierGenerator:r},globalFunctModule.default={...globalFunctModule?.default||{},IdentifierGeneratorHandlers:t};var n=globalFunctModule;return void 0!==e&&(e.IdentifierGenerator=r,e.IdentifierGeneratorHandlers=t,e.__bundledModules=n),"undefined"!=typeof window&&(window.IdentifierGenerator=r,window.IdentifierGeneratorHandlers=t,window.__bundledModules=n),"undefined"!=typeof module&&module.exports&&(module.exports=n,module.exports.IdentifierGenerator=r,module.exports.IdentifierGeneratorHandlers=t),"undefined"!=typeof exports&&(exports.IdentifierGenerator=r,exports.IdentifierGeneratorHandlers=t),n})("undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof globalThis?globalThis:{}),IdentifierGeneratorElementGF=globalFunct.IdentifierGenerator,IdentifierGeneratorHandlersElementGF=globalFunct.IdentifierGeneratorHandlers;"undefined"!=typeof module&&module.exports&&(module.exports={IdentifierGenerator:IdentifierGeneratorElementGF,IdentifierGeneratorHandlers:IdentifierGeneratorHandlersElementGF}),"undefined"!=typeof module&&module.exports&&(module.exports.default=globalFunct?.default);
|