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 3.0.0-rc1 to 3.0.0-rc2

lib/version.js

403

dist/short-unique-id.js

@@ -111,25 +111,33 @@ var __suid_module =

System.register("version", [], function (exports_1, context_1) {
"use strict";
var version;
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
exports_1("default", { "version": "3.0.0-rc1" });
exports_1("version", version = "3.0.0-rc1");
}
};
"use strict";
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
exports_1("default", "3.0.0-rc2");
},
};
});
System.register("mod", ["version"], function (exports_2, context_2) {
"use strict";
var version_json_1, DEFAULT_UUID_LENGTH, DIGIT_FIRST_ASCII, DIGIT_LAST_ASCII, ALPHA_LOWER_FIRST_ASCII, ALPHA_LOWER_LAST_ASCII, ALPHA_UPPER_FIRST_ASCII, ALPHA_UPPER_LAST_ASCII, DICT_RANGES, DEFAULT_OPTIONS, ShortUniqueId;
var __moduleName = context_2 && context_2.id;
return {
setters: [
function (version_json_1_1) {
version_json_1 = version_json_1_1;
}
],
execute: function () {
/**
"use strict";
var version_ts_1,
DEFAULT_UUID_LENGTH,
DIGIT_FIRST_ASCII,
DIGIT_LAST_ASCII,
ALPHA_LOWER_FIRST_ASCII,
ALPHA_LOWER_LAST_ASCII,
ALPHA_UPPER_FIRST_ASCII,
ALPHA_UPPER_LAST_ASCII,
DICT_RANGES,
DEFAULT_OPTIONS,
ShortUniqueId;
var __moduleName = context_2 && context_2.id;
return {
setters: [
function (version_ts_1_1) {
version_ts_1 = version_ts_1_1;
},
],
execute: function () {
/**
* 6 was chosen as the default UUID length since for most cases

@@ -144,21 +152,21 @@ * it will be more than aptly suitable to provide millions of UUIDs

*/
DEFAULT_UUID_LENGTH = 6;
DIGIT_FIRST_ASCII = 48;
DIGIT_LAST_ASCII = 58;
ALPHA_LOWER_FIRST_ASCII = 97;
ALPHA_LOWER_LAST_ASCII = 123;
ALPHA_UPPER_FIRST_ASCII = 65;
ALPHA_UPPER_LAST_ASCII = 91;
DICT_RANGES = {
digits: [DIGIT_FIRST_ASCII, DIGIT_LAST_ASCII],
lowerCase: [ALPHA_LOWER_FIRST_ASCII, ALPHA_LOWER_LAST_ASCII],
upperCase: [ALPHA_UPPER_FIRST_ASCII, ALPHA_UPPER_LAST_ASCII],
};
DEFAULT_OPTIONS = {
dictionary: [],
shuffle: true,
debug: false,
length: DEFAULT_UUID_LENGTH,
};
/**
DEFAULT_UUID_LENGTH = 6;
DIGIT_FIRST_ASCII = 48;
DIGIT_LAST_ASCII = 58;
ALPHA_LOWER_FIRST_ASCII = 97;
ALPHA_LOWER_LAST_ASCII = 123;
ALPHA_UPPER_FIRST_ASCII = 65;
ALPHA_UPPER_LAST_ASCII = 91;
DICT_RANGES = {
digits: [DIGIT_FIRST_ASCII, DIGIT_LAST_ASCII],
lowerCase: [ALPHA_LOWER_FIRST_ASCII, ALPHA_LOWER_LAST_ASCII],
upperCase: [ALPHA_UPPER_FIRST_ASCII, ALPHA_UPPER_LAST_ASCII],
};
DEFAULT_OPTIONS = {
dictionary: [],
shuffle: true,
debug: false,
length: DEFAULT_UUID_LENGTH,
};
/**
* Generate random or sequential UUID of any length.

@@ -183,3 +191,3 @@ *

* // Sequential UUID
* console.log(uid.sequentialUUID());
* console.log(uid.seq());
* ```

@@ -191,3 +199,3 @@ *

* <!-- Import -->
* <script src="https://jeanlescure.github.io/short-unique-id/dist/short-unique-id.min.js"></script>
* <script src="https://cdn.jsdelivr.net/npm/short-unique-id@3.0.0-rc1/dist/short-unique-id.min.js"></script>
*

@@ -197,3 +205,2 @@ * <!-- Usage -->

* // Instantiate
* var ShortUniqueId = window['short-unique-id'].default;
* var uid = new ShortUniqueId();

@@ -205,3 +212,3 @@ *

* // Sequential UUID
* document.write(uid.sequentialUUID());
* document.write(uid.seq());
* </script>

@@ -222,123 +229,142 @@ * ```

*/
ShortUniqueId = class ShortUniqueId extends Function {
/* tslint:enable consistent-return */
constructor(argOptions = {}) {
super('...args', 'return this.randomUUID(...args)');
this.dictIndex = 0;
this.dictRange = [];
this.lowerBound = 0;
this.upperBound = 0;
this.dictLength = 0;
const options = {
...DEFAULT_OPTIONS,
...argOptions,
};
this.counter = 0;
this.debug = false;
this.dict = [];
this.version = version_json_1.version;
const { dictionary: userDict, shuffle, length, } = options;
this.uuidLength = length;
if (userDict && userDict.length > 1) {
this.setDictionary(userDict);
}
else {
let i;
this.dictIndex = i = 0;
Object.keys(DICT_RANGES).forEach((rangeType) => {
const rangeTypeKey = rangeType;
this.dictRange = DICT_RANGES[rangeTypeKey];
this.lowerBound = this.dictRange[0];
this.upperBound = this.dictRange[1];
for (this.dictIndex = i = this.lowerBound; this.lowerBound <= this.upperBound ? i < this.upperBound : i > this.upperBound; this.dictIndex = this.lowerBound <= this.upperBound ? i += 1 : i -= 1) {
this.dict.push(String.fromCharCode(this.dictIndex));
}
});
}
if (shuffle) {
// Shuffle Dictionary for removing selection bias.
const PROBABILITY = 0.5;
this.setDictionary(this.dict.sort(() => Math.random() - PROBABILITY));
}
else {
this.setDictionary(this.dict);
}
this.debug = options.debug;
this.log(this.dict);
this.log((`Generator instantiated with Dictionary Size ${this.dictLength}`));
const instance = this.bind(this);
Object.getOwnPropertyNames(this).forEach((prop) => {
if (!(/arguments|caller|callee|length|name|prototype/).test(prop)) {
const propKey = prop;
instance[prop] = this[propKey];
}
});
return instance;
}
/* tslint:disable consistent-return */
log(...args) {
const finalArgs = [...args];
finalArgs[0] = `[short-unique-id] ${args[0]}`;
/* tslint:disable no-console */
if (this.debug === true) {
if (typeof console !== 'undefined' && console !== null) {
return console.log(...finalArgs);
}
}
/* tslint:enable no-console */
}
/** Change the dictionary after initialization. */
setDictionary(dictionary) {
this.dict = dictionary;
// Cache Dictionary Length for future usage.
this.dictLength = this.dict.length; // Resets internal counter.
this.counter = 0;
}
seq() {
return this.sequentialUUID();
}
/**
ShortUniqueId = class ShortUniqueId extends Function {
/* tslint:enable consistent-return */
constructor(argOptions = {}) {
super("...args", "return this.randomUUID(...args)");
this.dictIndex = 0;
this.dictRange = [];
this.lowerBound = 0;
this.upperBound = 0;
this.dictLength = 0;
const options = {
...DEFAULT_OPTIONS,
...argOptions,
};
this.counter = 0;
this.debug = false;
this.dict = [];
this.version = version_ts_1.default;
const { dictionary: userDict, shuffle, length } = options;
this.uuidLength = length;
if (userDict && userDict.length > 1) {
this.setDictionary(userDict);
} else {
let i;
this.dictIndex = i = 0;
Object.keys(DICT_RANGES).forEach((rangeType) => {
const rangeTypeKey = rangeType;
this.dictRange = DICT_RANGES[rangeTypeKey];
this.lowerBound = this.dictRange[0];
this.upperBound = this.dictRange[1];
for (
this.dictIndex = i = this.lowerBound;
this.lowerBound <= this.upperBound
? i < this.upperBound
: i > this.upperBound;
this.dictIndex = this.lowerBound <= this.upperBound
? i += 1
: i -= 1
) {
this.dict.push(String.fromCharCode(this.dictIndex));
}
});
}
if (shuffle) {
// Shuffle Dictionary for removing selection bias.
const PROBABILITY = 0.5;
this.setDictionary(
this.dict.sort(() => Math.random() - PROBABILITY),
);
} else {
this.setDictionary(this.dict);
}
this.debug = options.debug;
this.log(this.dict);
this.log(
(`Generator instantiated with Dictionary Size ${this.dictLength}`),
);
const instance = this.bind(this);
Object.getOwnPropertyNames(this).forEach((prop) => {
if (!(/arguments|caller|callee|length|name|prototype/).test(prop)) {
const propKey = prop;
instance[prop] = this[propKey];
}
});
return instance;
}
/* tslint:disable consistent-return */
log(...args) {
const finalArgs = [...args];
finalArgs[0] = `[short-unique-id] ${args[0]}`;
/* tslint:disable no-console */
if (this.debug === true) {
if (typeof console !== "undefined" && console !== null) {
return console.log(...finalArgs);
}
}
/* tslint:enable no-console */
}
/** Change the dictionary after initialization. */
setDictionary(dictionary) {
this.dict = dictionary;
// Cache Dictionary Length for future usage.
this.dictLength = this.dict.length; // Resets internal counter.
this.counter = 0;
}
seq() {
return this.sequentialUUID();
}
/**
* Generates UUID based on internal counter that's incremented after each ID generation.
* @alias `const uid = new ShortUniqueId(); uid.seq();`
*/
sequentialUUID() {
let counterDiv;
let counterRem;
let id = '';
counterDiv = this.counter;
/* tslint:disable no-constant-condition */
while (true) {
counterRem = counterDiv % this.dictLength;
counterDiv = Math.trunc(counterDiv / this.dictLength);
id += this.dict[counterRem];
if (counterDiv === 0) {
break;
}
}
/* tslint:enable no-constant-condition */
this.counter += 1;
return id;
}
/**
sequentialUUID() {
let counterDiv;
let counterRem;
let id = "";
counterDiv = this.counter;
/* tslint:disable no-constant-condition */
while (true) {
counterRem = counterDiv % this.dictLength;
counterDiv = Math.trunc(counterDiv / this.dictLength);
id += this.dict[counterRem];
if (counterDiv === 0) {
break;
}
}
/* tslint:enable no-constant-condition */
this.counter += 1;
return id;
}
/**
* Generates UUID by creating each part randomly.
* @alias `const uid = new ShortUniqueId(); uid(uuidLength: number);`
*/
randomUUID(uuidLength = this.uuidLength || DEFAULT_UUID_LENGTH) {
let id;
let randomPartIdx;
let j;
let idIndex;
if ((uuidLength === null || typeof uuidLength === 'undefined') || uuidLength < 1) {
throw new Error('Invalid UUID Length Provided');
}
// Generate random ID parts from Dictionary.
id = '';
for (idIndex = j = 0; 0 <= uuidLength ? j < uuidLength : j > uuidLength; idIndex = 0 <= uuidLength ? j += 1 : j -= 1) {
randomPartIdx = parseInt((Math.random() * this.dictLength).toFixed(0), 10) % this.dictLength;
id += this.dict[randomPartIdx];
}
// Return random generated ID.
return id;
}
/**
randomUUID(uuidLength = this.uuidLength || DEFAULT_UUID_LENGTH) {
let id;
let randomPartIdx;
let j;
let idIndex;
if (
(uuidLength === null || typeof uuidLength === "undefined") ||
uuidLength < 1
) {
throw new Error("Invalid UUID Length Provided");
}
// Generate random ID parts from Dictionary.
id = "";
for (
idIndex = j = 0;
0 <= uuidLength ? j < uuidLength : j > uuidLength;
idIndex = 0 <= uuidLength ? j += 1 : j -= 1
) {
randomPartIdx =
parseInt((Math.random() * this.dictLength).toFixed(0), 10) %
this.dictLength;
id += this.dict[randomPartIdx];
}
// Return random generated ID.
return id;
}
/**
* Calculates total number of possible UUIDs.

@@ -358,6 +384,8 @@ *

*/
availableUUIDs(uuidLength = this.uuidLength) {
return parseFloat(Math.pow([...new Set(this.dict)].length, uuidLength).toFixed(0));
}
/**
availableUUIDs(uuidLength = this.uuidLength) {
return parseFloat(
Math.pow([...new Set(this.dict)].length, uuidLength).toFixed(0),
);
}
/**
* Calculates approximate number of hashes before first collision.

@@ -379,6 +407,8 @@ *

*/
approxMaxBeforeCollision(rounds = this.availableUUIDs(this.uuidLength)) {
return parseFloat(Math.sqrt((Math.PI / 2) * rounds).toFixed(20));
}
/**
approxMaxBeforeCollision(
rounds = this.availableUUIDs(this.uuidLength),
) {
return parseFloat(Math.sqrt((Math.PI / 2) * rounds).toFixed(20));
}
/**
* Calculates probability of generating duplicate UUIDs (a collision) in a

@@ -404,6 +434,12 @@ * given number of UUID generation rounds.

*/
collisionProbability(rounds = this.availableUUIDs(this.uuidLength), uuidLength = this.uuidLength) {
return parseFloat((this.approxMaxBeforeCollision(rounds) / this.availableUUIDs(uuidLength)).toFixed(20));
}
/**
collisionProbability(
rounds = this.availableUUIDs(this.uuidLength),
uuidLength = this.uuidLength,
) {
return parseFloat(
(this.approxMaxBeforeCollision(rounds) /
this.availableUUIDs(uuidLength)).toFixed(20),
);
}
/**
* Calculate a "uniqueness" score (from 0 to 1) of UUIDs based on size of

@@ -428,13 +464,18 @@ * dictionary and chosen UUID length.

*/
uniqueness(rounds = this.availableUUIDs(this.uuidLength)) {
const score = parseFloat((1 - (this.approxMaxBeforeCollision(rounds) / rounds)).toFixed(20));
return (score > 1) ? (1) : ((score < 0) ? 0 : score);
}
getVersion() {
return this.version;
}
};
exports_2("default", ShortUniqueId);
uniqueness(rounds = this.availableUUIDs(this.uuidLength)) {
const score = parseFloat(
(1 - (this.approxMaxBeforeCollision(rounds) / rounds)).toFixed(20),
);
return (score > 1) ? (1) : ((score < 0) ? 0 : score);
}
};
/**
* Return the version of this module.
*/
getVersion() {
return this.version;
}
};
exports_2("default", ShortUniqueId);
},
};
});

