diff --git a/dist/short-unique-id.js b/dist/short-unique-id.js index 5f219df..b743953 100644 --- a/dist/short-unique-id.js +++ b/dist/short-unique-id.js @@ -28,7 +28,7 @@ __export(exports, { }); // package.json -var version = "4.3.4"; +var version = "4.3.5"; // src/index.ts var DEFAULT_UUID_LENGTH = 6; diff --git a/dist/short-unique-id.min.js b/dist/short-unique-id.min.js index d709d51..ce33735 100644 --- a/dist/short-unique-id.min.js +++ b/dist/short-unique-id.min.js @@ -1 +1 @@ -var h=Object.defineProperty;var c=Object.getOwnPropertySymbols;var m=Object.prototype.hasOwnProperty,f=Object.prototype.propertyIsEnumerable;var g=(r,t,i)=>t in r?h(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,d=(r,t)=>{for(var i in t||(t={}))m.call(t,i)&&g(r,i,t[i]);if(c)for(var i of c(t))f.call(t,i)&&g(r,i,t[i]);return r};var I=r=>h(r,"__esModule",{value:!0});var U=(r,t)=>{I(r);for(var i in t)h(r,i,{get:t[i],enumerable:!0})};U(exports,{DEFAULT_UUID_LENGTH:()=>l,default:()=>a});var b="4.3.4";var l=6,q={dictionary:"alphanum",shuffle:!0,debug:!1,length:l},p=class extends Function{constructor(t={}){super();this.dictIndex=0;this.dictRange=[];this.lowerBound=0;this.upperBound=0;this.dictLength=0;this._digit_first_ascii=48;this._digit_last_ascii=58;this._alpha_lower_first_ascii=97;this._alpha_lower_last_ascii=123;this._hex_last_ascii=103;this._alpha_upper_first_ascii=65;this._alpha_upper_last_ascii=91;this._number_dict_ranges={digits:[this._digit_first_ascii,this._digit_last_ascii]};this._alpha_dict_ranges={lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii],upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]};this._alpha_lower_dict_ranges={lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii]};this._alpha_upper_dict_ranges={upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]};this._alphanum_dict_ranges={digits:[this._digit_first_ascii,this._digit_last_ascii],lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii],upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]};this._alphanum_lower_dict_ranges={digits:[this._digit_first_ascii,this._digit_last_ascii],lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii]};this._alphanum_upper_dict_ranges={digits:[this._digit_first_ascii,this._digit_last_ascii],upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]};this._hex_dict_ranges={decDigits:[this._digit_first_ascii,this._digit_last_ascii],alphaDigits:[this._alpha_lower_first_ascii,this._hex_last_ascii]};this.log=(...t)=>{let i=[...t];if(i[0]=`[short-unique-id] ${t[0]}`,this.debug===!0&&typeof console!="undefined"&&console!==null)return console.log(...i)};this.setDictionary=(t,i)=>{let e;if(t&&Array.isArray(t)&&t.length>1)e=t;else{e=[];let s;this.dictIndex=s=0;let n=`_${t}_dict_ranges`,o=this[n];Object.keys(o).forEach(_=>{let u=_;for(this.dictRange=o[u],this.lowerBound=this.dictRange[0],this.upperBound=this.dictRange[1],this.dictIndex=s=this.lowerBound;this.lowerBound<=this.upperBound?sthis.upperBound;this.dictIndex=this.lowerBound<=this.upperBound?s+=1:s-=1)e.push(String.fromCharCode(this.dictIndex))})}if(i){let s=.5;e=e.sort(()=>Math.random()-s)}this.dict=e,this.dictLength=this.dict.length,this.counter=0};this.seq=()=>this.sequentialUUID();this.sequentialUUID=()=>{let t,i,e="";t=this.counter;do i=t%this.dictLength,t=Math.trunc(t/this.dictLength),e+=this.dict[i];while(t!==0);return this.counter+=1,e};this.randomUUID=(t=this.uuidLength||l)=>{let i,e,s;if(t===null||typeof t=="undefined"||t<1)throw new Error("Invalid UUID Length Provided");let n=t>=0;for(i="",s=0;sparseFloat(Math.pow([...new Set(this.dict)].length,t).toFixed(0));this.approxMaxBeforeCollision=(t=this.availableUUIDs(this.uuidLength))=>parseFloat(Math.sqrt(Math.PI/2*t).toFixed(20));this.collisionProbability=(t=this.availableUUIDs(this.uuidLength),i=this.uuidLength)=>parseFloat((this.approxMaxBeforeCollision(t)/this.availableUUIDs(i)).toFixed(20));this.uniqueness=(t=this.availableUUIDs(this.uuidLength))=>{let i=parseFloat((1-this.approxMaxBeforeCollision(t)/t).toFixed(20));return i>1?1:i<0?0:i};this.getVersion=()=>this.version;this.stamp=t=>{if(typeof t!="number"||t<10)throw new Error("Param finalLength must be number greater than 10");let i=Math.floor(+new Date/1e3).toString(16),e=t-9,s=Math.round(Math.random()*(e>15?15:e)),n=this.randomUUID(e);return`${n.substr(0,s)}${i}${n.substr(s)}${s.toString(16)}`};this.parseStamp=t=>{if(t.length<10)throw new Error("Stamp length invalid");let i=parseInt(t.substr(t.length-1,1),16);return new Date(parseInt(t.substr(i,8),16)*1e3)};let i=d(d({},q),t);this.counter=0,this.debug=!1,this.dict=[],this.version=b;let{dictionary:e,shuffle:s,length:n}=i;return this.uuidLength=n,this.setDictionary(e,s),this.debug=i.debug,this.log(this.dict),this.log(`Generator instantiated with Dictionary Size ${this.dictLength}`),new Proxy(this,{apply:(o,_,u)=>this.randomUUID(...u)})}},a=p;a.default=p;module.exports=a;0&&(module.exports={DEFAULT_UUID_LENGTH}); +var h=Object.defineProperty;var c=Object.getOwnPropertySymbols;var m=Object.prototype.hasOwnProperty,f=Object.prototype.propertyIsEnumerable;var g=(r,t,i)=>t in r?h(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,d=(r,t)=>{for(var i in t||(t={}))m.call(t,i)&&g(r,i,t[i]);if(c)for(var i of c(t))f.call(t,i)&&g(r,i,t[i]);return r};var I=r=>h(r,"__esModule",{value:!0});var U=(r,t)=>{I(r);for(var i in t)h(r,i,{get:t[i],enumerable:!0})};U(exports,{DEFAULT_UUID_LENGTH:()=>l,default:()=>a});var b="4.3.5";var l=6,q={dictionary:"alphanum",shuffle:!0,debug:!1,length:l},p=class extends Function{constructor(t={}){super();this.dictIndex=0;this.dictRange=[];this.lowerBound=0;this.upperBound=0;this.dictLength=0;this._digit_first_ascii=48;this._digit_last_ascii=58;this._alpha_lower_first_ascii=97;this._alpha_lower_last_ascii=123;this._hex_last_ascii=103;this._alpha_upper_first_ascii=65;this._alpha_upper_last_ascii=91;this._number_dict_ranges={digits:[this._digit_first_ascii,this._digit_last_ascii]};this._alpha_dict_ranges={lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii],upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]};this._alpha_lower_dict_ranges={lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii]};this._alpha_upper_dict_ranges={upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]};this._alphanum_dict_ranges={digits:[this._digit_first_ascii,this._digit_last_ascii],lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii],upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]};this._alphanum_lower_dict_ranges={digits:[this._digit_first_ascii,this._digit_last_ascii],lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii]};this._alphanum_upper_dict_ranges={digits:[this._digit_first_ascii,this._digit_last_ascii],upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]};this._hex_dict_ranges={decDigits:[this._digit_first_ascii,this._digit_last_ascii],alphaDigits:[this._alpha_lower_first_ascii,this._hex_last_ascii]};this.log=(...t)=>{let i=[...t];if(i[0]=`[short-unique-id] ${t[0]}`,this.debug===!0&&typeof console!="undefined"&&console!==null)return console.log(...i)};this.setDictionary=(t,i)=>{let e;if(t&&Array.isArray(t)&&t.length>1)e=t;else{e=[];let s;this.dictIndex=s=0;let n=`_${t}_dict_ranges`,o=this[n];Object.keys(o).forEach(_=>{let u=_;for(this.dictRange=o[u],this.lowerBound=this.dictRange[0],this.upperBound=this.dictRange[1],this.dictIndex=s=this.lowerBound;this.lowerBound<=this.upperBound?sthis.upperBound;this.dictIndex=this.lowerBound<=this.upperBound?s+=1:s-=1)e.push(String.fromCharCode(this.dictIndex))})}if(i){let s=.5;e=e.sort(()=>Math.random()-s)}this.dict=e,this.dictLength=this.dict.length,this.counter=0};this.seq=()=>this.sequentialUUID();this.sequentialUUID=()=>{let t,i,e="";t=this.counter;do i=t%this.dictLength,t=Math.trunc(t/this.dictLength),e+=this.dict[i];while(t!==0);return this.counter+=1,e};this.randomUUID=(t=this.uuidLength||l)=>{let i,e,s;if(t===null||typeof t=="undefined"||t<1)throw new Error("Invalid UUID Length Provided");let n=t>=0;for(i="",s=0;sparseFloat(Math.pow([...new Set(this.dict)].length,t).toFixed(0));this.approxMaxBeforeCollision=(t=this.availableUUIDs(this.uuidLength))=>parseFloat(Math.sqrt(Math.PI/2*t).toFixed(20));this.collisionProbability=(t=this.availableUUIDs(this.uuidLength),i=this.uuidLength)=>parseFloat((this.approxMaxBeforeCollision(t)/this.availableUUIDs(i)).toFixed(20));this.uniqueness=(t=this.availableUUIDs(this.uuidLength))=>{let i=parseFloat((1-this.approxMaxBeforeCollision(t)/t).toFixed(20));return i>1?1:i<0?0:i};this.getVersion=()=>this.version;this.stamp=t=>{if(typeof t!="number"||t<10)throw new Error("Param finalLength must be number greater than 10");let i=Math.floor(+new Date/1e3).toString(16),e=t-9,s=Math.round(Math.random()*(e>15?15:e)),n=this.randomUUID(e);return`${n.substr(0,s)}${i}${n.substr(s)}${s.toString(16)}`};this.parseStamp=t=>{if(t.length<10)throw new Error("Stamp length invalid");let i=parseInt(t.substr(t.length-1,1),16);return new Date(parseInt(t.substr(i,8),16)*1e3)};let i=d(d({},q),t);this.counter=0,this.debug=!1,this.dict=[],this.version=b;let{dictionary:e,shuffle:s,length:n}=i;return this.uuidLength=n,this.setDictionary(e,s),this.debug=i.debug,this.log(this.dict),this.log(`Generator instantiated with Dictionary Size ${this.dictLength}`),new Proxy(this,{apply:(o,_,u)=>this.randomUUID(...u)})}},a=p;a.default=p;module.exports=a;0&&(module.exports={DEFAULT_UUID_LENGTH}); diff --git a/docs/assets/contributors/char0n.svg b/docs/assets/contributors/char0n.svg new file mode 100644 index 0000000..90397d3 --- /dev/null +++ b/docs/assets/contributors/char0n.svg @@ -0,0 +1 @@ +Vladimir Gorej diff --git a/docs/assets/contributors/coldtq.svg b/docs/assets/contributors/coldtq.svg new file mode 100644 index 0000000..c0ae66d --- /dev/null +++ b/docs/assets/contributors/coldtq.svg @@ -0,0 +1 @@ +ColdtQ diff --git a/docs/classes/default.html b/docs/classes/default.html index 4e058bb..77b2162 100644 --- a/docs/classes/default.html +++ b/docs/classes/default.html @@ -4,7 +4,7 @@ Short Unique ID - Short UUID Generator - + @@ -299,7 +299,7 @@

