From 4e2832bb8632afa7526b72be71dad09800c0c8d7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 19 Jul 2020 18:52:11 +0000 Subject: [PATCH 1/6] Bump lodash from 4.17.15 to 4.17.19 Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19. - [Release notes](https://github.com/lodash/lodash/releases) - [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.19) Signed-off-by: dependabot[bot] --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index ccc1ff9..5b09969 100644 --- a/yarn.lock +++ b/yarn.lock @@ -835,9 +835,9 @@ lodash.memoize@~3.0.3: integrity sha1-LcvSwofLwKVcxCMovQxzYVDVPj8= lodash@^4.17.15: - version "4.17.15" - resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" - integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A== + version "4.17.19" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b" + integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ== lower-case@^1.1.1: version "1.1.4" From 7832dfa3cb502cb00a2e3f700925f14a8e0ad4de Mon Sep 17 00:00:00 2001 From: "Jean M. Lescure" Date: Sun, 19 Jul 2020 13:39:36 -0600 Subject: [PATCH 2/6] add publish config --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 1869172..4b91be5 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,9 @@ "type": "git", "url": "https://github.com/jeanlescure/short-unique-id" }, + "publishConfig": { + "registry": "https://npm.pkg.github.com/" + }, "runkitExampleFilename": "./test/runkit.js", "scripts": { "gen:version": "echo \"export default '`jq -r .version package.json`';\" > short_uuid/version.ts", From b83114f482a083a63d76513a7ad702c38d6f53a5 Mon Sep 17 00:00:00 2001 From: "Jean M. Lescure" Date: Sun, 19 Jul 2020 13:42:28 -0600 Subject: [PATCH 3/6] update workflow to use latest Deno --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 71776dd..ac32416 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -31,7 +31,7 @@ jobs: # Runs a single command using the runners shell - name: Install Deno - run: curl -fsSL https://deno.land/x/install/install.sh | sh -s v1.0.0 + run: curl -fsSL https://deno.land/x/install/install.sh | sh - name: Install Yarn run: npm install -g yarn From 75e0fae5744b4b19f8c99b91be767fb31fdb0fc3 Mon Sep 17 00:00:00 2001 From: "Jean M. Lescure" Date: Sun, 19 Jul 2020 14:07:46 -0600 Subject: [PATCH 4/6] adjust tsconfig and bump version --- .vscode/settings.json | 3 +- dist/short-unique-id.js | 533 ++++++++++---------------------- dist/short-unique-id.min.js | 2 +- docs/assets/js/search.json | 2 +- docs/classes/shortuniqueid.html | 62 +++- docs/globals.html | 6 +- docs/index.html | 6 +- lib/short-unique-id.js | 533 ++++++++++---------------------- lib/version.js | 37 +-- package.json | 4 +- tsconfig.json | 15 + 11 files changed, 426 insertions(+), 777 deletions(-) create mode 100644 tsconfig.json diff --git a/.vscode/settings.json b/.vscode/settings.json index 4b9fb22..8f8df68 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "deno.enable": true + "deno.enable": true, + "typescript.tsdk": "node_modules/typescript/lib" } \ No newline at end of file diff --git a/dist/short-unique-id.js b/dist/short-unique-id.js index 7c4b0cb..a8e089e 100644 --- a/dist/short-unique-id.js +++ b/dist/short-unique-id.js @@ -4,10 +4,11 @@ var __suid_module = // This is a specialised implementation of a System module loader. +"use strict"; + // @ts-nocheck /* eslint-disable */ -let System, __instantiateAsync, __instantiate; - +let System, __instantiate; (() => { const r = new Map(); @@ -16,7 +17,6 @@ let System, __instantiateAsync, __instantiate; r.set(id, { d, f, exp: {} }); }, }; - async function dI(mid, src) { let id = mid.replace(/\.\w+$/i, ""); if (id.includes("./")) { @@ -93,385 +93,176 @@ let System, __instantiateAsync, __instantiate; } return m.exp; } - - __instantiateAsync = async (m) => { - System = __instantiateAsync = __instantiate = undefined; - rF(m); - return gExpA(m); - }; - - __instantiate = (m) => { - System = __instantiateAsync = __instantiate = undefined; + __instantiate = (m, a) => { + System = __instantiate = undefined; rF(m); - return gExp(m); + return a ? gExpA(m) : gExp(m); }; })(); System.register("version", [], function (exports_1, context_1) { - "use strict"; - var __moduleName = context_1 && context_1.id; - return { - setters: [], - execute: function () { - exports_1("default", "3.0.2"); - }, - }; + "use strict"; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + exports_1("default", '3.0.4'); + } + }; }); System.register("mod", ["version"], function (exports_2, context_2) { - "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 - * it will be more than aptly suitable to provide millions of UUIDs - * with a very low probability of producing a duplicate UUID. - * - * For example, with a dictionary including digits from 0 to 9, - * as well as the alphabet from a to z both in UPPER and lower case, - * the probability of generating a duplicate in 1,000,000 rounds - * is ~0.00000002, or about 1 in 50,000,000. - */ - 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. - * - * ### Use as module - * - * ```js - * // Deno (web module) Import - * import ShortUniqueId from 'https://cdn.jsdelivr.net/npm/short-unique-id@latest/short_uuid/mod.ts'; - * - * // ES6 / TypeScript Import - * import ShortUniqueId from 'short-unique-id'; - * - * //or Node.js require - * const {default: ShortUniqueId} = require('short-unique-id'); - * - * //Instantiate - * const uid = new ShortUniqueId(); - * - * // Random UUID - * console.log(uid()); - * - * // Sequential UUID - * console.log(uid.seq()); - * ``` - * - * ### Use in browser - * - * ```html - * - * - * - * - * - * ``` - * - * ### Options - * - * Options can be passed when instantiating `uid`: - * - * ```js - * const options = { ... }; - * - * const uid = new ShortUniqueId(options); - * ``` - * - * For more information take a look at the [Options type definition](/globals.html#options). - */ - 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; + "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; } - } - /* 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; - } - /** - * Calculates total number of possible UUIDs. - * - * Given that: - * - * - `H` is the total number of possible UUIDs - * - `n` is the number of unique characters in the dictionary - * - `l` is the UUID length - * - * Then `H` is defined as `n` to the power of `l`: - * - * ![](https://render.githubusercontent.com/render/math?math=%5CHuge%20H=n%5El) - * - * This function returns `H`. - */ - availableUUIDs(uuidLength = this.uuidLength) { - return parseFloat( - Math.pow([...new Set(this.dict)].length, uuidLength).toFixed(0), - ); + ], + execute: function () { + 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, + }; + ShortUniqueId = class ShortUniqueId extends Function { + 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) { + 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; + } + log(...args) { + const finalArgs = [...args]; + finalArgs[0] = `[short-unique-id] ${args[0]}`; + if (this.debug === true) { + if (typeof console !== 'undefined' && console !== null) { + return console.log(...finalArgs); + } + } + } + setDictionary(dictionary) { + this.dict = dictionary; + this.dictLength = this.dict.length; + this.counter = 0; + } + seq() { + return this.sequentialUUID(); + } + sequentialUUID() { + let counterDiv; + let counterRem; + let id = ''; + counterDiv = this.counter; + while (true) { + counterRem = counterDiv % this.dictLength; + counterDiv = Math.trunc(counterDiv / this.dictLength); + id += this.dict[counterRem]; + if (counterDiv === 0) { + break; + } + } + this.counter += 1; + 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'); + } + 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 id; + } + availableUUIDs(uuidLength = this.uuidLength) { + return parseFloat(Math.pow([...new Set(this.dict)].length, uuidLength).toFixed(0)); + } + approxMaxBeforeCollision(rounds = this.availableUUIDs(this.uuidLength)) { + return parseFloat(Math.sqrt((Math.PI / 2) * rounds).toFixed(20)); + } + collisionProbability(rounds = this.availableUUIDs(this.uuidLength), uuidLength = this.uuidLength) { + return parseFloat((this.approxMaxBeforeCollision(rounds) / this.availableUUIDs(uuidLength)).toFixed(20)); + } + 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); } - /** - * Calculates approximate number of hashes before first collision. - * - * Given that: - * - * - `H` is the total number of possible UUIDs, or in terms of this library, - * the result of running `availableUUIDs()` - * - the expected number of values we have to choose before finding the - * first collision can be expressed as the quantity `Q(H)` - * - * Then `Q(H)` can be approximated as the square root of the of the product - * of half of pi times `H`: - * - * ![](https://render.githubusercontent.com/render/math?math=%5CHuge%20Q(H)%5Capprox%5Csqrt%7B%5Cfrac%7B%5Cpi%7D%7B2%7DH%7D) - * - * This function returns `Q(H)`. - */ - 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 - * given number of UUID generation rounds. - * - * Given that: - * - * - `r` is the maximum number of times that `randomUUID()` will be called, - * or better said the number of _rounds_ - * - `H` is the total number of possible UUIDs, or in terms of this library, - * the result of running `availableUUIDs()` - * - * Then the probability of collision `p(r; H)` can be approximated as the result - * of dividing the square root of the of the product of half of pi times `H` by `H`: - * - * ![](https://render.githubusercontent.com/render/math?math=%5CHuge%20p(r%3B%20H)%5Capprox%5Cfrac%7B%5Csqrt%7B%5Cfrac%7B%5Cpi%7D%7B2%7Dr%7D%7D%7BH%7D) - * - * This function returns `p(r; H)`. - * - * (Useful if you are wondering _"If I use this lib and expect to perform at most - * `r` rounds of UUID generations, what is the probability that I will hit a duplicate UUID?"_.) - */ - 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 - * dictionary and chosen UUID length. - * - * Given that: - * - * - `H` is the total number of possible UUIDs, or in terms of this library, - * the result of running `availableUUIDs()` - * - `Q(H)` is the approximate number of hashes before first collision, - * or in terms of this library, the result of running `approxMaxBeforeCollision()` - * - * Then `uniqueness` can be expressed as the additive inverse of the probability of - * generating a "word" I had previously generated (a duplicate) at any given iteration - * up to the the total number of possible UUIDs expressed as the quotiend of `Q(H)` and `H`: - * - * ![](https://render.githubusercontent.com/render/math?math=%5CHuge%201-%5Cfrac%7BQ(H)%7D%7BH%7D) - * - * (Useful if you need a value to rate the "quality" of the combination of given dictionary - * and UUID length. The closer to 1, higher the uniqueness and thus better the quality.) - */ - 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); - }, - }; + }; }); -const __exp = __instantiate("mod"); +const __exp = __instantiate("mod", false); exports. default = __exp["default"]; },{}]},{},[1]); diff --git a/dist/short-unique-id.min.js b/dist/short-unique-id.min.js index a36b9f9..50e3582 100644 --- a/dist/short-unique-id.min.js +++ b/dist/short-unique-id.min.js @@ -1 +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 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{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)}ut(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=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;i1)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?tthis.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?nt;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{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)}ut(i))}(n,i),meta:{url:i,main:n}}}function r(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})}}async function o(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=s=void 0,function(t){for(const[n,s]of e.entries()){const{f:e,exp:o}=s,{execute:u,setters:h}=e(r(o),i(n,n===t));delete s.f,s.e=u,s.s=h}}(t),u?o(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;i1)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?tthis.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?nt;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 r=s("mod",!1);i.default=r.default},{}]},{},[1]),ShortUniqueId=__suid_module(1).default; diff --git a/docs/assets/js/search.json b/docs/assets/js/search.json index 0b33361..bed2022 100644 --- a/docs/assets/js/search.json +++ b/docs/assets/js/search.json @@ -1 +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":"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":[]}} \ No newline at end of file +{"kinds":{"32":"Variable","128":"Class","1024":"Property","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":1024,"name":"name","url":"classes/shortuniqueid.html#name","classes":"tsd-kind-property tsd-parent-kind-class tsd-is-inherited","parent":"ShortUniqueId"},{"id":14,"kind":2048,"name":"[Symbol.hasInstance]","url":"classes/shortuniqueid.html#_symbol_hasinstance_","classes":"tsd-kind-method tsd-parent-kind-class tsd-is-inherited","parent":"ShortUniqueId"},{"id":15,"kind":4194304,"name":"Options","url":"globals.html#options","classes":"tsd-kind-type-alias"},{"id":16,"kind":65536,"name":"__type","url":"globals.html#options.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias","parent":"Options"},{"id":17,"kind":32,"name":"dictionary","url":"globals.html#options.__type.dictionary","classes":"tsd-kind-variable tsd-parent-kind-type-literal","parent":"Options.__type"},{"id":18,"kind":32,"name":"shuffle","url":"globals.html#options.__type.shuffle","classes":"tsd-kind-variable tsd-parent-kind-type-literal","parent":"Options.__type"},{"id":19,"kind":32,"name":"debug","url":"globals.html#options.__type.debug","classes":"tsd-kind-variable tsd-parent-kind-type-literal","parent":"Options.__type"},{"id":20,"kind":32,"name":"length","url":"globals.html#options.__type.length","classes":"tsd-kind-variable tsd-parent-kind-type-literal","parent":"Options.__type"},{"id":21,"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,3.947]],["parent/0",[]],["name/1",[1,27.3]],["parent/1",[0,0.371]],["name/2",[2,27.3]],["parent/2",[0,0.371]],["name/3",[3,27.3]],["parent/3",[0,0.371]],["name/4",[4,27.3]],["parent/4",[0,0.371]],["name/5",[5,27.3]],["parent/5",[0,0.371]],["name/6",[6,27.3]],["parent/6",[0,0.371]],["name/7",[7,27.3]],["parent/7",[0,0.371]],["name/8",[8,27.3]],["parent/8",[0,0.371]],["name/9",[9,27.3]],["parent/9",[0,0.371]],["name/10",[10,27.3]],["parent/10",[0,0.371]],["name/11",[11,27.3]],["parent/11",[0,0.371]],["name/12",[12,27.3]],["parent/12",[0,0.371]],["name/13",[13,27.3]],["parent/13",[0,0.371]],["name/14",[14,27.3]],["parent/14",[0,0.371]],["name/15",[15,22.192]],["parent/15",[]],["name/16",[16,27.3]],["parent/16",[15,2.085]],["name/17",[17,27.3]],["parent/17",[18,1.532]],["name/18",[19,27.3]],["parent/18",[18,1.532]],["name/19",[20,27.3]],["parent/19",[18,1.532]],["name/20",[21,27.3]],["parent/20",[18,1.532]],["name/21",[22,27.3]],["parent/21",[]]],"invertedIndex":[["__type",{"_index":16,"name":{"16":{}},"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":20,"name":{"19":{}},"parent":{}}],["default_uuid_length",{"_index":22,"name":{"21":{}},"parent":{}}],["dictionary",{"_index":17,"name":{"17":{}},"parent":{}}],["getversion",{"_index":8,"name":{"8":{}},"parent":{}}],["length",{"_index":21,"name":{"20":{}},"parent":{}}],["name",{"_index":13,"name":{"13":{}},"parent":{}}],["options",{"_index":15,"name":{"15":{}},"parent":{"16":{}}}],["options.__type",{"_index":18,"name":{},"parent":{"17":{},"18":{},"19":{},"20":{}}}],["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":{},"13":{},"14":{}}}],["shuffle",{"_index":19,"name":{"18":{}},"parent":{}}],["symbol.hasinstance",{"_index":14,"name":{"14":{}},"parent":{}}],["tostring",{"_index":12,"name":{"12":{}},"parent":{}}],["uniqueness",{"_index":7,"name":{"7":{}},"parent":{}}]],"pipeline":[]}} \ No newline at end of file diff --git a/docs/classes/shortuniqueid.html b/docs/classes/shortuniqueid.html index 0e403e1..4619022 100644 --- a/docs/classes/shortuniqueid.html +++ b/docs/classes/shortuniqueid.html @@ -4,7 +4,7 @@ Short Unique ID - Short UUID Generator - + @@ -33,7 +33,7 @@
  • Preparing search index...
  • The search index is not available
  • - short-unique-id - v3.0.2 + short-unique-id - v3.0.4
    @@ -79,6 +79,12 @@

    API Reference

  • ShortUniqueId
      +
    • + name +
    • +
    • + [Symbol.hasInstance] +
    • apply
    • @@ -198,9 +204,16 @@

      Hierarchy

      Index

      +
      +

      Properties

      + +

      Methods

      +
      +

      Properties

      +
      + +

      Readonly name

      +
      name: string
      + +
      +
      +

      Returns the name of the function. Function names are read-only and can not be changed.

      +
      +
      +
      +

      Methods

      +
      + +

      [Symbol.hasInstance]

      +
        +
      • [Symbol.hasInstance](value: any): boolean
      • +
      +
        +
      • + +
        +
        +

        Determines whether the given value inherits from this function if this function was used + as a constructor function.

        +
        +

        A constructor function can control which objects are recognized as its instances by + 'instanceof' by overriding this method.

        +
        +

        Parameters

        +
          +
        • +
          value: any
          +
        • +
        +

        Returns boolean

        +
      • +
      +

      apply

      diff --git a/docs/globals.html b/docs/globals.html index 8792c18..c732fbd 100644 --- a/docs/globals.html +++ b/docs/globals.html @@ -4,7 +4,7 @@ Short Unique ID - Short UUID Generator - + @@ -33,7 +33,7 @@
    • Preparing search index...
    • The search index is not available
    - short-unique-id - v3.0.2 + short-unique-id - v3.0.4
  • @@ -58,7 +58,7 @@
    -

    short-unique-id - v3.0.2

    +

    short-unique-id - v3.0.4

    diff --git a/docs/index.html b/docs/index.html index 6f3d50c..76be6ef 100644 --- a/docs/index.html +++ b/docs/index.html @@ -4,7 +4,7 @@ Short Unique ID - Short UUID Generator - + @@ -33,7 +33,7 @@
  • Preparing search index...
  • The search index is not available
  • - short-unique-id - v3.0.2 + short-unique-id - v3.0.4
    @@ -58,7 +58,7 @@
    -

    short-unique-id - v3.0.2

    +

    short-unique-id - v3.0.4

    diff --git a/lib/short-unique-id.js b/lib/short-unique-id.js index 23b6f1a..c471c10 100644 --- a/lib/short-unique-id.js +++ b/lib/short-unique-id.js @@ -2,10 +2,11 @@ // This is a specialised implementation of a System module loader. +"use strict"; + // @ts-nocheck /* eslint-disable */ -let System, __instantiateAsync, __instantiate; - +let System, __instantiate; (() => { const r = new Map(); @@ -14,7 +15,6 @@ let System, __instantiateAsync, __instantiate; r.set(id, { d, f, exp: {} }); }, }; - async function dI(mid, src) { let id = mid.replace(/\.\w+$/i, ""); if (id.includes("./")) { @@ -91,383 +91,174 @@ let System, __instantiateAsync, __instantiate; } return m.exp; } - - __instantiateAsync = async (m) => { - System = __instantiateAsync = __instantiate = undefined; - rF(m); - return gExpA(m); - }; - - __instantiate = (m) => { - System = __instantiateAsync = __instantiate = undefined; + __instantiate = (m, a) => { + System = __instantiate = undefined; rF(m); - return gExp(m); + return a ? gExpA(m) : gExp(m); }; })(); System.register("version", [], function (exports_1, context_1) { - "use strict"; - var __moduleName = context_1 && context_1.id; - return { - setters: [], - execute: function () { - exports_1("default", "3.0.2"); - }, - }; + "use strict"; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + exports_1("default", '3.0.4'); + } + }; }); System.register("mod", ["version"], function (exports_2, context_2) { - "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 - * it will be more than aptly suitable to provide millions of UUIDs - * with a very low probability of producing a duplicate UUID. - * - * For example, with a dictionary including digits from 0 to 9, - * as well as the alphabet from a to z both in UPPER and lower case, - * the probability of generating a duplicate in 1,000,000 rounds - * is ~0.00000002, or about 1 in 50,000,000. - */ - 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. - * - * ### Use as module - * - * ```js - * // Deno (web module) Import - * import ShortUniqueId from 'https://cdn.jsdelivr.net/npm/short-unique-id@latest/short_uuid/mod.ts'; - * - * // ES6 / TypeScript Import - * import ShortUniqueId from 'short-unique-id'; - * - * //or Node.js require - * const {default: ShortUniqueId} = require('short-unique-id'); - * - * //Instantiate - * const uid = new ShortUniqueId(); - * - * // Random UUID - * console.log(uid()); - * - * // Sequential UUID - * console.log(uid.seq()); - * ``` - * - * ### Use in browser - * - * ```html - * - * - * - * - * - * ``` - * - * ### Options - * - * Options can be passed when instantiating `uid`: - * - * ```js - * const options = { ... }; - * - * const uid = new ShortUniqueId(options); - * ``` - * - * For more information take a look at the [Options type definition](/globals.html#options). - */ - 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; + "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; } - } - /* 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; - } - /** - * Calculates total number of possible UUIDs. - * - * Given that: - * - * - `H` is the total number of possible UUIDs - * - `n` is the number of unique characters in the dictionary - * - `l` is the UUID length - * - * Then `H` is defined as `n` to the power of `l`: - * - * ![](https://render.githubusercontent.com/render/math?math=%5CHuge%20H=n%5El) - * - * This function returns `H`. - */ - availableUUIDs(uuidLength = this.uuidLength) { - return parseFloat( - Math.pow([...new Set(this.dict)].length, uuidLength).toFixed(0), - ); + ], + execute: function () { + 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, + }; + ShortUniqueId = class ShortUniqueId extends Function { + 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) { + 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; + } + log(...args) { + const finalArgs = [...args]; + finalArgs[0] = `[short-unique-id] ${args[0]}`; + if (this.debug === true) { + if (typeof console !== 'undefined' && console !== null) { + return console.log(...finalArgs); + } + } + } + setDictionary(dictionary) { + this.dict = dictionary; + this.dictLength = this.dict.length; + this.counter = 0; + } + seq() { + return this.sequentialUUID(); + } + sequentialUUID() { + let counterDiv; + let counterRem; + let id = ''; + counterDiv = this.counter; + while (true) { + counterRem = counterDiv % this.dictLength; + counterDiv = Math.trunc(counterDiv / this.dictLength); + id += this.dict[counterRem]; + if (counterDiv === 0) { + break; + } + } + this.counter += 1; + 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'); + } + 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 id; + } + availableUUIDs(uuidLength = this.uuidLength) { + return parseFloat(Math.pow([...new Set(this.dict)].length, uuidLength).toFixed(0)); + } + approxMaxBeforeCollision(rounds = this.availableUUIDs(this.uuidLength)) { + return parseFloat(Math.sqrt((Math.PI / 2) * rounds).toFixed(20)); + } + collisionProbability(rounds = this.availableUUIDs(this.uuidLength), uuidLength = this.uuidLength) { + return parseFloat((this.approxMaxBeforeCollision(rounds) / this.availableUUIDs(uuidLength)).toFixed(20)); + } + 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); } - /** - * Calculates approximate number of hashes before first collision. - * - * Given that: - * - * - `H` is the total number of possible UUIDs, or in terms of this library, - * the result of running `availableUUIDs()` - * - the expected number of values we have to choose before finding the - * first collision can be expressed as the quantity `Q(H)` - * - * Then `Q(H)` can be approximated as the square root of the of the product - * of half of pi times `H`: - * - * ![](https://render.githubusercontent.com/render/math?math=%5CHuge%20Q(H)%5Capprox%5Csqrt%7B%5Cfrac%7B%5Cpi%7D%7B2%7DH%7D) - * - * This function returns `Q(H)`. - */ - 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 - * given number of UUID generation rounds. - * - * Given that: - * - * - `r` is the maximum number of times that `randomUUID()` will be called, - * or better said the number of _rounds_ - * - `H` is the total number of possible UUIDs, or in terms of this library, - * the result of running `availableUUIDs()` - * - * Then the probability of collision `p(r; H)` can be approximated as the result - * of dividing the square root of the of the product of half of pi times `H` by `H`: - * - * ![](https://render.githubusercontent.com/render/math?math=%5CHuge%20p(r%3B%20H)%5Capprox%5Cfrac%7B%5Csqrt%7B%5Cfrac%7B%5Cpi%7D%7B2%7Dr%7D%7D%7BH%7D) - * - * This function returns `p(r; H)`. - * - * (Useful if you are wondering _"If I use this lib and expect to perform at most - * `r` rounds of UUID generations, what is the probability that I will hit a duplicate UUID?"_.) - */ - 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 - * dictionary and chosen UUID length. - * - * Given that: - * - * - `H` is the total number of possible UUIDs, or in terms of this library, - * the result of running `availableUUIDs()` - * - `Q(H)` is the approximate number of hashes before first collision, - * or in terms of this library, the result of running `approxMaxBeforeCollision()` - * - * Then `uniqueness` can be expressed as the additive inverse of the probability of - * generating a "word" I had previously generated (a duplicate) at any given iteration - * up to the the total number of possible UUIDs expressed as the quotiend of `Q(H)` and `H`: - * - * ![](https://render.githubusercontent.com/render/math?math=%5CHuge%201-%5Cfrac%7BQ(H)%7D%7BH%7D) - * - * (Useful if you need a value to rate the "quality" of the combination of given dictionary - * and UUID length. The closer to 1, higher the uniqueness and thus better the quality.) - */ - 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); - }, - }; + }; }); -const __exp = __instantiate("mod"); +const __exp = __instantiate("mod", false); exports. default = __exp["default"]; diff --git a/lib/version.js b/lib/version.js index 5e7fc00..b207d9d 100644 --- a/lib/version.js +++ b/lib/version.js @@ -2,10 +2,11 @@ // This is a specialised implementation of a System module loader. +"use strict"; + // @ts-nocheck /* eslint-disable */ -let System, __instantiateAsync, __instantiate; - +let System, __instantiate; (() => { const r = new Map(); @@ -14,7 +15,6 @@ let System, __instantiateAsync, __instantiate; r.set(id, { d, f, exp: {} }); }, }; - async function dI(mid, src) { let id = mid.replace(/\.\w+$/i, ""); if (id.includes("./")) { @@ -91,30 +91,23 @@ let System, __instantiateAsync, __instantiate; } return m.exp; } - - __instantiateAsync = async (m) => { - System = __instantiateAsync = __instantiate = undefined; + __instantiate = (m, a) => { + System = __instantiate = undefined; rF(m); - return gExpA(m); - }; - - __instantiate = (m) => { - System = __instantiateAsync = __instantiate = undefined; - rF(m); - return gExp(m); + return a ? gExpA(m) : gExp(m); }; })(); System.register("version", [], function (exports_1, context_1) { - "use strict"; - var __moduleName = context_1 && context_1.id; - return { - setters: [], - execute: function () { - exports_1("default", "3.0.2"); - }, - }; + "use strict"; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + exports_1("default", '3.0.4'); + } + }; }); -const __exp = __instantiate("version"); +const __exp = __instantiate("version", false); exports. default = __exp["default"]; diff --git a/package.json b/package.json index 4b91be5..f1a3ae6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "short-unique-id", - "version": "3.0.3", + "version": "3.0.4", "description": "Generate random or sequential UUID of any length", "keywords": [ "short", @@ -27,7 +27,7 @@ "scripts": { "gen:version": "echo \"export default '`jq -r .version package.json`';\" > short_uuid/version.ts", "gen:docs": "cd short_uuid && typedoc --gaID UA-159642755-1 --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", - "gen:typings": "cd short_uuid && ../node_modules/typescript/bin/tsc --declaration --emitDeclarationOnly mod.ts ; mv mod.d.ts ../typings/short-unique-id.d.ts", + "gen:typings": "tsc --lib dom,es2015 --downlevelIteration --declaration --emitDeclarationOnly ./short_uuid/mod.ts ; mv ./short_uuid/mod.d.ts ./typings/short-unique-id.d.ts", "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", "test": "cd short_uuid && deno test && cd .. && yarn link && yarn link short-unique-id && node ./runkit.js", diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..e1fdcb7 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "experimentalDecorators": true, + "pretty": true, + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, + "forceConsistentCasingInFileNames": true, + "allowSyntheticDefaultImports": true, + "downlevelIteration": true, + "lib": [ + "DOM", + "ES2015" + ] + } +} From fccf901524dfe0a630b1268967e7a4fffb6f645e Mon Sep 17 00:00:00 2001 From: "Jean M. Lescure" Date: Sun, 19 Jul 2020 14:09:40 -0600 Subject: [PATCH 5/6] update deno tested version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0635588..8094ee7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![tests](https://github.com/jeanlescure/short-unique-id/workflows/tests/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) -[![Deno v1.0.0](https://img.shields.io/badge/deno-v1.0.0-green.svg)](https://deno.land) +[![Deno v1.2.0](https://img.shields.io/badge/deno-v1.2.0-green.svg)](https://deno.land) [![8 Contributors](https://img.shields.io/badge/all_contributors-8-purple.svg)](#contributors) From 0d3a11c164d707a7597f140900c7d4198c98db45 Mon Sep 17 00:00:00 2001 From: "Jean M. Lescure" Date: Sun, 19 Jul 2020 14:10:52 -0600 Subject: [PATCH 6/6] update submodule to latest --- short_uuid | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/short_uuid b/short_uuid index 19a5cbb..aed5860 160000 --- a/short_uuid +++ b/short_uuid @@ -1 +1 @@ -Subproject commit 19a5cbb5a90b4ac2c9cc86001b307e37f4ba8820 +Subproject commit aed58607a7d7f6600b8928044b7c2ad3023d1529