@@ -441,0 +482,0 @@

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

var __suid_module=function t(e,i,n){function s(o,u){if(!i[o]){if(!e[o]){var h="function"==typeof require&&require;if(!u&&h)return h(o,!0);if(r)return r(o,!0);var d=new Error("Cannot find module '"+o+"'");throw d.code="MODULE_NOT_FOUND",d}var c=i[o]={exports:{}};e[o][0].call(c.exports,(function(t){return s(e[o][1][t]||t)}),c,c.exports,t,e,i,n)}return i[o].exports}for(var r="function"==typeof require&&require,o=0;o<n.length;o++)s(n[o]);return s}({1:[function(t,e,i){"use strict";let n,s,r;Object.defineProperty(i,"__esModule",{value:!0}),(()=>{const e=new Map;function i(i,n){return{id:i,import:n=>async function(i,n){let s=i.replace(/\.\w+$/i,"");if(s.includes("./")){const[t,...e]=s.split("/").reverse(),[,...i]=n.split("/").reverse(),r=[t];let o,u=0;for(;o=e.shift();)if(".."===o)u++;else{if("."===o)break;r.push(o)}u<i.length&&r.push(...i.slice(u)),s=r.reverse().join("/")}return e.has(s)?h(s):Promise.resolve().then(()=>t(i))}(n,i),meta:{url:i,main:n}}}function o(t){return(e,i)=>{i="string"==typeof e?{[e]:i}:e;for(const[e,n]of Object.entries(i))Object.defineProperty(t,e,{value:n,writable:!0,enumerable:!0})}}function u(t){for(const[n,s]of e.entries()){const{f:e,exp:r}=s,{execute:u,setters:h}=e(o(r),i(n,n===t));delete s.f,s.e=u,s.s=h}}async function h(t){if(!e.has(t))return;const i=e.get(t);if(i.s){const{d:t,e:e,s:n}=i;delete i.s,delete i.e;for(let e=0;e<n.length;e++)n[e](await h(t[e]));const s=e();s&&await s}return i.exp}n={register(t,i,n){e.set(t,{d:i,f:n,exp:{}})}},s=async t=>(n=s=r=void 0,u(t),h(t)),r=t=>(n=s=r=void 0,u(t),function t(i){if(!e.has(i))return;const n=e.get(i);if(n.s){const{d:e,e:i,s:s}=n;delete n.s,delete n.e;for(let i=0;i<s.length;i++)s[i](t(e[i]));i()}return n.exp}(t))})(),n.register("version",[],(function(t,e){e&&e.id;return{setters:[],execute:function(){t("default",{version:"3.0.0-rc1"}),t("version","3.0.0-rc1")}}})),n.register("mod",["version"],(function(t,e){var i,n,s;e&&e.id;return{setters:[function(t){i=t}],execute:function(){6,48,58,97,123,65,91,n={digits:[48,58],lowerCase:[97,123],upperCase:[65,91]},s={dictionary:[],shuffle:!0,debug:!1,length:6},t("default",class extends Function{constructor(t={}){super("...args","return this.randomUUID(...args)"),this.dictIndex=0,this.dictRange=[],this.lowerBound=0,this.upperBound=0,this.dictLength=0;const e={...s,...t};this.counter=0,this.debug=!1,this.dict=[],this.version=i.version;const{dictionary:r,shuffle:o,length:u}=e;if(this.uuidLength=u,r&&r.length>1)this.setDictionary(r);else{let t;this.dictIndex=t=0,Object.keys(n).forEach(e=>{const i=e;for(this.dictRange=n[i],this.lowerBound=this.dictRange[0],this.upperBound=this.dictRange[1],this.dictIndex=t=this.lowerBound;this.lowerBound<=this.upperBound?t<this.upperBound:t>this.upperBound;this.dictIndex=this.lowerBound<=this.upperBound?t+=1:t-=1)this.dict.push(String.fromCharCode(this.dictIndex))})}if(o){const t=.5;this.setDictionary(this.dict.sort(()=>Math.random()-t))}else this.setDictionary(this.dict);this.debug=e.debug,this.log(this.dict),this.log("Generator instantiated with Dictionary Size "+this.dictLength);const h=this.bind(this);return Object.getOwnPropertyNames(this).forEach(t=>{if(!/arguments|caller|callee|length|name|prototype/.test(t)){const e=t;h[t]=this[e]}}),h}log(...t){const e=[...t];if(e[0]="[short-unique-id] "+t[0],!0===this.debug&&"undefined"!=typeof console&&null!==console)return console.log(...e)}setDictionary(t){this.dict=t,this.dictLength=this.dict.length,this.counter=0}seq(){return this.sequentialUUID()}sequentialUUID(){let t,e,i="";for(t=this.counter;e=t%this.dictLength,t=Math.trunc(t/this.dictLength),i+=this.dict[e],0!==t;);return this.counter+=1,i}randomUUID(t=this.uuidLength||6){let e,i,n,s;if(null==t||t<1)throw new Error("Invalid UUID Length Provided");for(e="",s=n=0;0<=t?n<t:n>t;s=0<=t?n+=1:n-=1)i=parseInt((Math.random()*this.dictLength).toFixed(0),10)%this.dictLength,e+=this.dict[i];return e}availableUUIDs(t=this.uuidLength){return parseFloat(Math.pow([...new Set(this.dict)].length,t).toFixed(0))}approxMaxBeforeCollision(t=this.availableUUIDs(this.uuidLength)){return parseFloat(Math.sqrt(Math.PI/2*t).toFixed(20))}collisionProbability(t=this.availableUUIDs(this.uuidLength),e=this.uuidLength){return parseFloat((this.approxMaxBeforeCollision(t)/this.availableUUIDs(e)).toFixed(20))}uniqueness(t=this.availableUUIDs(this.uuidLength)){const e=parseFloat((1-this.approxMaxBeforeCollision(t)/t).toFixed(20));return e>1?1:e<0?0:e}getVersion(){return this.version}})}}}));const o=r("mod");i.default=o.default},{}]},{},[1]),ShortUniqueId=__suid_module(1).default;
var __suid_module=function t(e,i,n){function s(o,u){if(!i[o]){if(!e[o]){var h="function"==typeof require&&require;if(!u&&h)return h(o,!0);if(r)return r(o,!0);var d=new Error("Cannot find module '"+o+"'");throw d.code="MODULE_NOT_FOUND",d}var a=i[o]={exports:{}};e[o][0].call(a.exports,(function(t){return s(e[o][1][t]||t)}),a,a.exports,t,e,i,n)}return i[o].exports}for(var r="function"==typeof require&&require,o=0;o<n.length;o++)s(n[o]);return s}({1:[function(t,e,i){"use strict";let n,s,r;Object.defineProperty(i,"__esModule",{value:!0}),(()=>{const e=new Map;function i(i,n){return{id:i,import:n=>async function(i,n){let s=i.replace(/\.\w+$/i,"");if(s.includes("./")){const[t,...e]=s.split("/").reverse(),[,...i]=n.split("/").reverse(),r=[t];let o,u=0;for(;o=e.shift();)if(".."===o)u++;else{if("."===o)break;r.push(o)}u<i.length&&r.push(...i.slice(u)),s=r.reverse().join("/")}return e.has(s)?h(s):Promise.resolve().then(()=>t(i))}(n,i),meta:{url:i,main:n}}}function o(t){return(e,i)=>{i="string"==typeof e?{[e]:i}:e;for(const[e,n]of Object.entries(i))Object.defineProperty(t,e,{value:n,writable:!0,enumerable:!0})}}function u(t){for(const[n,s]of e.entries()){const{f:e,exp:r}=s,{execute:u,setters:h}=e(o(r),i(n,n===t));delete s.f,s.e=u,s.s=h}}async function h(t){if(!e.has(t))return;const i=e.get(t);if(i.s){const{d:t,e:e,s:n}=i;delete i.s,delete i.e;for(let e=0;e<n.length;e++)n[e](await h(t[e]));const s=e();s&&await s}return i.exp}n={register(t,i,n){e.set(t,{d:i,f:n,exp:{}})}},s=async t=>(n=s=r=void 0,u(t),h(t)),r=t=>(n=s=r=void 0,u(t),function t(i){if(!e.has(i))return;const n=e.get(i);if(n.s){const{d:e,e:i,s:s}=n;delete n.s,delete n.e;for(let i=0;i<s.length;i++)s[i](t(e[i]));i()}return n.exp}(t))})(),n.register("version",[],(function(t,e){e&&e.id;return{setters:[],execute:function(){t("default","3.0.0-rc2")}}})),n.register("mod",["version"],(function(t,e){var i,n,s;e&&e.id;return{setters:[function(t){i=t}],execute:function(){6,48,58,97,123,65,91,n={digits:[48,58],lowerCase:[97,123],upperCase:[65,91]},s={dictionary:[],shuffle:!0,debug:!1,length:6},t("default",class extends Function{constructor(t={}){super("...args","return this.randomUUID(...args)"),this.dictIndex=0,this.dictRange=[],this.lowerBound=0,this.upperBound=0,this.dictLength=0;const e={...s,...t};this.counter=0,this.debug=!1,this.dict=[],this.version=i.default;const{dictionary:r,shuffle:o,length:u}=e;if(this.uuidLength=u,r&&r.length>1)this.setDictionary(r);else{let t;this.dictIndex=t=0,Object.keys(n).forEach(e=>{const i=e;for(this.dictRange=n[i],this.lowerBound=this.dictRange[0],this.upperBound=this.dictRange[1],this.dictIndex=t=this.lowerBound;this.lowerBound<=this.upperBound?t<this.upperBound:t>this.upperBound;this.dictIndex=this.lowerBound<=this.upperBound?t+=1:t-=1)this.dict.push(String.fromCharCode(this.dictIndex))})}if(o){const t=.5;this.setDictionary(this.dict.sort(()=>Math.random()-t))}else this.setDictionary(this.dict);this.debug=e.debug,this.log(this.dict),this.log("Generator instantiated with Dictionary Size "+this.dictLength);const h=this.bind(this);return Object.getOwnPropertyNames(this).forEach(t=>{if(!/arguments|caller|callee|length|name|prototype/.test(t)){const e=t;h[t]=this[e]}}),h}log(...t){const e=[...t];if(e[0]="[short-unique-id] "+t[0],!0===this.debug&&"undefined"!=typeof console&&null!==console)return console.log(...e)}setDictionary(t){this.dict=t,this.dictLength=this.dict.length,this.counter=0}seq(){return this.sequentialUUID()}sequentialUUID(){let t,e,i="";for(t=this.counter;e=t%this.dictLength,t=Math.trunc(t/this.dictLength),i+=this.dict[e],0!==t;);return this.counter+=1,i}randomUUID(t=this.uuidLength||6){let e,i,n,s;if(null==t||t<1)throw new Error("Invalid UUID Length Provided");for(e="",s=n=0;0<=t?n<t:n>t;s=0<=t?n+=1:n-=1)i=parseInt((Math.random()*this.dictLength).toFixed(0),10)%this.dictLength,e+=this.dict[i];return e}availableUUIDs(t=this.uuidLength){return parseFloat(Math.pow([...new Set(this.dict)].length,t).toFixed(0))}approxMaxBeforeCollision(t=this.availableUUIDs(this.uuidLength)){return parseFloat(Math.sqrt(Math.PI/2*t).toFixed(20))}collisionProbability(t=this.availableUUIDs(this.uuidLength),e=this.uuidLength){return parseFloat((this.approxMaxBeforeCollision(t)/this.availableUUIDs(e)).toFixed(20))}uniqueness(t=this.availableUUIDs(this.uuidLength)){const e=parseFloat((1-this.approxMaxBeforeCollision(t)/t).toFixed(20));return e>1?1:e<0?0:e}getVersion(){return this.version}})}}}));const o=r("mod");i.default=o.default},{}]},{},[1]),ShortUniqueId=__suid_module(1).default;

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

