@jsarc/id-generator 0.0.1-beta.0.1 → 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 +2 -41
- package/js/index.js +2 -28
- package/package.json +1 -1
- package/web/id-generator.js +2 -18
- package/web/id-generator.min.js +1 -1
- package/id-generator.ts +0 -538
- package/ts/id-generator.ts +0 -538
- package/ts/index.ts +0 -552
package/index.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
|
|
3
|
-
interface Window {
|
|
4
|
-
default: typeof defaultElementGF;
|
|
5
|
-
IdentifierGenerator: any;
|
|
6
|
-
IdentifierGeneratorHandlers: any;
|
|
7
|
-
__bundledModules: any;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
3
|
export interface RandomOptions {
|
|
11
4
|
size: number;
|
|
12
5
|
type: RandomType;
|
|
@@ -37,7 +30,7 @@ export type UUIDVersion = 'v1' | 'v2' | 'v3' | 'v4' | 'v5';
|
|
|
37
30
|
|
|
38
31
|
export type CustomHandler = () => string;
|
|
39
32
|
|
|
40
|
-
const globalFunct = (function(
|
|
33
|
+
const globalFunct = (function() {
|
|
41
34
|
'use strict';
|
|
42
35
|
|
|
43
36
|
|
|
@@ -50,8 +43,6 @@ const globalFunct = (function(global: any) {
|
|
|
50
43
|
|
|
51
44
|
|
|
52
45
|
|
|
53
|
-
|
|
54
|
-
|
|
55
46
|
class IdentifierGenerator {
|
|
56
47
|
private static instance: IdentifierGenerator;
|
|
57
48
|
private cache: Map<string, Map<string, string>> = new Map();
|
|
@@ -461,13 +452,6 @@ const globalFunct = (function(global: any) {
|
|
|
461
452
|
public static generateId(format: string, customHandlers: Record<string, CustomHandler> = {}): string {
|
|
462
453
|
return this.getInstance().generate(format, customHandlers);
|
|
463
454
|
}
|
|
464
|
-
|
|
465
|
-
static exposeToGlobal(): void {
|
|
466
|
-
if (typeof window !== 'undefined') {
|
|
467
|
-
(window as any).IdentifierGenerator = IdentifierGenerator;
|
|
468
|
-
(window as any).IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
455
|
}
|
|
472
456
|
|
|
473
457
|
const IdentifierGeneratorHandlers = {
|
|
@@ -481,11 +465,6 @@ const globalFunct = (function(global: any) {
|
|
|
481
465
|
env: (envVar: string) => process.env[envVar] || ''
|
|
482
466
|
};
|
|
483
467
|
|
|
484
|
-
if (typeof window !== 'undefined') {
|
|
485
|
-
(window as any).IdentifierGenerator = IdentifierGenerator;
|
|
486
|
-
(window as any).IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
468
|
const idGen = {
|
|
490
469
|
IdentifierGenerator,
|
|
491
470
|
IdentifierGeneratorHandlers,
|
|
@@ -501,20 +480,6 @@ const globalFunct = (function(global: any) {
|
|
|
501
480
|
|
|
502
481
|
const __bundledModules = globalFunctModule;
|
|
503
482
|
|
|
504
|
-
if (typeof global !== 'undefined') {
|
|
505
|
-
(global as any).default = idGen;
|
|
506
|
-
(global as any).IdentifierGenerator = IdentifierGenerator;
|
|
507
|
-
(global as any).IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
508
|
-
(global as any).__bundledModules = __bundledModules;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
if (typeof window !== "undefined") {
|
|
512
|
-
(window as any).default = idGen;
|
|
513
|
-
(window as any).IdentifierGenerator = IdentifierGenerator;
|
|
514
|
-
(window as any).IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
515
|
-
(window as any).__bundledModules = __bundledModules;
|
|
516
|
-
}
|
|
517
|
-
|
|
518
483
|
if (typeof exports !== 'undefined') {
|
|
519
484
|
exports.default = idGen;
|
|
520
485
|
exports.IdentifierGenerator = IdentifierGenerator;
|
|
@@ -522,11 +487,7 @@ const globalFunct = (function(global: any) {
|
|
|
522
487
|
}
|
|
523
488
|
return globalFunctModule;
|
|
524
489
|
|
|
525
|
-
})(
|
|
526
|
-
typeof window !== 'undefined' ? window :
|
|
527
|
-
typeof self !== 'undefined' ? self :
|
|
528
|
-
typeof globalThis !== 'undefined' ? globalThis :
|
|
529
|
-
{});
|
|
490
|
+
})();
|
|
530
491
|
|
|
531
492
|
type IdentifierGeneratorElementTypeGF = typeof globalFunct.IdentifierGenerator;
|
|
532
493
|
|
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,10 +361,6 @@ const globalFunct = (function (global) {
|
|
|
367
361
|
})(),
|
|
368
362
|
env: (envVar) => process.env[envVar] || ''
|
|
369
363
|
};
|
|
370
|
-
if (typeof window !== 'undefined') {
|
|
371
|
-
window.IdentifierGenerator = IdentifierGenerator;
|
|
372
|
-
window.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
373
|
-
}
|
|
374
364
|
const idGen = {
|
|
375
365
|
IdentifierGenerator,
|
|
376
366
|
IdentifierGeneratorHandlers,
|
|
@@ -381,29 +371,13 @@ const globalFunct = (function (global) {
|
|
|
381
371
|
IdentifierGeneratorHandlers: IdentifierGeneratorHandlers,
|
|
382
372
|
};
|
|
383
373
|
const __bundledModules = globalFunctModule;
|
|
384
|
-
if (typeof global !== 'undefined') {
|
|
385
|
-
global.default = idGen;
|
|
386
|
-
global.IdentifierGenerator = IdentifierGenerator;
|
|
387
|
-
global.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
388
|
-
global.__bundledModules = __bundledModules;
|
|
389
|
-
}
|
|
390
|
-
if (typeof window !== "undefined") {
|
|
391
|
-
window.default = idGen;
|
|
392
|
-
window.IdentifierGenerator = IdentifierGenerator;
|
|
393
|
-
window.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
394
|
-
window.__bundledModules = __bundledModules;
|
|
395
|
-
}
|
|
396
374
|
if (typeof exports !== 'undefined') {
|
|
397
375
|
exports.default = idGen;
|
|
398
376
|
exports.IdentifierGenerator = IdentifierGenerator;
|
|
399
377
|
exports.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
400
378
|
}
|
|
401
379
|
return globalFunctModule;
|
|
402
|
-
})(
|
|
403
|
-
typeof window !== 'undefined' ? window :
|
|
404
|
-
typeof self !== 'undefined' ? self :
|
|
405
|
-
typeof globalThis !== 'undefined' ? globalThis :
|
|
406
|
-
{});
|
|
380
|
+
})();
|
|
407
381
|
const IdentifierGeneratorElementGF = globalFunct.IdentifierGenerator;
|
|
408
382
|
const IdentifierGeneratorHandlersElementGF = globalFunct.IdentifierGeneratorHandlers;
|
|
409
383
|
const defaultElementGF = globalFunct.default;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.0.1-beta.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;
|
|
@@ -381,29 +381,13 @@ const globalFunct = (function (global) {
|
|
|
381
381
|
IdentifierGeneratorHandlers: IdentifierGeneratorHandlers,
|
|
382
382
|
};
|
|
383
383
|
const __bundledModules = globalFunctModule;
|
|
384
|
-
if (typeof global !== 'undefined') {
|
|
385
|
-
global.default = idGen;
|
|
386
|
-
global.IdentifierGenerator = IdentifierGenerator;
|
|
387
|
-
global.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
388
|
-
global.__bundledModules = __bundledModules;
|
|
389
|
-
}
|
|
390
|
-
if (typeof window !== "undefined") {
|
|
391
|
-
window.default = idGen;
|
|
392
|
-
window.IdentifierGenerator = IdentifierGenerator;
|
|
393
|
-
window.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
394
|
-
window.__bundledModules = __bundledModules;
|
|
395
|
-
}
|
|
396
384
|
if (typeof exports !== 'undefined') {
|
|
397
385
|
exports.default = idGen;
|
|
398
386
|
exports.IdentifierGenerator = IdentifierGenerator;
|
|
399
387
|
exports.IdentifierGeneratorHandlers = IdentifierGeneratorHandlers;
|
|
400
388
|
}
|
|
401
389
|
return globalFunctModule;
|
|
402
|
-
})(
|
|
403
|
-
typeof window !== 'undefined' ? window :
|
|
404
|
-
typeof self !== 'undefined' ? self :
|
|
405
|
-
typeof globalThis !== 'undefined' ? globalThis :
|
|
406
|
-
{});
|
|
390
|
+
})();
|
|
407
391
|
const IdentifierGeneratorElementGF = globalFunct.IdentifierGenerator;
|
|
408
392
|
const IdentifierGeneratorHandlersElementGF = globalFunct.IdentifierGeneratorHandlers;
|
|
409
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;
|