constructor

Parameters

@@ -321,7 +321,7 @@

counter

counter: number
@@ -331,7 +331,7 @@

debug

debug: boolean
@@ -341,7 +341,7 @@

dict

dict: string[]
@@ -351,7 +351,7 @@

dictIndex

dictIndex: number = 0
@@ -361,7 +361,7 @@

dictLength

dictLength: number = 0
@@ -371,7 +371,7 @@

dictRange

dictRange: number[] = []
@@ -381,7 +381,7 @@

lowerBound

lowerBound: number = 0
@@ -391,7 +391,7 @@

upperBound

upperBound: number = 0
@@ -401,7 +401,7 @@

uuidLength

uuidLength: number
@@ -411,7 +411,7 @@

version

version: string
@@ -421,7 +421,7 @@

Static default

default: typeof default = ...
@@ -438,7 +438,7 @@

approxMaxBeforeCollision

  • @@ -478,7 +478,7 @@

    availableUUIDs

  • @@ -515,7 +515,7 @@

    collisionProbability

  • @@ -561,7 +561,7 @@

    getVersion

  • @@ -583,7 +583,7 @@

    parseStamp

  • @@ -618,7 +618,7 @@

    randomUUID

  • @@ -651,7 +651,7 @@

    seq

  • Returns string

    @@ -668,7 +668,7 @@

    sequentialUUID

  • @@ -695,7 +695,7 @@

    setDictionary

  • @@ -726,7 +726,7 @@

    stamp

  • @@ -761,7 +761,7 @@

    uniqueness

  • diff --git a/docs/index.html b/docs/index.html index 194db47..a6bee57 100644 --- a/docs/index.html +++ b/docs/index.html @@ -4,7 +4,7 @@ Short Unique ID - Short UUID Generator - + @@ -15,7 +15,7 @@
    -

    short-unique-id - v4.3.3

    +

    short-unique-id - v4.3.5

    @@ -408,6 +408,8 @@

    Contributors ✨

    🛡️
    +
    💻
    +
    💻
    diff --git a/docs/interfaces/shortuniqueidoptions.html b/docs/interfaces/shortuniqueidoptions.html index e2d4570..3e851ce 100644 --- a/docs/interfaces/shortuniqueidoptions.html +++ b/docs/interfaces/shortuniqueidoptions.html @@ -4,7 +4,7 @@ Short Unique ID - Short UUID Generator - + @@ -123,7 +123,7 @@

    debug

    debug: boolean
    @@ -138,7 +138,7 @@

    dictionary

    dictionary: string[] | defaultDictionaries
    @@ -153,7 +153,7 @@

    length

    length: number
    @@ -168,7 +168,7 @@

    shuffle

    shuffle: boolean
    diff --git a/docs/modules.html b/docs/modules.html index eb2341c..b81eb57 100644 --- a/docs/modules.html +++ b/docs/modules.html @@ -4,7 +4,7 @@ Short Unique ID - Short UUID Generator - + @@ -15,7 +15,7 @@
    -

    short-unique-id - v4.3.3

    +

    short-unique-id - v4.3.5

    @@ -77,7 +77,7 @@

    Const DEFAULT_UUID_LENG
    DEFAULT_UUID_LENGTH: number = 6