{"kinds":{"32":"Variable","128":"Class","2048":"Method","65536":"Type literal","4194304":"Type alias"},"rows":[{"id":0,"kind":128,"name":"ShortUniqueId","url":"classes/shortuniqueid.html","classes":"tsd-kind-class"},{"id":1,"kind":2048,"name":"setDictionary","url":"classes/shortuniqueid.html#setdictionary","classes":"tsd-kind-method tsd-parent-kind-class","parent":"ShortUniqueId"},{"id":2,"kind":2048,"name":"sequentialUUID","url":"classes/shortuniqueid.html#sequentialuuid","classes":"tsd-kind-method tsd-parent-kind-class","parent":"ShortUniqueId"},{"id":3,"kind":2048,"name":"randomUUID","url":"classes/shortuniqueid.html#randomuuid","classes":"tsd-kind-method tsd-parent-kind-class","parent":"ShortUniqueId"},{"id":4,"kind":2048,"name":"availableUUIDs","url":"classes/shortuniqueid.html#availableuuids","classes":"tsd-kind-method tsd-parent-kind-class","parent":"ShortUniqueId"},{"id":5,"kind":2048,"name":"approxMaxBeforeCollision","url":"classes/shortuniqueid.html#approxmaxbeforecollision","classes":"tsd-kind-method tsd-parent-kind-class","parent":"ShortUniqueId"},{"id":6,"kind":2048,"name":"collisionProbability","url":"classes/shortuniqueid.html#collisionprobability","classes":"tsd-kind-method tsd-parent-kind-class","parent":"ShortUniqueId"},{"id":7,"kind":2048,"name":"uniqueness","url":"classes/shortuniqueid.html#uniqueness","classes":"tsd-kind-method tsd-parent-kind-class","parent":"ShortUniqueId"},{"id":8,"kind":2048,"name":"apply","url":"classes/shortuniqueid.html#apply","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-inherited","parent":"ShortUniqueId"},{"id":9,"kind":2048,"name":"call","url":"classes/shortuniqueid.html#call","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-inherited","parent":"ShortUniqueId"},{"id":10,"kind":2048,"name":"bind","url":"classes/shortuniqueid.html#bind","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-inherited","parent":"ShortUniqueId"},{"id":11,"kind":2048,"name":"toString","url":"classes/shortuniqueid.html#tostring","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-inherited","parent":"ShortUniqueId"},{"id":12,"kind":4194304,"name":"Options","url":"globals.html#options","classes":"tsd-kind-type-alias"},{"id":13,"kind":65536,"name":"__type","url":"globals.html#options.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias","parent":"Options"},{"id":14,"kind":32,"name":"dictionary","url":"globals.html#options.__type.dictionary","classes":"tsd-kind-variable tsd-parent-kind-type-literal","parent":"Options.__type"},{"id":15,"kind":32,"name":"shuffle","url":"globals.html#options.__type.shuffle","classes":"tsd-kind-variable tsd-parent-kind-type-literal","parent":"Options.__type"},{"id":16,"kind":32,"name":"debug","url":"globals.html#options.__type.debug","classes":"tsd-kind-variable tsd-parent-kind-type-literal","parent":"Options.__type"},{"id":17,"kind":32,"name":"length","url":"globals.html#options.__type.length","classes":"tsd-kind-variable tsd-parent-kind-type-literal","parent":"Options.__type"},{"id":18,"kind":32,"name":"DEFAULT_UUID_LENGTH","url":"globals.html#default_uuid_length","classes":"tsd-kind-variable"}],"index":{"version":"2.3.8","fields":["name","parent"],"fieldVectors":[["name/0",[0,4.7]],["parent/0",[]],["name/1",[1,25.903]],["parent/1",[0,0.437]],["name/2",[2,25.903]],["parent/2",[0,0.437]],["name/3",[3,25.903]],["parent/3",[0,0.437]],["name/4",[4,25.903]],["parent/4",[0,0.437]],["name/5",[5,25.903]],["parent/5",[0,0.437]],["name/6",[6,25.903]],["parent/6",[0,0.437]],["name/7",[7,25.903]],["parent/7",[0,0.437]],["name/8",[8,25.903]],["parent/8",[0,0.437]],["name/9",[9,25.903]],["parent/9",[0,0.437]],["name/10",[10,25.903]],["parent/10",[0,0.437]],["name/11",[11,25.903]],["parent/11",[0,0.437]],["name/12",[12,20.794]],["parent/12",[]],["name/13",[13,25.903]],["parent/13",[12,1.931]],["name/14",[14,25.903]],["parent/14",[15,1.385]],["name/15",[16,25.903]],["parent/15",[15,1.385]],["name/16",[17,25.903]],["parent/16",[15,1.385]],["name/17",[18,25.903]],["parent/17",[15,1.385]],["name/18",[19,25.903]],["parent/18",[]]],"invertedIndex":[["__type",{"_index":13,"name":{"13":{}},"parent":{}}],["apply",{"_index":8,"name":{"8":{}},"parent":{}}],["approxmaxbeforecollision",{"_index":5,"name":{"5":{}},"parent":{}}],["availableuuids",{"_index":4,"name":{"4":{}},"parent":{}}],["bind",{"_index":10,"name":{"10":{}},"parent":{}}],["call",{"_index":9,"name":{"9":{}},"parent":{}}],["collisionprobability",{"_index":6,"name":{"6":{}},"parent":{}}],["debug",{"_index":17,"name":{"16":{}},"parent":{}}],["default_uuid_length",{"_index":19,"name":{"18":{}},"parent":{}}],["dictionary",{"_index":14,"name":{"14":{}},"parent":{}}],["length",{"_index":18,"name":{"17":{}},"parent":{}}],["options",{"_index":12,"name":{"12":{}},"parent":{"13":{}}}],["options.__type",{"_index":15,"name":{},"parent":{"14":{},"15":{},"16":{},"17":{}}}],["randomuuid",{"_index":3,"name":{"3":{}},"parent":{}}],["sequentialuuid",{"_index":2,"name":{"2":{}},"parent":{}}],["setdictionary",{"_index":1,"name":{"1":{}},"parent":{}}],["shortuniqueid",{"_index":0,"name":{"0":{}},"parent":{"1":{},"2":{},"3":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{},"10":{},"11":{}}}],["shuffle",{"_index":16,"name":{"15":{}},"parent":{}}],["tostring",{"_index":11,"name":{"11":{}},"parent":{}}],["uniqueness",{"_index":7,"name":{"7":{}},"parent":{}}]],"pipeline":[]}}
{"kinds":{"32":"Variable","128":"Class","2048":"Method","65536":"Type literal","4194304":"Type alias"},"rows":[{"id":0,"kind":128,"name":"ShortUniqueId","url":"classes/shortuniqueid.html","classes":"tsd-kind-class"},{"id":1,"kind":2048,"name":"setDictionary","url":"classes/shortuniqueid.html#setdictionary","classes":"tsd-kind-method tsd-parent-kind-class","parent":"ShortUniqueId"},{"id":2,"kind":2048,"name":"sequentialUUID","url":"classes/shortuniqueid.html#sequentialuuid","classes":"tsd-kind-method tsd-parent-kind-class","parent":"ShortUniqueId"},{"id":3,"kind":2048,"name":"randomUUID","url":"classes/shortuniqueid.html#randomuuid","classes":"tsd-kind-method tsd-parent-kind-class","parent":"ShortUniqueId"},{"id":4,"kind":2048,"name":"availableUUIDs","url":"classes/shortuniqueid.html#availableuuids","classes":"tsd-kind-method tsd-parent-kind-class","parent":"ShortUniqueId"},{"id":5,"kind":2048,"name":"approxMaxBeforeCollision","url":"classes/shortuniqueid.html#approxmaxbeforecollision","classes":"tsd-kind-method tsd-parent-kind-class","parent":"ShortUniqueId"},{"id":6,"kind":2048,"name":"collisionProbability","url":"classes/shortuniqueid.html#collisionprobability","classes":"tsd-kind-method tsd-parent-kind-class","parent":"ShortUniqueId"},{"id":7,"kind":2048,"name":"uniqueness","url":"classes/shortuniqueid.html#uniqueness","classes":"tsd-kind-method tsd-parent-kind-class","parent":"ShortUniqueId"},{"id":8,"kind":2048,"name":"getVersion","url":"classes/shortuniqueid.html#getversion","classes":"tsd-kind-method tsd-parent-kind-class","parent":"ShortUniqueId"},{"id":9,"kind":2048,"name":"apply","url":"classes/shortuniqueid.html#apply","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-inherited","parent":"ShortUniqueId"},{"id":10,"kind":2048,"name":"call","url":"classes/shortuniqueid.html#call","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-inherited","parent":"ShortUniqueId"},{"id":11,"kind":2048,"name":"bind","url":"classes/shortuniqueid.html#bind","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-inherited","parent":"ShortUniqueId"},{"id":12,"kind":2048,"name":"toString","url":"classes/shortuniqueid.html#tostring","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-inherited","parent":"ShortUniqueId"},{"id":13,"kind":4194304,"name":"Options","url":"globals.html#options","classes":"tsd-kind-type-alias"},{"id":14,"kind":65536,"name":"__type","url":"globals.html#options.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias","parent":"Options"},{"id":15,"kind":32,"name":"dictionary","url":"globals.html#options.__type.dictionary","classes":"tsd-kind-variable tsd-parent-kind-type-literal","parent":"Options.__type"},{"id":16,"kind":32,"name":"shuffle","url":"globals.html#options.__type.shuffle","classes":"tsd-kind-variable tsd-parent-kind-type-literal","parent":"Options.__type"},{"id":17,"kind":32,"name":"debug","url":"globals.html#options.__type.debug","classes":"tsd-kind-variable tsd-parent-kind-type-literal","parent":"Options.__type"},{"id":18,"kind":32,"name":"length","url":"globals.html#options.__type.length","classes":"tsd-kind-variable tsd-parent-kind-type-literal","parent":"Options.__type"},{"id":19,"kind":32,"name":"DEFAULT_UUID_LENGTH","url":"globals.html#default_uuid_length","classes":"tsd-kind-variable"}],"index":{"version":"2.3.8","fields":["name","parent"],"fieldVectors":[["name/0",[0,4.418]],["parent/0",[]],["name/1",[1,26.391]],["parent/1",[0,0.412]],["name/2",[2,26.391]],["parent/2",[0,0.412]],["name/3",[3,26.391]],["parent/3",[0,0.412]],["name/4",[4,26.391]],["parent/4",[0,0.412]],["name/5",[5,26.391]],["parent/5",[0,0.412]],["name/6",[6,26.391]],["parent/6",[0,0.412]],["name/7",[7,26.391]],["parent/7",[0,0.412]],["name/8",[8,26.391]],["parent/8",[0,0.412]],["name/9",[9,26.391]],["parent/9",[0,0.412]],["name/10",[10,26.391]],["parent/10",[0,0.412]],["name/11",[11,26.391]],["parent/11",[0,0.412]],["name/12",[12,26.391]],["parent/12",[0,0.412]],["name/13",[13,21.282]],["parent/13",[]],["name/14",[14,26.391]],["parent/14",[13,1.985]],["name/15",[15,26.391]],["parent/15",[16,1.437]],["name/16",[17,26.391]],["parent/16",[16,1.437]],["name/17",[18,26.391]],["parent/17",[16,1.437]],["name/18",[19,26.391]],["parent/18",[16,1.437]],["name/19",[20,26.391]],["parent/19",[]]],"invertedIndex":[["__type",{"_index":14,"name":{"14":{}},"parent":{}}],["apply",{"_index":9,"name":{"9":{}},"parent":{}}],["approxmaxbeforecollision",{"_index":5,"name":{"5":{}},"parent":{}}],["availableuuids",{"_index":4,"name":{"4":{}},"parent":{}}],["bind",{"_index":11,"name":{"11":{}},"parent":{}}],["call",{"_index":10,"name":{"10":{}},"parent":{}}],["collisionprobability",{"_index":6,"name":{"6":{}},"parent":{}}],["debug",{"_index":18,"name":{"17":{}},"parent":{}}],["default_uuid_length",{"_index":20,"name":{"19":{}},"parent":{}}],["dictionary",{"_index":15,"name":{"15":{}},"parent":{}}],["getversion",{"_index":8,"name":{"8":{}},"parent":{}}],["length",{"_index":19,"name":{"18":{}},"parent":{}}],["options",{"_index":13,"name":{"13":{}},"parent":{"14":{}}}],["options.__type",{"_index":16,"name":{},"parent":{"15":{},"16":{},"17":{},"18":{}}}],["randomuuid",{"_index":3,"name":{"3":{}},"parent":{}}],["sequentialuuid",{"_index":2,"name":{"2":{}},"parent":{}}],["setdictionary",{"_index":1,"name":{"1":{}},"parent":{}}],["shortuniqueid",{"_index":0,"name":{"0":{}},"parent":{"1":{},"2":{},"3":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{},"10":{},"11":{},"12":{}}}],["shuffle",{"_index":17,"name":{"16":{}},"parent":{}}],["tostring",{"_index":12,"name":{"12":{}},"parent":{}}],["uniqueness",{"_index":7,"name":{"7":{}},"parent":{}}]],"pipeline":[]}}

