Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

short-unique-id

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

short-unique-id - npm Package Compare versions

Comparing version 5.0.3 to 5.0.4

2

dist/short-unique-id.js

@@ -48,3 +48,3 @@ "use strict";

// package.json
var version = "5.0.3";
var version = "5.0.4";

@@ -51,0 +51,0 @@ // src/index.ts

@@ -1,3 +0,3 @@

"use strict";var ShortUniqueId=(()=>{var l=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames,m=Object.getOwnPropertySymbols;var f=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var g=(a,t,i)=>t in a?l(a,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):a[t]=i,b=(a,t)=>{for(var i in t||(t={}))f.call(t,i)&&g(a,i,t[i]);if(m)for(var i of m(t))q.call(t,i)&&g(a,i,t[i]);return a};var x=(a,t)=>{for(var i in t)l(a,i,{get:t[i],enumerable:!0})},y=(a,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of w(t))!f.call(a,r)&&r!==i&&l(a,r,{get:()=>t[r],enumerable:!(s=D(t,r))||s.enumerable});return a};var S=a=>y(l({},"__esModule",{value:!0}),a);var e=(a,t,i)=>(g(a,typeof t!="symbol"?t+"":t,i),i);var v={};x(v,{DEFAULT_OPTIONS:()=>I,DEFAULT_UUID_LENGTH:()=>d,default:()=>p});var U="5.0.3";var d=6,I={dictionary:"alphanum",shuffle:!0,debug:!1,length:d,counter:0},_=class _{constructor(t={}){e(this,"counter");e(this,"debug");e(this,"dict");e(this,"version");e(this,"dictIndex",0);e(this,"dictRange",[]);e(this,"lowerBound",0);e(this,"upperBound",0);e(this,"dictLength",0);e(this,"uuidLength");e(this,"_digit_first_ascii",48);e(this,"_digit_last_ascii",58);e(this,"_alpha_lower_first_ascii",97);e(this,"_alpha_lower_last_ascii",123);e(this,"_hex_last_ascii",103);e(this,"_alpha_upper_first_ascii",65);e(this,"_alpha_upper_last_ascii",91);e(this,"_number_dict_ranges",{digits:[this._digit_first_ascii,this._digit_last_ascii]});e(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]});e(this,"_alpha_lower_dict_ranges",{lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii]});e(this,"_alpha_upper_dict_ranges",{upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]});e(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]});e(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]});e(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]});e(this,"_hex_dict_ranges",{decDigits:[this._digit_first_ascii,this._digit_last_ascii],alphaDigits:[this._alpha_lower_first_ascii,this._hex_last_ascii]});e(this,"_dict_ranges",{_number_dict_ranges:this._number_dict_ranges,_alpha_dict_ranges:this._alpha_dict_ranges,_alpha_lower_dict_ranges:this._alpha_lower_dict_ranges,_alpha_upper_dict_ranges:this._alpha_upper_dict_ranges,_alphanum_dict_ranges:this._alphanum_dict_ranges,_alphanum_lower_dict_ranges:this._alphanum_lower_dict_ranges,_alphanum_upper_dict_ranges:this._alphanum_upper_dict_ranges,_hex_dict_ranges:this._hex_dict_ranges});e(this,"log",(...t)=>{let i=[...t];if(i[0]=`[short-unique-id] ${t[0]}`,this.debug===!0&&typeof console<"u"&&console!==null)return console.log(...i)});e(this,"setDictionary",(t,i)=>{let s;if(t&&Array.isArray(t)&&t.length>1)s=t;else{s=[];let r;this.dictIndex=r=0;let o=`_${t}_dict_ranges`,n=this._dict_ranges[o];Object.keys(n).forEach(h=>{let c=h;for(this.dictRange=n[c],this.lowerBound=this.dictRange[0],this.upperBound=this.dictRange[1],this.dictIndex=r=this.lowerBound;this.lowerBound<=this.upperBound?r<this.upperBound:r>this.upperBound;this.dictIndex=this.lowerBound<=this.upperBound?r+=1:r-=1)s.push(String.fromCharCode(this.dictIndex))})}i&&(s=s.sort(()=>Math.random()-.5)),this.dict=s,this.dictLength=this.dict.length,this.setCounter(0)});e(this,"seq",()=>this.sequentialUUID());e(this,"sequentialUUID",()=>{let t,i,s="";t=this.counter;do i=t%this.dictLength,t=Math.trunc(t/this.dictLength),s+=this.dict[i];while(t!==0);return this.counter+=1,s});e(this,"rnd",(t=this.uuidLength||d)=>this.randomUUID(t));e(this,"randomUUID",(t=this.uuidLength||d)=>{let i,s,r;if(t===null||typeof t>"u"||t<1)throw new Error("Invalid UUID Length Provided");let o=t>=0;for(i="",r=0;r<t;r+=1)s=parseInt((Math.random()*this.dictLength).toFixed(0),10)%this.dictLength,i+=this.dict[s];return i});e(this,"fmt",(t,i)=>this.formattedUUID(t,i));e(this,"formattedUUID",(t,i)=>{let s={$r:this.randomUUID,$s:this.sequentialUUID,$t:this.stamp};return t.replace(/\$[rs]\d{0,}|\$t0|\$t[1-9]\d{1,}/g,o=>{let n=o.slice(0,2),h=parseInt(o.slice(2),10);return n==="$s"?s[n]().padStart(h,"0"):n==="$t"&&i?s[n](h,i):s[n](h)})});e(this,"availableUUIDs",(t=this.uuidLength)=>parseFloat(Math.pow([...new Set(this.dict)].length,t).toFixed(0)));e(this,"approxMaxBeforeCollision",(t=this.availableUUIDs(this.uuidLength))=>parseFloat(Math.sqrt(Math.PI/2*t).toFixed(20)));e(this,"collisionProbability",(t=this.availableUUIDs(this.uuidLength),i=this.uuidLength)=>parseFloat((this.approxMaxBeforeCollision(t)/this.availableUUIDs(i)).toFixed(20)));e(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});e(this,"getVersion",()=>this.version);e(this,"stamp",(t,i)=>{let s=Math.floor(+(i||new Date)/1e3).toString(16);if(typeof t=="number"&&t===0)return s;if(typeof t!="number"||t<10)throw new Error(["Param finalLength must be a number greater than or equal to 10,","or 0 if you want the raw hexadecimal timestamp"].join(`
`));let r=t-9,o=Math.round(Math.random()*(r>15?15:r)),n=this.randomUUID(r);return`${n.substring(0,o)}${s}${n.substring(o)}${o.toString(16)}`});e(this,"parseStamp",(t,i)=>{if(i&&!/t0|t[1-9]\d{1,}/.test(i))throw new Error("Cannot extract date from a formated UUID with no timestamp in the format");let s=i?i.replace(/\$[rs]\d{0,}|\$t0|\$t[1-9]\d{1,}/g,o=>{let n={$r:u=>[...Array(u)].map(()=>"r").join(""),$s:u=>[...Array(u)].map(()=>"s").join(""),$t:u=>[...Array(u)].map(()=>"t").join("")},h=o.slice(0,2),c=parseInt(o.slice(2),10);return n[h](c)}).replace(/^(.*?)(t{8,})(.*)$/g,(o,n,h)=>t.substring(n.length,n.length+h.length)):t;if(s.length===8)return new Date(parseInt(s,16)*1e3);if(s.length<10)throw new Error("Stamp length invalid");let r=parseInt(s.substring(s.length-1),16);return new Date(parseInt(s.substring(r,r+8),16)*1e3)});e(this,"setCounter",t=>{this.counter=t});let i=b(b({},I),t);this.counter=0,this.debug=!1,this.dict=[],this.version=U;let{dictionary:s,shuffle:r,length:o,counter:n}=i;return this.uuidLength=o,this.setDictionary(s,r),this.setCounter(n),this.debug=i.debug,this.log(this.dict),this.log(`Generator instantiated with Dictionary Size ${this.dictLength} and counter set to ${this.counter}`),this.log=this.log.bind(this),this.setDictionary=this.setDictionary.bind(this),this.setCounter=this.setCounter.bind(this),this.seq=this.seq.bind(this),this.sequentialUUID=this.sequentialUUID.bind(this),this.rnd=this.rnd.bind(this),this.randomUUID=this.randomUUID.bind(this),this.fmt=this.fmt.bind(this),this.formattedUUID=this.formattedUUID.bind(this),this.availableUUIDs=this.availableUUIDs.bind(this),this.approxMaxBeforeCollision=this.approxMaxBeforeCollision.bind(this),this.collisionProbability=this.collisionProbability.bind(this),this.uniqueness=this.uniqueness.bind(this),this.getVersion=this.getVersion.bind(this),this.stamp=this.stamp.bind(this),this.parseStamp=this.parseStamp.bind(this),this}};e(_,"default",_);var p=_;return S(v);})();
"use strict";var ShortUniqueId=(()=>{var l=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames,b=Object.getOwnPropertySymbols;var f=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable;var g=(a,t,i)=>t in a?l(a,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):a[t]=i,m=(a,t)=>{for(var i in t||(t={}))f.call(t,i)&&g(a,i,t[i]);if(b)for(var i of b(t))x.call(t,i)&&g(a,i,t[i]);return a};var q=(a,t)=>{for(var i in t)l(a,i,{get:t[i],enumerable:!0})},y=(a,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of w(t))!f.call(a,r)&&r!==i&&l(a,r,{get:()=>t[r],enumerable:!(s=D(t,r))||s.enumerable});return a};var S=a=>y(l({},"__esModule",{value:!0}),a);var e=(a,t,i)=>(g(a,typeof t!="symbol"?t+"":t,i),i);var $={};q($,{DEFAULT_OPTIONS:()=>I,DEFAULT_UUID_LENGTH:()=>d,default:()=>p});var U="5.0.4";var d=6,I={dictionary:"alphanum",shuffle:!0,debug:!1,length:d,counter:0},_=class _{constructor(t={}){e(this,"counter");e(this,"debug");e(this,"dict");e(this,"version");e(this,"dictIndex",0);e(this,"dictRange",[]);e(this,"lowerBound",0);e(this,"upperBound",0);e(this,"dictLength",0);e(this,"uuidLength");e(this,"_digit_first_ascii",48);e(this,"_digit_last_ascii",58);e(this,"_alpha_lower_first_ascii",97);e(this,"_alpha_lower_last_ascii",123);e(this,"_hex_last_ascii",103);e(this,"_alpha_upper_first_ascii",65);e(this,"_alpha_upper_last_ascii",91);e(this,"_number_dict_ranges",{digits:[this._digit_first_ascii,this._digit_last_ascii]});e(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]});e(this,"_alpha_lower_dict_ranges",{lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii]});e(this,"_alpha_upper_dict_ranges",{upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]});e(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]});e(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]});e(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]});e(this,"_hex_dict_ranges",{decDigits:[this._digit_first_ascii,this._digit_last_ascii],alphaDigits:[this._alpha_lower_first_ascii,this._hex_last_ascii]});e(this,"_dict_ranges",{_number_dict_ranges:this._number_dict_ranges,_alpha_dict_ranges:this._alpha_dict_ranges,_alpha_lower_dict_ranges:this._alpha_lower_dict_ranges,_alpha_upper_dict_ranges:this._alpha_upper_dict_ranges,_alphanum_dict_ranges:this._alphanum_dict_ranges,_alphanum_lower_dict_ranges:this._alphanum_lower_dict_ranges,_alphanum_upper_dict_ranges:this._alphanum_upper_dict_ranges,_hex_dict_ranges:this._hex_dict_ranges});e(this,"log",(...t)=>{let i=[...t];if(i[0]=`[short-unique-id] ${t[0]}`,this.debug===!0&&typeof console<"u"&&console!==null)return console.log(...i)});e(this,"setDictionary",(t,i)=>{let s;if(t&&Array.isArray(t)&&t.length>1)s=t;else{s=[];let r;this.dictIndex=r=0;let o=`_${t}_dict_ranges`,n=this._dict_ranges[o];Object.keys(n).forEach(h=>{let c=h;for(this.dictRange=n[c],this.lowerBound=this.dictRange[0],this.upperBound=this.dictRange[1],this.dictIndex=r=this.lowerBound;this.lowerBound<=this.upperBound?r<this.upperBound:r>this.upperBound;this.dictIndex=this.lowerBound<=this.upperBound?r+=1:r-=1)s.push(String.fromCharCode(this.dictIndex))})}i&&(s=s.sort(()=>Math.random()-.5)),this.dict=s,this.dictLength=this.dict.length,this.setCounter(0)});e(this,"seq",()=>this.sequentialUUID());e(this,"sequentialUUID",()=>{let t,i,s="";t=this.counter;do i=t%this.dictLength,t=Math.trunc(t/this.dictLength),s+=this.dict[i];while(t!==0);return this.counter+=1,s});e(this,"rnd",(t=this.uuidLength||d)=>this.randomUUID(t));e(this,"randomUUID",(t=this.uuidLength||d)=>{let i,s,r;if(t===null||typeof t>"u"||t<1)throw new Error("Invalid UUID Length Provided");let o=t>=0;for(i="",r=0;r<t;r+=1)s=parseInt((Math.random()*this.dictLength).toFixed(0),10)%this.dictLength,i+=this.dict[s];return i});e(this,"fmt",(t,i)=>this.formattedUUID(t,i));e(this,"formattedUUID",(t,i)=>{let s={$r:this.randomUUID,$s:this.sequentialUUID,$t:this.stamp};return t.replace(/\$[rs]\d{0,}|\$t0|\$t[1-9]\d{1,}/g,o=>{let n=o.slice(0,2),h=parseInt(o.slice(2),10);return n==="$s"?s[n]().padStart(h,"0"):n==="$t"&&i?s[n](h,i):s[n](h)})});e(this,"availableUUIDs",(t=this.uuidLength)=>parseFloat(Math.pow([...new Set(this.dict)].length,t).toFixed(0)));e(this,"approxMaxBeforeCollision",(t=this.availableUUIDs(this.uuidLength))=>parseFloat(Math.sqrt(Math.PI/2*t).toFixed(20)));e(this,"collisionProbability",(t=this.availableUUIDs(this.uuidLength),i=this.uuidLength)=>parseFloat((this.approxMaxBeforeCollision(t)/this.availableUUIDs(i)).toFixed(20)));e(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});e(this,"getVersion",()=>this.version);e(this,"stamp",(t,i)=>{let s=Math.floor(+(i||new Date)/1e3).toString(16);if(typeof t=="number"&&t===0)return s;if(typeof t!="number"||t<10)throw new Error(["Param finalLength must be a number greater than or equal to 10,","or 0 if you want the raw hexadecimal timestamp"].join(`
`));let r=t-9,o=Math.round(Math.random()*(r>15?15:r)),n=this.randomUUID(r);return`${n.substring(0,o)}${s}${n.substring(o)}${o.toString(16)}`});e(this,"parseStamp",(t,i)=>{if(i&&!/t0|t[1-9]\d{1,}/.test(i))throw new Error("Cannot extract date from a formated UUID with no timestamp in the format");let s=i?i.replace(/\$[rs]\d{0,}|\$t0|\$t[1-9]\d{1,}/g,o=>{let n={$r:u=>[...Array(u)].map(()=>"r").join(""),$s:u=>[...Array(u)].map(()=>"s").join(""),$t:u=>[...Array(u)].map(()=>"t").join("")},h=o.slice(0,2),c=parseInt(o.slice(2),10);return n[h](c)}).replace(/^(.*?)(t{8,})(.*)$/g,(o,n,h)=>t.substring(n.length,n.length+h.length)):t;if(s.length===8)return new Date(parseInt(s,16)*1e3);if(s.length<10)throw new Error("Stamp length invalid");let r=parseInt(s.substring(s.length-1),16);return new Date(parseInt(s.substring(r,r+8),16)*1e3)});e(this,"setCounter",t=>{this.counter=t});let i=m(m({},I),t);this.counter=0,this.debug=!1,this.dict=[],this.version=U;let{dictionary:s,shuffle:r,length:o,counter:n}=i;return this.uuidLength=o,this.setDictionary(s,r),this.setCounter(n),this.debug=i.debug,this.log(this.dict),this.log(`Generator instantiated with Dictionary Size ${this.dictLength} and counter set to ${this.counter}`),this.log=this.log.bind(this),this.setDictionary=this.setDictionary.bind(this),this.setCounter=this.setCounter.bind(this),this.seq=this.seq.bind(this),this.sequentialUUID=this.sequentialUUID.bind(this),this.rnd=this.rnd.bind(this),this.randomUUID=this.randomUUID.bind(this),this.fmt=this.fmt.bind(this),this.formattedUUID=this.formattedUUID.bind(this),this.availableUUIDs=this.availableUUIDs.bind(this),this.approxMaxBeforeCollision=this.approxMaxBeforeCollision.bind(this),this.collisionProbability=this.collisionProbability.bind(this),this.uniqueness=this.uniqueness.bind(this),this.getVersion=this.getVersion.bind(this),this.stamp=this.stamp.bind(this),this.parseStamp=this.parseStamp.bind(this),this}};e(_,"default",_);var p=_;return S($);})();
'undefined'!=typeof module&&(module.exports=ShortUniqueId.default),'undefined'!=typeof window&&(ShortUniqueId=ShortUniqueId.default);
{
"name": "short-unique-id",
"version": "5.0.3",
"version": "5.0.4",
"description": "Generate random or sequential UUID of any length",

@@ -30,3 +30,4 @@ "keywords": [

"scripts": {
"test": "ts-node src/test.ts",
"test": "tsx ./src/test.ts",
"test:local": "tsx ./src/test.ts && tsx --tsconfig ./specs/tsconfig.json ./specs/import-esm.spec.ts && ./scripts/cjs-test",
"build": "./scripts/build",

@@ -54,3 +55,3 @@ "docs": "./scripts/docs",

"devDependencies": {
"@types/node": "^20.3.2",
"@types/node": "^20.12.7",
"auto-changelog": "^2.4.0",

@@ -60,10 +61,13 @@ "esbuild": "^0.18.10",

"release-it": "^15.11.0",
"ts-node": "^10.9.1",
"tslib": "^2.6.0",
"typedoc": "^0.24.8",
"typedoc-plugin-extras": "^2.3.3",
"typedoc-plugin-rename-defaults": "^0.6.5",
"typedoc-plugin-script-inject": "^1.0.0",
"typescript": "^5.1.6"
"tslib": "^2.6.2",
"tsx": "^4.7.3",
"typedoc": "^0.25.13",
"typedoc-plugin-extras": "^3.0.0",
"typedoc-plugin-rename-defaults": "^0.7.0",
"typedoc-plugin-script-inject": "^2.0.0",
"typescript": "^5.4.5"
},
"overrides": {
"vm2": "npm:vm2-fixed@0.0.1"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc