short-unique-id
Advanced tools
Comparing version 4.0.2 to 4.2.0
@@ -5,2 +5,15 @@ # Changelog | ||
## [4.2.0](https://github.com/jeanlescure/short-unique-id/compare/v4.1.3...v4.2.0) (2021-05-04) | ||
### [4.1.3](https://github.com/jeanlescure/short-unique-id/compare/v4.1.2...v4.1.3) (2021-05-04) | ||
### [4.1.2](https://github.com/jeanlescure/short-unique-id/compare/v4.1.0...v4.1.2) (2021-05-04) | ||
## [4.1.0](https://github.com/jeanlescure/short-unique-id/compare/v4.0.2...v4.1.0) (2021-05-04) | ||
### Bug Fixes | ||
* wrong image address ([ac7ccb6](https://github.com/jeanlescure/short-unique-id/commit/ac7ccb600dedfcaccbde2cfd7aca2047262dc440)) | ||
### [4.0.2](https://github.com/jeanlescure/short-unique-id/compare/v4.0.1...v4.0.2) (2021-05-04) | ||
@@ -7,0 +20,0 @@ |
@@ -72,3 +72,3 @@ (function (global, factory) { | ||
var version = "4.0.0"; | ||
var version = "4.2.0"; | ||
@@ -75,0 +75,0 @@ // @module ShortUniqueId |
@@ -15,2 +15,2 @@ (function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?factory(exports):typeof define==="function"&&define.amd?define(["exports"],factory):(global=typeof globalThis!=="undefined"?globalThis:global||self,factory(global.ShortUniqueId={}))})(this,(function(exports){"use strict"; | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */var extendStatics=function(d,b){extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)if(Object.prototype.hasOwnProperty.call(b,p))d[p]=b[p]};return extendStatics(d,b)};function __extends(d,b){if(typeof b!=="function"&&b!==null)throw new TypeError("Class extends value "+String(b)+" is not a constructor or null");extendStatics(d,b);function __(){this.constructor=d}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __)}var __assign=function(){__assign=Object.assign||function __assign(t){for(var s,i=1,n=arguments.length;i<n;i++){s=arguments[i];for(var p in s)if(Object.prototype.hasOwnProperty.call(s,p))t[p]=s[p]}return t};return __assign.apply(this,arguments)};function __read(o,n){var m=typeof Symbol==="function"&&o[Symbol.iterator];if(!m)return o;var i=m.call(o),r,ar=[],e;try{while((n===void 0||n-- >0)&&!(r=i.next()).done)ar.push(r.value)}catch(error){e={error:error}}finally{try{if(r&&!r.done&&(m=i["return"]))m.call(i)}finally{if(e)throw e.error}}return ar}function __spreadArray(to,from){for(var i=0,il=from.length,j=to.length;i<il;i++,j++)to[j]=from[i];return to}var version="4.0.0";var DEFAULT_UUID_LENGTH=6;var DIGIT_FIRST_ASCII=48;var DIGIT_LAST_ASCII=58;var ALPHA_LOWER_FIRST_ASCII=97;var ALPHA_LOWER_LAST_ASCII=123;var ALPHA_UPPER_FIRST_ASCII=65;var ALPHA_UPPER_LAST_ASCII=91;var 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]};var DEFAULT_OPTIONS={dictionary:[],shuffle:true,debug:false,length:DEFAULT_UUID_LENGTH};var ShortUniqueId=function(_super){__extends(ShortUniqueId,_super);function ShortUniqueId(argOptions){if(argOptions===void 0){argOptions={}}var _this=_super.call(this)||this;_this.dictIndex=0;_this.dictRange=[];_this.lowerBound=0;_this.upperBound=0;_this.dictLength=0;_this.log=function(){var args=[];for(var _i=0;_i<arguments.length;_i++){args[_i]=arguments[_i]}var finalArgs=__spreadArray([],__read(args));finalArgs[0]="[short-unique-id] "+args[0];if(_this.debug===true){if(typeof console!=="undefined"&&console!==null){return console.log.apply(console,__spreadArray([],__read(finalArgs)))}}};_this.setDictionary=function(dictionary){_this.dict=dictionary;_this.dictLength=_this.dict.length;_this.counter=0};_this.seq=function(){return _this.sequentialUUID()};_this.sequentialUUID=function(){var counterDiv;var counterRem;var id="";counterDiv=_this.counter;do{counterRem=counterDiv%_this.dictLength;counterDiv=Math.trunc(counterDiv/_this.dictLength);id+=_this.dict[counterRem]}while(counterDiv!==0);_this.counter+=1;return id};_this.randomUUID=function(uuidLength){if(uuidLength===void 0){uuidLength=_this.uuidLength||DEFAULT_UUID_LENGTH}var id;var randomPartIdx;var j;if(uuidLength===null||typeof uuidLength==="undefined"||uuidLength<1){throw new Error("Invalid UUID Length Provided")}id="";for(j=0;j<uuidLength;j+=1){randomPartIdx=parseInt((Math.random()*_this.dictLength).toFixed(0),10)%_this.dictLength;id+=_this.dict[randomPartIdx]}return id};_this.availableUUIDs=function(uuidLength){if(uuidLength===void 0){uuidLength=_this.uuidLength}return parseFloat(Math.pow(__spreadArray([],__read(new Set(_this.dict))).length,uuidLength).toFixed(0))};_this.approxMaxBeforeCollision=function(rounds){if(rounds===void 0){rounds=_this.availableUUIDs(_this.uuidLength)}return parseFloat(Math.sqrt(Math.PI/2*rounds).toFixed(20))};_this.collisionProbability=function(rounds,uuidLength){if(rounds===void 0){rounds=_this.availableUUIDs(_this.uuidLength)}if(uuidLength===void 0){uuidLength=_this.uuidLength}return parseFloat((_this.approxMaxBeforeCollision(rounds)/_this.availableUUIDs(uuidLength)).toFixed(20))};_this.uniqueness=function(rounds){if(rounds===void 0){rounds=_this.availableUUIDs(_this.uuidLength)}var score=parseFloat((1-_this.approxMaxBeforeCollision(rounds)/rounds).toFixed(20));return score>1?1:score<0?0:score};_this.getVersion=function(){return _this.version};_this.stamp=function(finalLength){if(finalLength<10){throw new Error("Param finalLength must be at least 10")}var hexStamp=Math.floor(+new Date/1e3).toString(16);var idLength=finalLength-9;var rndIdx=Math.round(Math.random()*(idLength>15?15:idLength));var id=_this.randomUUID(idLength);return""+id.substr(0,rndIdx)+hexStamp+id.substr(rndIdx)+rndIdx.toString(16)};_this.parseStamp=function(stamp){if(stamp.length<10){throw new Error("Stamp length invalid")}var rndIdx=parseInt(stamp.substr(stamp.length-1,1),16);return new Date(parseInt(stamp.substr(rndIdx,8),16)*1e3)};var options=__assign(__assign({},DEFAULT_OPTIONS),argOptions);_this.counter=0;_this.debug=false;_this.dict=[];_this.version=version;var userDict=options.dictionary,shuffle=options.shuffle,length=options.length;_this.uuidLength=length;if(userDict&&userDict.length>1){_this.setDictionary(userDict)}else{var i_1;_this.dictIndex=i_1=0;Object.keys(DICT_RANGES).forEach((function(rangeType){var rangeTypeKey=rangeType;_this.dictRange=DICT_RANGES[rangeTypeKey];_this.lowerBound=_this.dictRange[0];_this.upperBound=_this.dictRange[1];for(_this.dictIndex=i_1=_this.lowerBound;_this.lowerBound<=_this.upperBound?i_1<_this.upperBound:i_1>_this.upperBound;_this.dictIndex=_this.lowerBound<=_this.upperBound?i_1+=1:i_1-=1){_this.dict.push(String.fromCharCode(_this.dictIndex))}}))}if(shuffle){var PROBABILITY_1=.5;_this.setDictionary(_this.dict.sort((function(){return Math.random()-PROBABILITY_1})))}else{_this.setDictionary(_this.dict)}_this.debug=options.debug;_this.log(_this.dict);_this.log("Generator instantiated with Dictionary Size "+_this.dictLength);return new Proxy(_this,{apply:function(target,that,args){return _this.randomUUID.apply(_this,__spreadArray([],__read(args)))}})}return ShortUniqueId}(Function);exports.DEFAULT_UUID_LENGTH=DEFAULT_UUID_LENGTH;exports.default=ShortUniqueId;Object.defineProperty(exports,"__esModule",{value:true})})); | ||
***************************************************************************** */var extendStatics=function(d,b){extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)if(Object.prototype.hasOwnProperty.call(b,p))d[p]=b[p]};return extendStatics(d,b)};function __extends(d,b){if(typeof b!=="function"&&b!==null)throw new TypeError("Class extends value "+String(b)+" is not a constructor or null");extendStatics(d,b);function __(){this.constructor=d}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __)}var __assign=function(){__assign=Object.assign||function __assign(t){for(var s,i=1,n=arguments.length;i<n;i++){s=arguments[i];for(var p in s)if(Object.prototype.hasOwnProperty.call(s,p))t[p]=s[p]}return t};return __assign.apply(this,arguments)};function __read(o,n){var m=typeof Symbol==="function"&&o[Symbol.iterator];if(!m)return o;var i=m.call(o),r,ar=[],e;try{while((n===void 0||n-- >0)&&!(r=i.next()).done)ar.push(r.value)}catch(error){e={error:error}}finally{try{if(r&&!r.done&&(m=i["return"]))m.call(i)}finally{if(e)throw e.error}}return ar}function __spreadArray(to,from){for(var i=0,il=from.length,j=to.length;i<il;i++,j++)to[j]=from[i];return to}var version="4.2.0";var DEFAULT_UUID_LENGTH=6;var DIGIT_FIRST_ASCII=48;var DIGIT_LAST_ASCII=58;var ALPHA_LOWER_FIRST_ASCII=97;var ALPHA_LOWER_LAST_ASCII=123;var ALPHA_UPPER_FIRST_ASCII=65;var ALPHA_UPPER_LAST_ASCII=91;var 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]};var DEFAULT_OPTIONS={dictionary:[],shuffle:true,debug:false,length:DEFAULT_UUID_LENGTH};var ShortUniqueId=function(_super){__extends(ShortUniqueId,_super);function ShortUniqueId(argOptions){if(argOptions===void 0){argOptions={}}var _this=_super.call(this)||this;_this.dictIndex=0;_this.dictRange=[];_this.lowerBound=0;_this.upperBound=0;_this.dictLength=0;_this.log=function(){var args=[];for(var _i=0;_i<arguments.length;_i++){args[_i]=arguments[_i]}var finalArgs=__spreadArray([],__read(args));finalArgs[0]="[short-unique-id] "+args[0];if(_this.debug===true){if(typeof console!=="undefined"&&console!==null){return console.log.apply(console,__spreadArray([],__read(finalArgs)))}}};_this.setDictionary=function(dictionary){_this.dict=dictionary;_this.dictLength=_this.dict.length;_this.counter=0};_this.seq=function(){return _this.sequentialUUID()};_this.sequentialUUID=function(){var counterDiv;var counterRem;var id="";counterDiv=_this.counter;do{counterRem=counterDiv%_this.dictLength;counterDiv=Math.trunc(counterDiv/_this.dictLength);id+=_this.dict[counterRem]}while(counterDiv!==0);_this.counter+=1;return id};_this.randomUUID=function(uuidLength){if(uuidLength===void 0){uuidLength=_this.uuidLength||DEFAULT_UUID_LENGTH}var id;var randomPartIdx;var j;if(uuidLength===null||typeof uuidLength==="undefined"||uuidLength<1){throw new Error("Invalid UUID Length Provided")}id="";for(j=0;j<uuidLength;j+=1){randomPartIdx=parseInt((Math.random()*_this.dictLength).toFixed(0),10)%_this.dictLength;id+=_this.dict[randomPartIdx]}return id};_this.availableUUIDs=function(uuidLength){if(uuidLength===void 0){uuidLength=_this.uuidLength}return parseFloat(Math.pow(__spreadArray([],__read(new Set(_this.dict))).length,uuidLength).toFixed(0))};_this.approxMaxBeforeCollision=function(rounds){if(rounds===void 0){rounds=_this.availableUUIDs(_this.uuidLength)}return parseFloat(Math.sqrt(Math.PI/2*rounds).toFixed(20))};_this.collisionProbability=function(rounds,uuidLength){if(rounds===void 0){rounds=_this.availableUUIDs(_this.uuidLength)}if(uuidLength===void 0){uuidLength=_this.uuidLength}return parseFloat((_this.approxMaxBeforeCollision(rounds)/_this.availableUUIDs(uuidLength)).toFixed(20))};_this.uniqueness=function(rounds){if(rounds===void 0){rounds=_this.availableUUIDs(_this.uuidLength)}var score=parseFloat((1-_this.approxMaxBeforeCollision(rounds)/rounds).toFixed(20));return score>1?1:score<0?0:score};_this.getVersion=function(){return _this.version};_this.stamp=function(finalLength){if(finalLength<10){throw new Error("Param finalLength must be at least 10")}var hexStamp=Math.floor(+new Date/1e3).toString(16);var idLength=finalLength-9;var rndIdx=Math.round(Math.random()*(idLength>15?15:idLength));var id=_this.randomUUID(idLength);return""+id.substr(0,rndIdx)+hexStamp+id.substr(rndIdx)+rndIdx.toString(16)};_this.parseStamp=function(stamp){if(stamp.length<10){throw new Error("Stamp length invalid")}var rndIdx=parseInt(stamp.substr(stamp.length-1,1),16);return new Date(parseInt(stamp.substr(rndIdx,8),16)*1e3)};var options=__assign(__assign({},DEFAULT_OPTIONS),argOptions);_this.counter=0;_this.debug=false;_this.dict=[];_this.version=version;var userDict=options.dictionary,shuffle=options.shuffle,length=options.length;_this.uuidLength=length;if(userDict&&userDict.length>1){_this.setDictionary(userDict)}else{var i_1;_this.dictIndex=i_1=0;Object.keys(DICT_RANGES).forEach((function(rangeType){var rangeTypeKey=rangeType;_this.dictRange=DICT_RANGES[rangeTypeKey];_this.lowerBound=_this.dictRange[0];_this.upperBound=_this.dictRange[1];for(_this.dictIndex=i_1=_this.lowerBound;_this.lowerBound<=_this.upperBound?i_1<_this.upperBound:i_1>_this.upperBound;_this.dictIndex=_this.lowerBound<=_this.upperBound?i_1+=1:i_1-=1){_this.dict.push(String.fromCharCode(_this.dictIndex))}}))}if(shuffle){var PROBABILITY_1=.5;_this.setDictionary(_this.dict.sort((function(){return Math.random()-PROBABILITY_1})))}else{_this.setDictionary(_this.dict)}_this.debug=options.debug;_this.log(_this.dict);_this.log("Generator instantiated with Dictionary Size "+_this.dictLength);return new Proxy(_this,{apply:function(target,that,args){return _this.randomUUID.apply(_this,__spreadArray([],__read(args)))}})}return ShortUniqueId}(Function);exports.DEFAULT_UUID_LENGTH=DEFAULT_UUID_LENGTH;exports.default=ShortUniqueId;Object.defineProperty(exports,"__esModule",{value:true})})); |
{ | ||
"name": "short-unique-id", | ||
"version": "4.0.2", | ||
"version": "4.2.0", | ||
"description": "Generate random or sequential UUID of any length", | ||
@@ -32,2 +32,7 @@ "keywords": [ | ||
}, | ||
"standard-version": { | ||
"scripts": { | ||
"postbump": "scripty" | ||
} | ||
}, | ||
"devDependencies": { | ||
@@ -34,0 +39,0 @@ "@rollup/plugin-json": "^4.1.0", |
@@ -177,3 +177,3 @@ # Short Unique ID (UUID) Generating Library | ||
![image depicting over 12000 weekly npm downloads](https://raw.githubusercontent.com/jeanlescure/short-unique-id/master/assets/weekly-downloads.png) | ||
![image depicting over 12000 weekly npm downloads](https://raw.githubusercontent.com/jeanlescure/short-unique-id/main/assets/weekly-downloads.png) | ||
@@ -180,0 +180,0 @@ Since this package is now reporting 12k+ npm weekly downloads, we've gone ahead and re-written the whole of it in TypeScript and made sure to package dist modules compatible with Deno, Node.js and all major Browsers. |
// Copyright 2017-2020 the Short Unique ID authors. All rights reserved. Apache license. | ||
import assert from 'assert'; | ||
import ShortUniqueId from '../dist/short-unique-id'; | ||
import ShortUniqueId from './'; | ||
@@ -6,0 +6,0 @@ const test = ( |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
608508
52