@@ -109,25 +109,33 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

System.register("version", [], function (exports_1, context_1) {
"use strict";
var version;
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
exports_1("default", { "version": "3.0.0-rc1" });
exports_1("version", version = "3.0.0-rc1");
}
};
"use strict";
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
exports_1("default", "3.0.0-rc2");
},
};
});
System.register("mod", ["version"], function (exports_2, context_2) {
"use strict";
var version_json_1, DEFAULT_UUID_LENGTH, DIGIT_FIRST_ASCII, DIGIT_LAST_ASCII, ALPHA_LOWER_FIRST_ASCII, ALPHA_LOWER_LAST_ASCII, ALPHA_UPPER_FIRST_ASCII, ALPHA_UPPER_LAST_ASCII, DICT_RANGES, DEFAULT_OPTIONS, ShortUniqueId;
var __moduleName = context_2 && context_2.id;
return {
setters: [
function (version_json_1_1) {
version_json_1 = version_json_1_1;
}
],
execute: function () {
/**
"use strict";
var version_ts_1,
DEFAULT_UUID_LENGTH,
DIGIT_FIRST_ASCII,
DIGIT_LAST_ASCII,
ALPHA_LOWER_FIRST_ASCII,
ALPHA_LOWER_LAST_ASCII,
ALPHA_UPPER_FIRST_ASCII,
ALPHA_UPPER_LAST_ASCII,
DICT_RANGES,
DEFAULT_OPTIONS,
ShortUniqueId;
var __moduleName = context_2 && context_2.id;
return {
setters: [
function (version_ts_1_1) {
version_ts_1 = version_ts_1_1;
},
],
execute: function () {
/**
* 6 was chosen as the default UUID length since for most cases

@@ -142,21 +150,21 @@ * it will be more than aptly suitable to provide millions of UUIDs

*/
DEFAULT_UUID_LENGTH = 6;
DIGIT_FIRST_ASCII = 48;
DIGIT_LAST_ASCII = 58;
ALPHA_LOWER_FIRST_ASCII = 97;
ALPHA_LOWER_LAST_ASCII = 123;
ALPHA_UPPER_FIRST_ASCII = 65;
ALPHA_UPPER_LAST_ASCII = 91;
DICT_RANGES = {
digits: [DIGIT_FIRST_ASCII, DIGIT_LAST_ASCII],
lowerCase: [ALPHA_LOWER_FIRST_ASCII, ALPHA_LOWER_LAST_ASCII],
upperCase: [ALPHA_UPPER_FIRST_ASCII, ALPHA_UPPER_LAST_ASCII],
};
DEFAULT_OPTIONS = {
dictionary: [],
shuffle: true,
debug: false,
length: DEFAULT_UUID_LENGTH,
};
/**
DEFAULT_UUID_LENGTH = 6;
DIGIT_FIRST_ASCII = 48;
DIGIT_LAST_ASCII = 58;
ALPHA_LOWER_FIRST_ASCII = 97;
ALPHA_LOWER_LAST_ASCII = 123;
ALPHA_UPPER_FIRST_ASCII = 65;
ALPHA_UPPER_LAST_ASCII = 91;
DICT_RANGES = {
digits: [DIGIT_FIRST_ASCII, DIGIT_LAST_ASCII],
lowerCase: [ALPHA_LOWER_FIRST_ASCII, ALPHA_LOWER_LAST_ASCII],
upperCase: [ALPHA_UPPER_FIRST_ASCII, ALPHA_UPPER_LAST_ASCII],
};
DEFAULT_OPTIONS = {
dictionary: [],
shuffle: true,
debug: false,
length: DEFAULT_UUID_LENGTH,
};
/**
* Generate random or sequential UUID of any length.

@@ -181,3 +189,3 @@ *

* // Sequential UUID
* console.log(uid.sequentialUUID());
* console.log(uid.seq());
* ```

@@ -189,3 +197,3 @@ *

* <!-- Import -->
* <script src="https://jeanlescure.github.io/short-unique-id/dist/short-unique-id.min.js"></script>
* <script src="https://cdn.jsdelivr.net/npm/short-unique-id@3.0.0-rc1/dist/short-unique-id.min.js"></script>
*

@@ -195,3 +203,2 @@ * <!-- Usage -->

* // Instantiate
* var ShortUniqueId = window['short-unique-id'].default;
* var uid = new ShortUniqueId();

@@ -203,3 +210,3 @@ *

* // Sequential UUID
* document.write(uid.sequentialUUID());
* document.write(uid.seq());
* </script>

@@ -220,123 +227,142 @@ * ```

*/
ShortUniqueId = class ShortUniqueId extends Function {
/* tslint:enable consistent-return */
constructor(argOptions = {}) {
super('...args', 'return this.randomUUID(...args)');
this.dictIndex = 0;
this.dictRange = [];
this.lowerBound = 0;
this.upperBound = 0;
this.dictLength = 0;
const options = {
...DEFAULT_OPTIONS,
...argOptions,
};
this.counter = 0;
this.debug = false;
this.dict = [];
this.version = version_json_1.version;
const { dictionary: userDict, shuffle, length, } = options;
this.uuidLength = length;
if (userDict && userDict.length > 1) {
this.setDictionary(userDict);
}
else {
let i;
this.dictIndex = i = 0;
Object.keys(DICT_RANGES).forEach((rangeType) => {
const rangeTypeKey = rangeType;
this.dictRange = DICT_RANGES[rangeTypeKey];
this.lowerBound = this.dictRange[0];
this.upperBound = this.dictRange[1];
for (this.dictIndex = i = this.lowerBound; this.lowerBound <= this.upperBound ? i < this.upperBound : i > this.upperBound; this.dictIndex = this.lowerBound <= this.upperBound ? i += 1 : i -= 1) {
this.dict.push(String.fromCharCode(this.dictIndex));
}
});
}
if (shuffle) {
// Shuffle Dictionary for removing selection bias.
const PROBABILITY = 0.5;
this.setDictionary(this.dict.sort(() => Math.random() - PROBABILITY));
}
else {
this.setDictionary(this.dict);
}
this.debug = options.debug;
this.log(this.dict);
this.log((`Generator instantiated with Dictionary Size ${this.dictLength}`));
const instance = this.bind(this);
Object.getOwnPropertyNames(this).forEach((prop) => {
if (!(/arguments|caller|callee|length|name|prototype/).test(prop)) {
const propKey = prop;
instance[prop] = this[propKey];
}
});
return instance;
}
/* tslint:disable consistent-return */
log(...args) {
const finalArgs = [...args];
finalArgs[0] = `[short-unique-id] ${args[0]}`;
/* tslint:disable no-console */
if (this.debug === true) {
if (typeof console !== 'undefined' && console !== null) {
return console.log(...finalArgs);
}
}
/* tslint:enable no-console */
}
/** Change the dictionary after initialization. */
setDictionary(dictionary) {
this.dict = dictionary;
// Cache Dictionary Length for future usage.
this.dictLength = this.dict.length; // Resets internal counter.
this.counter = 0;
}
seq() {
return this.sequentialUUID();
}
/**
ShortUniqueId = class ShortUniqueId extends Function {
/* tslint:enable consistent-return */
constructor(argOptions = {}) {
super("...args", "return this.randomUUID(...args)");
this.dictIndex = 0;
this.dictRange = [];
this.lowerBound = 0;
this.upperBound = 0;
this.dictLength = 0;
const options = {
...DEFAULT_OPTIONS,
...argOptions,
};
this.counter = 0;
this.debug = false;
this.dict = [];
this.version = version_ts_1.default;
const { dictionary: userDict, shuffle, length } = options;
this.uuidLength = length;
if (userDict && userDict.length > 1) {
this.setDictionary(userDict);
} else {
let i;
this.dictIndex = i = 0;
Object.keys(DICT_RANGES).forEach((rangeType) => {
const rangeTypeKey = rangeType;
this.dictRange = DICT_RANGES[rangeTypeKey];
this.lowerBound = this.dictRange[0];
this.upperBound = this.dictRange[1];
for (
this.dictIndex = i = this.lowerBound;
this.lowerBound <= this.upperBound
? i < this.upperBound
: i > this.upperBound;
this.dictIndex = this.lowerBound <= this.upperBound
? i += 1
: i -= 1
) {
this.dict.push(String.fromCharCode(this.dictIndex));
}
});
}
if (shuffle) {
// Shuffle Dictionary for removing selection bias.
const PROBABILITY = 0.5;
this.setDictionary(
this.dict.sort(() => Math.random() - PROBABILITY),
);
} else {
this.setDictionary(this.dict);
}
this.debug = options.debug;
this.log(this.dict);
this.log(
(`Generator instantiated with Dictionary Size ${this.dictLength}`),
);
const instance = this.bind(this);
Object.getOwnPropertyNames(this).forEach((prop) => {
if (!(/arguments|caller|callee|length|name|prototype/).test(prop)) {
const propKey = prop;
instance[prop] = this[propKey];
}
});
return instance;
}
/* tslint:disable consistent-return */
log(...args) {
const finalArgs = [...args];
finalArgs[0] = `[short-unique-id] ${args[0]}`;
/* tslint:disable no-console */
if (this.debug === true) {
if (typeof console !== "undefined" && console !== null) {
return console.log(...finalArgs);
}
}
/* tslint:enable no-console */
}
/** Change the dictionary after initialization. */
setDictionary(dictionary) {
this.dict = dictionary;
// Cache Dictionary Length for future usage.
this.dictLength = this.dict.length; // Resets internal counter.
this.counter = 0;
}
seq() {
return this.sequentialUUID();
}
/**
* Generates UUID based on internal counter that's incremented after each ID generation.
* @alias `const uid = new ShortUniqueId(); uid.seq();`
*/
sequentialUUID() {
let counterDiv;
let counterRem;
let id = '';
counterDiv = this.counter;
/* tslint:disable no-constant-condition */
while (true) {
counterRem = counterDiv % this.dictLength;
counterDiv = Math.trunc(counterDiv / this.dictLength);
id += this.dict[counterRem];
if (counterDiv === 0) {
break;
}
}
/* tslint:enable no-constant-condition */
this.counter += 1;
return id;
}
/**
sequentialUUID() {
let counterDiv;
let counterRem;
let id = "";
counterDiv = this.counter;
/* tslint:disable no-constant-condition */
while (true) {
counterRem = counterDiv % this.dictLength;
counterDiv = Math.trunc(counterDiv / this.dictLength);
id += this.dict[counterRem];
if (counterDiv === 0) {
break;
}
}
/* tslint:enable no-constant-condition */
this.counter += 1;
return id;
}
/**
* Generates UUID by creating each part randomly.
* @alias `const uid = new ShortUniqueId(); uid(uuidLength: number);`
*/
randomUUID(uuidLength = this.uuidLength || DEFAULT_UUID_LENGTH) {
let id;
let randomPartIdx;
let j;
let idIndex;
if ((uuidLength === null || typeof uuidLength === 'undefined') || uuidLength < 1) {
throw new Error('Invalid UUID Length Provided');
}
// Generate random ID parts from Dictionary.
id = '';
for (idIndex = j = 0; 0 <= uuidLength ? j < uuidLength : j > uuidLength; idIndex = 0 <= uuidLength ? j += 1 : j -= 1) {
randomPartIdx = parseInt((Math.random() * this.dictLength).toFixed(0), 10) % this.dictLength;
id += this.dict[randomPartIdx];
}
// Return random generated ID.
return id;
}
/**
randomUUID(uuidLength = this.uuidLength || DEFAULT_UUID_LENGTH) {
let id;
let randomPartIdx;
let j;
let idIndex;
if (
(uuidLength === null || typeof uuidLength === "undefined") ||
uuidLength < 1
) {
throw new Error("Invalid UUID Length Provided");
}
// Generate random ID parts from Dictionary.
id = "";
for (
idIndex = j = 0;
0 <= uuidLength ? j < uuidLength : j > uuidLength;
idIndex = 0 <= uuidLength ? j += 1 : j -= 1
) {
randomPartIdx =
parseInt((Math.random() * this.dictLength).toFixed(0), 10) %
this.dictLength;
id += this.dict[randomPartIdx];
}
// Return random generated ID.
return id;
}
/**
* Calculates total number of possible UUIDs.

@@ -356,6 +382,8 @@ *

*/
availableUUIDs(uuidLength = this.uuidLength) {
return parseFloat(Math.pow([...new Set(this.dict)].length, uuidLength).toFixed(0));
}
/**
availableUUIDs(uuidLength = this.uuidLength) {
return parseFloat(
Math.pow([...new Set(this.dict)].length, uuidLength).toFixed(0),
);
}
/**
* Calculates approximate number of hashes before first collision.

@@ -377,6 +405,8 @@ *

*/
approxMaxBeforeCollision(rounds = this.availableUUIDs(this.uuidLength)) {
return parseFloat(Math.sqrt((Math.PI / 2) * rounds).toFixed(20));
}
/**
approxMaxBeforeCollision(
rounds = this.availableUUIDs(this.uuidLength),
) {
return parseFloat(Math.sqrt((Math.PI / 2) * rounds).toFixed(20));
}
/**
* Calculates probability of generating duplicate UUIDs (a collision) in a

@@ -402,6 +432,12 @@ * given number of UUID generation rounds.

*/
collisionProbability(rounds = this.availableUUIDs(this.uuidLength), uuidLength = this.uuidLength) {
return parseFloat((this.approxMaxBeforeCollision(rounds) / this.availableUUIDs(uuidLength)).toFixed(20));
}
/**
collisionProbability(
rounds = this.availableUUIDs(this.uuidLength),
uuidLength = this.uuidLength,
) {
return parseFloat(
(this.approxMaxBeforeCollision(rounds) /
this.availableUUIDs(uuidLength)).toFixed(20),
);
}
/**
* Calculate a "uniqueness" score (from 0 to 1) of UUIDs based on size of

@@ -426,13 +462,18 @@ * dictionary and chosen UUID length.

*/
uniqueness(rounds = this.availableUUIDs(this.uuidLength)) {
const score = parseFloat((1 - (this.approxMaxBeforeCollision(rounds) / rounds)).toFixed(20));
return (score > 1) ? (1) : ((score < 0) ? 0 : score);
}
getVersion() {
return this.version;
}
};
exports_2("default", ShortUniqueId);
uniqueness(rounds = this.availableUUIDs(this.uuidLength)) {
const score = parseFloat(
(1 - (this.approxMaxBeforeCollision(rounds) / rounds)).toFixed(20),
);
return (score > 1) ? (1) : ((score < 0) ? 0 : score);
}
};
/**
* Return the version of this module.
*/
getVersion() {
return this.version;
}
};
exports_2("default", ShortUniqueId);
},
};
});

