@jsarc/id-generator 0.0.0 → 0.0.1-beta.0.2
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/index.ts +15 -41
- package/js/index.js +7 -29
- package/package.json +1 -1
- package/web/id-generator.js +14 -17
- package/web/id-generator.min.js +1 -1
package/index.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
|
|
3
|
-
interface Window {
|
|
4
|
-
IdentifierGenerator: any;
|
|
5
|
-
IdentifierGeneratorHandlers: any;
|
|
6
|
-
__bundledModules: any;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
3
|
export interface RandomOptions {
|
|
10
4
|
size: number;
|
|
11
5
|
type: RandomType;
|
|
@@ -36,7 +30,7 @@ export type UUIDVersion = 'v1' | 'v2' | 'v3' | 'v4' | 'v5';
|
|
|
36
30
|
|
|
37
31
|
export type CustomHandler = () => string;
|
|
38
32
|
|
|
39
|
-
const globalFunct = (function(
|
|
33
|
+
const globalFunct = (function() {
|
|
40
34
|
'use strict';
|
|
41
35
|
|
|
42
36
|
|
|
@@ -49,8 +43,6 @@ const globalFunct = (function(global: any) {
|
|
|
49
43
|
|
|
50
44
|
|
|
51
45
|
|
|
52
|
-
|
|
53
|
-
|
|
54
46
|
class IdentifierGenerator {
|
|
55
47
|
private static instance: IdentifierGenerator;
|
|
56
48
|
private cache: Map<string, Map<string, string>> = new Map();
|
|
@@ -460,13 +452,6 @@ const globalFunct = (function(global: any) {
|
|
|
460
452
|
public static generateId(format: string, customHandlers: Record<string, CustomHandler> = {}): string {
|
|
461
453
|
return this.getInstance().generate(format, customHandlers);
|
|
462
454
|
}
|
|
463
|
-
|
|
464
|
-
static exposeToGlobal(): void {
|
|
465
|
-
if (typeof window !== 'undefined') {
|
|
466
|
-
window.IdentifierGenerator = IdentifierGenerator;
|
|
467
|
-
window.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
455
|
}
|
|
471
456
|
|
|
472
457
|
const IdentifierGeneratorHandlers = {
|
|
@@ -480,18 +465,14 @@ const globalFunct = (function(global: any) {
|
|
|
480
465
|
env: (envVar: string) => process.env[envVar] || ''
|
|
481
466
|
};
|
|
482
467
|
|
|
483
|
-
|
|
484
|
-
window.IdentifierGenerator = IdentifierGenerator;
|
|
485
|
-
window.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
export default {
|
|
468
|
+
const idGen = {
|
|
489
469
|
IdentifierGenerator,
|
|
490
470
|
IdentifierGeneratorHandlers,
|
|
491
|
-
}
|
|
471
|
+
};
|
|
472
|
+
|
|
492
473
|
|
|
493
474
|
const globalFunctModule = {
|
|
494
|
-
default:
|
|
475
|
+
default: idGen,
|
|
495
476
|
IdentifierGenerator: IdentifierGenerator,
|
|
496
477
|
IdentifierGeneratorHandlers: IdentifierGeneratorHandlers,
|
|
497
478
|
};
|
|
@@ -499,41 +480,34 @@ const globalFunct = (function(global: any) {
|
|
|
499
480
|
|
|
500
481
|
const __bundledModules = globalFunctModule;
|
|
501
482
|
|
|
502
|
-
if (typeof global !== 'undefined') {
|
|
503
|
-
(global as any).IdentifierGenerator = IdentifierGenerator;
|
|
504
|
-
(global as any).IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
505
|
-
(global as any).__bundledModules = __bundledModules;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
if (typeof window !== "undefined") {
|
|
509
|
-
(window as any).IdentifierGenerator = IdentifierGenerator;
|
|
510
|
-
(window as any).IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
511
|
-
(window as any).__bundledModules = __bundledModules;
|
|
512
|
-
}
|
|
513
|
-
|
|
514
483
|
if (typeof exports !== 'undefined') {
|
|
484
|
+
exports.default = idGen;
|
|
515
485
|
exports.IdentifierGenerator = IdentifierGenerator;
|
|
516
486
|
exports.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
517
487
|
}
|
|
518
488
|
return globalFunctModule;
|
|
519
489
|
|
|
520
|
-
})(
|
|
521
|
-
typeof window !== 'undefined' ? window :
|
|
522
|
-
typeof self !== 'undefined' ? self :
|
|
523
|
-
typeof globalThis !== 'undefined' ? globalThis :
|
|
524
|
-
{});
|
|
490
|
+
})();
|
|
525
491
|
|
|
526
492
|
type IdentifierGeneratorElementTypeGF = typeof globalFunct.IdentifierGenerator;
|
|
527
493
|
|
|
528
494
|
type IdentifierGeneratorHandlersElementTypeGF = typeof globalFunct.IdentifierGeneratorHandlers;
|
|
529
495
|
|
|
496
|
+
type DefaultElementTypeGF = typeof globalFunct.default;
|
|
497
|
+
|
|
530
498
|
const IdentifierGeneratorElementGF: IdentifierGeneratorElementTypeGF = globalFunct.IdentifierGenerator;
|
|
531
499
|
|
|
532
500
|
const IdentifierGeneratorHandlersElementGF: IdentifierGeneratorHandlersElementTypeGF = globalFunct.IdentifierGeneratorHandlers;
|
|
533
501
|
|
|
502
|
+
const defaultElementGF: DefaultElementTypeGF = globalFunct.default;
|
|
503
|
+
|
|
534
504
|
export {
|
|
505
|
+
defaultElementGF as default,
|
|
535
506
|
IdentifierGeneratorElementGF as IdentifierGenerator,
|
|
536
507
|
IdentifierGeneratorHandlersElementGF as IdentifierGeneratorHandlers,
|
|
537
508
|
};
|
|
538
509
|
export type {
|
|
510
|
+
DefaultElementTypeGF,
|
|
511
|
+
RandomType,UUIDVersion,CustomHandler,RandomOptions,UUIDOptions,TokenDefinition,
|
|
512
|
+
IdentifierGeneratorElementTypeGF,IdentifierGeneratorHandlersElementTypeGF,
|
|
539
513
|
};
|
package/js/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const globalFunct = (function (
|
|
1
|
+
const globalFunct = (function () {
|
|
2
2
|
'use strict';
|
|
3
3
|
class IdentifierGenerator {
|
|
4
4
|
static instance;
|
|
@@ -350,12 +350,6 @@ const globalFunct = (function (global) {
|
|
|
350
350
|
static generateId(format, customHandlers = {}) {
|
|
351
351
|
return this.getInstance().generate(format, customHandlers);
|
|
352
352
|
}
|
|
353
|
-
static exposeToGlobal() {
|
|
354
|
-
if (typeof window !== 'undefined') {
|
|
355
|
-
window.IdentifierGenerator = IdentifierGenerator;
|
|
356
|
-
window.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
353
|
}
|
|
360
354
|
const IdentifierGeneratorHandlers = {
|
|
361
355
|
timestamp: () => Date.now().toString(),
|
|
@@ -367,40 +361,24 @@ const globalFunct = (function (global) {
|
|
|
367
361
|
})(),
|
|
368
362
|
env: (envVar) => process.env[envVar] || ''
|
|
369
363
|
};
|
|
370
|
-
|
|
371
|
-
window.IdentifierGenerator = IdentifierGenerator;
|
|
372
|
-
window.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
373
|
-
}
|
|
374
|
-
export default {
|
|
364
|
+
const idGen = {
|
|
375
365
|
IdentifierGenerator,
|
|
376
366
|
IdentifierGeneratorHandlers,
|
|
377
367
|
};
|
|
378
368
|
const globalFunctModule = {
|
|
379
|
-
default:
|
|
369
|
+
default: idGen,
|
|
380
370
|
IdentifierGenerator: IdentifierGenerator,
|
|
381
371
|
IdentifierGeneratorHandlers: IdentifierGeneratorHandlers,
|
|
382
372
|
};
|
|
383
373
|
const __bundledModules = globalFunctModule;
|
|
384
|
-
if (typeof global !== 'undefined') {
|
|
385
|
-
global.IdentifierGenerator = IdentifierGenerator;
|
|
386
|
-
global.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
387
|
-
global.__bundledModules = __bundledModules;
|
|
388
|
-
}
|
|
389
|
-
if (typeof window !== "undefined") {
|
|
390
|
-
window.IdentifierGenerator = IdentifierGenerator;
|
|
391
|
-
window.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
392
|
-
window.__bundledModules = __bundledModules;
|
|
393
|
-
}
|
|
394
374
|
if (typeof exports !== 'undefined') {
|
|
375
|
+
exports.default = idGen;
|
|
395
376
|
exports.IdentifierGenerator = IdentifierGenerator;
|
|
396
377
|
exports.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
397
378
|
}
|
|
398
379
|
return globalFunctModule;
|
|
399
|
-
})(
|
|
400
|
-
typeof window !== 'undefined' ? window :
|
|
401
|
-
typeof self !== 'undefined' ? self :
|
|
402
|
-
typeof globalThis !== 'undefined' ? globalThis :
|
|
403
|
-
{});
|
|
380
|
+
})();
|
|
404
381
|
const IdentifierGeneratorElementGF = globalFunct.IdentifierGenerator;
|
|
405
382
|
const IdentifierGeneratorHandlersElementGF = globalFunct.IdentifierGeneratorHandlers;
|
|
406
|
-
|
|
383
|
+
const defaultElementGF = globalFunct.default;
|
|
384
|
+
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.2",
|
|
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": [],
|
package/web/id-generator.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const globalFunct = (function (
|
|
1
|
+
const globalFunct = (function () {
|
|
2
2
|
'use strict';
|
|
3
3
|
class IdentifierGenerator {
|
|
4
4
|
static instance;
|
|
@@ -371,26 +371,23 @@ const globalFunct = (function (global) {
|
|
|
371
371
|
window.IdentifierGenerator = IdentifierGenerator;
|
|
372
372
|
window.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
373
373
|
}
|
|
374
|
+
const idGen = {
|
|
375
|
+
IdentifierGenerator,
|
|
376
|
+
IdentifierGeneratorHandlers,
|
|
377
|
+
};
|
|
378
|
+
const globalFunctModule = {
|
|
379
|
+
default: idGen,
|
|
380
|
+
IdentifierGenerator: IdentifierGenerator,
|
|
381
|
+
IdentifierGeneratorHandlers: IdentifierGeneratorHandlers,
|
|
382
|
+
};
|
|
374
383
|
const __bundledModules = globalFunctModule;
|
|
375
|
-
if (typeof global !== 'undefined') {
|
|
376
|
-
global.IdentifierGenerator = IdentifierGenerator;
|
|
377
|
-
global.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
378
|
-
global.__bundledModules = __bundledModules;
|
|
379
|
-
}
|
|
380
|
-
if (typeof window !== "undefined") {
|
|
381
|
-
window.IdentifierGenerator = IdentifierGenerator;
|
|
382
|
-
window.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
383
|
-
window.__bundledModules = __bundledModules;
|
|
384
|
-
}
|
|
385
384
|
if (typeof exports !== 'undefined') {
|
|
385
|
+
exports.default = idGen;
|
|
386
386
|
exports.IdentifierGenerator = IdentifierGenerator;
|
|
387
387
|
exports.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
388
388
|
}
|
|
389
389
|
return globalFunctModule;
|
|
390
|
-
})(
|
|
391
|
-
typeof window !== 'undefined' ? window :
|
|
392
|
-
typeof self !== 'undefined' ? self :
|
|
393
|
-
typeof globalThis !== 'undefined' ? globalThis :
|
|
394
|
-
{});
|
|
390
|
+
})();
|
|
395
391
|
const IdentifierGeneratorElementGF = globalFunct.IdentifierGenerator;
|
|
396
|
-
const IdentifierGeneratorHandlersElementGF = globalFunct.IdentifierGeneratorHandlers;
|
|
392
|
+
const IdentifierGeneratorHandlersElementGF = globalFunct.IdentifierGeneratorHandlers;
|
|
393
|
+
const defaultElementGF = globalFunct.default;
|
package/web/id-generator.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let globalFunct=(
|
|
1
|
+
let globalFunct=(()=>{class e{static instance;cache=new Map;constructor(){}static getInstance(){return e.instance||(e.instance=new e),e.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 s=r[e];if(i)i=!1;else if("\\"===s)i=!0;else if('"'===s||"'"===s)a=!a;else if(!a)if("{"===s)n++;else if("}"===s){if(0===n)return e;n--}else{if("#"===s&&0===n)return e;if(!1===/[a-zA-Z0-9]/.test(s)&&","!==s&&":"!==s&&"-"!==s&&"_"!==s&&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,s="",o=0;for(let e=0;e<r.length;e++){var l=r[e];if('"'===l||"'"===l)i?s===l?i=!1:a+=l:(i=!0,s=l);else{if(!i)if(":"===l){if(0===o){n=a.trim(),a="";continue}}else if("{"===l)o++;else if("}"===l)o--;else if(","===l&&0===o){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=e,window.IdentifierGeneratorHandlers=r)}}let r={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=e,window.IdentifierGeneratorHandlers=r);var t={IdentifierGenerator:e,IdentifierGeneratorHandlers:r},n={default:t,IdentifierGenerator:e,IdentifierGeneratorHandlers:r};return"undefined"!=typeof exports&&(exports.default=t,exports.IdentifierGenerator=e,exports.IdentifierGeneratorHandlers=r),n})(),IdentifierGeneratorElementGF=globalFunct.IdentifierGenerator,IdentifierGeneratorHandlersElementGF=globalFunct.IdentifierGeneratorHandlers,defaultElementGF=globalFunct.default;
|