@@ -439,0 +480,0 @@

{
"name": "short-unique-id",
"version": "3.0.0-rc1",
"version": "3.0.0-rc2",
"description": "Generate random or sequential UUID of any length",

@@ -24,5 +24,5 @@ "keywords": [

"scripts": {
"gen:version": "echo \"{\\\"version\\\": `jq .version package.json`}\" > short_uuid/version.json",
"gen:version": "echo \"export default '`jq -r .version package.json`';\" > short_uuid/version.ts",
"gen:docs": "cd short_uuid && typedoc --readme ../README.md --theme ../node_modules/short_uuid_typedoc_template/bin/default --out ../docs . && cd .. && cp -r ./assets ./docs && mv ./docs/assets/favicon.ico ./docs/ && echo shortunique.id > ./docs/CNAME",
"lib:build": "yarn gen:version && rm ./lib/* ; mkdir -p tmp && cd short_uuid && deno bundle mod.ts ../tmp/mod.js && cd .. && sucrase ./tmp -d ./lib -t imports && mv ./lib/mod.js ./lib/short-unique-id.js && cp short_uuid/version.json ./lib && rm -rf ./tmp",
"lib:build": "yarn gen:version && rm ./lib/* ; mkdir -p tmp && cd short_uuid && deno bundle mod.ts ../tmp/mod.js && deno bundle version.ts ../tmp/version.js && cd .. && sucrase ./tmp -d ./lib -t imports && mv ./lib/mod.js ./lib/short-unique-id.js && rm -rf ./tmp",
"dist:build": "yarn lib:build && rm ./dist/* ; echo 'var __suid_module = ' > ./dist/short-unique-id.js && browserify ./lib/short-unique-id.js >> ./dist/short-unique-id.js && echo 'var ShortUniqueId = __suid_module(1)[\"default\"];' >> ./dist/short-unique-id.js && minify ./dist/short-unique-id.js > ./dist/short-unique-id.min.js",

@@ -35,3 +35,3 @@ "test": "yarn gen:version && cd short_uuid && deno test && cd .. && yarn link && yarn link short-unique-id && node ./runkit.js",

"minify": "^5.1.1",
"short_uuid_typedoc_template": "^1.0.5",
"short_uuid_typedoc_template": "^1.0.8",
"sucrase": "^3.13.0",

@@ -38,0 +38,0 @@ "tslint": "^6.1.1",

# Short Unique ID (UUID) Generating Library
![CD](https://github.com/jeanlescure/short-unique-id/workflows/CD/badge.svg)
[![Try short-unique-id on RunKit](https://badge.runkitcdn.com/short-unique-id.svg)](https://npm.runkit.com/short-unique-id)
[![NPM Downloads](https://img.shields.io/npm/dt/short-unique-id.svg?maxAge=2592000)](https://npmjs.com/package/short-unique-id)
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

@@ -6,5 +10,2 @@ [![3 Contributors](https://img.shields.io/badge/all_contributors-3-purple.svg?style=flat-square)](#contributors)

[![Try short-unique-id on RunKit](https://badge.runkitcdn.com/short-unique-id.svg)](https://npm.runkit.com/short-unique-id)
[![NPM Downloads](https://img.shields.io/npm/dt/short-unique-id.svg?maxAge=2592000)](https://npmjs.com/package/short-unique-id)
## Documentation and Online Short UUID Generator

@@ -114,12 +115,12 @@

<tr>
<td align="center"><a href="https://github.com/serendipious"><img src="assets/contributors/serendipious.svg" /></a><table><tbody><tr><td width="150" align="center"><a href="https://github.com/jeanlescure/short-unique-id/commits?author=serendipious" title="Code">💻</a></td></tr></tbody></table></td>
<td align="center"><a href="https://jeanlescure.cr"><img src="assets/contributors/jeanlescure.svg" /></a><table><tbody><tr><td width="150" align="center"><a href="#maintenance-jeanlescure" title="Maintenance">🚧</a> <a href="https://github.com/jeanlescure/short-unique-id/commits?author=jeanlescure" title="Code">💻</a> <a href="#content-jeanlescure" title="Content">🖋</a> <a href="https://github.com/jeanlescure/short-unique-id/commits?author=jeanlescure" title="Documentation">📖</a> <a href="https://github.com/jeanlescure/short-unique-id/commits?author=jeanlescure" title="Tests">⚠️</a></td></tr></tbody></table></td>
<td align="center"><a href="https://dianalu.design"><img src="assets/contributors/dilescure.svg" /></a><table><tbody><tr><td width="150" align="center"><a href="https://github.com/jeanlescure/short_uuid/commits?author=DiLescure" title="Code">💻</a></td></tr></tbody></table></td>
<td align="center"><a href="https://github.com/EmerLM"><img src="assets/contributors/emerlm.svg" /></a><table><tbody><tr><td width="150" align="center"><a href="https://github.com/jeanlescure/short_uuid/commits?author=EmerLM" title="Code">💻</a></td></tr></tbody></table></td>
<td align="center"><a href="https://github.com/serendipious"><img src="https://shortunique.id/assets/contributors/serendipious.svg" /></a><table><tbody><tr><td width="150" align="center"><a href="https://github.com/jeanlescure/short-unique-id/commits?author=serendipious" title="Code">💻</a></td></tr></tbody></table></td>
<td align="center"><a href="https://jeanlescure.cr"><img src="https://shortunique.id/assets/contributors/jeanlescure.svg" /></a><table><tbody><tr><td width="150" align="center"><a href="#maintenance-jeanlescure" title="Maintenance">🚧</a> <a href="https://github.com/jeanlescure/short-unique-id/commits?author=jeanlescure" title="Code">💻</a> <a href="#content-jeanlescure" title="Content">🖋</a> <a href="https://github.com/jeanlescure/short-unique-id/commits?author=jeanlescure" title="Documentation">📖</a> <a href="https://github.com/jeanlescure/short-unique-id/commits?author=jeanlescure" title="Tests">⚠️</a></td></tr></tbody></table></td>
<td align="center"><a href="https://dianalu.design"><img src="https://shortunique.id/assets/contributors/dilescure.svg" /></a><table><tbody><tr><td width="150" align="center"><a href="https://github.com/jeanlescure/short_uuid/commits?author=DiLescure" title="Code">💻</a></td></tr></tbody></table></td>
<td align="center"><a href="https://github.com/EmerLM"><img src="https://shortunique.id/assets/contributors/emerlm.svg" /></a><table><tbody><tr><td width="150" align="center"><a href="https://github.com/jeanlescure/short_uuid/commits?author=EmerLM" title="Code">💻</a></td></tr></tbody></table></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/angelnath26"><img src="assets/contributors/angelnath26.svg" /></a><table><tbody><tr><td width="150" align="center"><a href="https://github.com/jeanlescure/short_uuid/commits?author=angelnath26" title="Code">💻</a> <a href="https://github.com/jeanlescure/short_uuid/pulls?q=is%3Apr+reviewed-by%3Aangelnath26" title="Reviewed Pull Requests">👀</a></td></tr></tbody></table></td>
<td align="center"><a href="https://twitter.com/jeffturcotte"><img src="assets/contributors/jeffturcotte.svg" /></a><table><tbody><tr><td width="150" align="center"><a href="https://github.com/jeanlescure/short-unique-id/commits?author=jeffturcotte" title="Code">💻</a></td></tr></tbody></table></td>
<td align="center"><a href="https://github.com/neversun"><img src="assets/contributors/neversun.svg" /></a><table><tbody><tr><td width="150" align="center"><a href="https://github.com/jeanlescure/short-unique-id/commits?author=neversun" title="Code">💻</a></td></tr></tbody></table></td>
<td align="center"><a href="https://github.com/ekelvin"><img src="assets/contributors/ekelvin.svg" /></a><table><tbody><tr><td width="150" align="center"><a href="https://github.com/jeanlescure/short-unique-id/issues/19" title="Ideas, Planning, & Feedback">🤔</a></td></tr></tbody></table></td>
<td align="center"><a href="https://github.com/angelnath26"><img src="https://shortunique.id/assets/contributors/angelnath26.svg" /></a><table><tbody><tr><td width="150" align="center"><a href="https://github.com/jeanlescure/short_uuid/commits?author=angelnath26" title="Code">💻</a> <a href="https://github.com/jeanlescure/short_uuid/pulls?q=is%3Apr+reviewed-by%3Aangelnath26" title="Reviewed Pull Requests">👀</a></td></tr></tbody></table></td>
<td align="center"><a href="https://twitter.com/jeffturcotte"><img src="https://shortunique.id/assets/contributors/jeffturcotte.svg" /></a><table><tbody><tr><td width="150" align="center"><a href="https://github.com/jeanlescure/short-unique-id/commits?author=jeffturcotte" title="Code">💻</a></td></tr></tbody></table></td>
<td align="center"><a href="https://github.com/neversun"><img src="https://shortunique.id/assets/contributors/neversun.svg" /></a><table><tbody><tr><td width="150" align="center"><a href="https://github.com/jeanlescure/short-unique-id/commits?author=neversun" title="Code">💻</a></td></tr></tbody></table></td>
<td align="center"><a href="https://github.com/ekelvin"><img src="https://shortunique.id/assets/contributors/ekelvin.svg" /></a><table><tbody><tr><td width="150" align="center"><a href="https://github.com/jeanlescure/short-unique-id/issues/19" title="Ideas, Planning, & Feedback">🤔</a></td></tr></tbody></table></td>
</tr>

@@ -126,0 +127,0 @@ </table>

// Copyright 2017-2020 the Short Unique ID authors. All rights reserved. Apache 2.0 license.
import { version } from './version.json';
import version from './version.ts';

@@ -86,3 +86,3 @@ type Ranges = {

* // Sequential UUID
* console.log(uid.sequentialUUID());
* console.log(uid.seq());
* ```

@@ -94,3 +94,3 @@ *

* <!-- Import -->
* <script src="https://jeanlescure.github.io/short-unique-id/dist/short-unique-id.min.js"></script>
* <script src="https://cdn.jsdelivr.net/npm/short-unique-id@3.0.0-rc1/dist/short-unique-id.min.js"></script>
*

@@ -100,3 +100,2 @@ * <!-- Usage -->

* // Instantiate
* var ShortUniqueId = window['short-unique-id'].default;
* var uid = new ShortUniqueId();

@@ -108,3 +107,3 @@ *

* // Sequential UUID
* document.write(uid.sequentialUUID());
* document.write(uid.seq());
* </script>

@@ -415,2 +414,5 @@ * ```

/**
* Return the version of this module.
*/
getVersion(): string {

@@ -417,0 +419,0 @@ return this.version;

# Deno Short UUID Module
This is a random UUID reneration module which allows you to set your own dictionary and length.
This is a random UUID generation module which allows you to set your own dictionary and length.

@@ -37,3 +37,3 @@ ## Platform Support

// Sequential UUID
// Sequential UUID (using internal counter)
console.log(abUid.seq()); // a

@@ -40,0 +40,0 @@ console.log(abUid.seq()); // b

@@ -12,2 +12,15 @@ // Copyright 2017-2020 the Short Unique ID authors. All rights reserved. Apache license.

test({
name: 'ability to show module version',
fn(): void {
const uid: ShortUniqueId = new ShortUniqueId({
dictionary: ['a', 'b'],
shuffle: false,
});
const version = uid.getVersion();
assert((/^\d+\.\d+.\d+/).test(version));
},
});
test({
name: 'ability to generate random id\'s based on internal counter',

@@ -14,0 +27,0 @@ fn(): void {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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