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 1.1.1 to 2.0.0

.eslintrc.js

3

dist/short-unique-id.min.js

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

(function(){var _ShortUniqueId=function _ShortUniqueId(options){var self=this;this.DEFAULT_RANDOM_ID_LEN=6;this.DICT_RANGES={digits:[48,58],lowerCase:[97,123],upperCase:[65,91]};this.dict=[];this.log=function log(){var args=[],len=arguments.length;while(len--)args[len]=arguments[len];args[0]="[short-unique-id] "+args[0];if(this.debug===true){if(typeof console!=="undefined"&&console!==null){return console.log.apply(console,args)}}return undefined};this.getDict=function getDict(){return this.dict};this.sequentialUUID=function sequentialUUID(){var counterDiv;var counterRem;var id;id="";counterDiv=this.counter;while(true){counterRem=counterDiv%self.dictLength;counterDiv=parseInt(counterDiv/self.dictLength,10);id+=self.dict[counterRem];if(counterDiv===0){break}}this.counter+=1;return id};this.randomUUID=function randomUUID(uuidLength){var id;var randomPartIdx;var _j;if(uuidLength===null||typeof uuidLength==="undefined"){uuidLength=this.DEFAULT_RANDOM_ID_LEN}if(uuidLength===null||typeof uuidLength==="undefined"||uuidLength<1){throw new Error("Invalid UUID Length Provided")}var idIndex;id="";for(idIndex=_j=0;0<=uuidLength?_j<uuidLength:_j>uuidLength;idIndex=0<=uuidLength?++_j:--_j){randomPartIdx=parseInt(Math.random()*self.dictLength)%self.dictLength;id+=self.dict[randomPartIdx]}return id};this.dictIndex=this._i=0;var rangeType;for(rangeType in self.DICT_RANGES){self.dictRange=self.DICT_RANGES[rangeType];self.lowerBound=self.dictRange[0],self.upperBound=self.dictRange[1];for(this.dictIndex=this._i=this.lowerBound;this.lowerBound<=this.upperBound?this._i<this.upperBound:this._i>this.upperBound;this.dictIndex=this.lowerBound<=this.upperBound?++this._i:--this._i){self.dict.push(String.fromCharCode(self.dictIndex))}}this.dict=this.dict.sort(function(){return Math.random()<=.5});this.dictLength=this.dict.length;if(options===null||typeof options==="undefined"){options={}}this.counter=0;this.debug=options.debug;this.log("Generator created with Dictionary Size "+this.dictLength)};if(typeof module!=="undefined"&&typeof module.exports!=="undefined"){module.exports=_ShortUniqueId}else if(typeof define==="function"&&define.amd){define([],function(){return _ShortUniqueId})}else{window.ShortUniqueId=_ShortUniqueId}})();
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("short-unique-id",[],e):"object"==typeof exports?exports["short-unique-id"]=e():t["short-unique-id"]=e()}(window,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){t.exports=n(1)},function(t,e,n){"use strict";function r(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}n.r(e);var u={digits:[48,58],lowerCase:[97,123],upperCase:[65,91]};e.default=function t(){var e,n=this,c=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};o(this,t),i(this,"counter",0),i(this,"debug",void 0),i(this,"dict",[]),i(this,"log",(function(){for(var t=arguments.length,e=new Array(t),o=0;o<t;o++)e[o]=arguments[o];var i,u=[].concat(e);if((u[0]="[short-unique-id] ".concat(e[0]),!0===n.debug)&&("undefined"!=typeof console&&null!==console))return(i=console).log.apply(i,r(u))})),i(this,"getDict",(function(){return n.dict})),i(this,"sequentialUUID",(function(){var t,e,r;for(r="",t=n.counter;e=t%n.dictLength,t=parseInt(t/n.dictLength,10),r+=n.dict[e],0!==t;);return n.counter+=1,r})),i(this,"randomUUID",(function(){var t,e,r,o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:6;if(null==o||o<1)throw new Error("Invalid UUID Length Provided");for(t="",r=0;0<=o?r<o:r>o;0<=o?r+=1:r-=1)e=parseInt(Math.random()*n.dictLength)%n.dictLength,t+=n.dict[e];return t})),this.dictIndex=e=0,Object.keys(u).forEach((function(t){for(n.dictRange=u[t],n.lowerBound=n.dictRange[0],n.upperBound=n.dictRange[1],n.dictIndex=e=n.lowerBound;n.lowerBound<=n.upperBound?e<n.upperBound:e>n.upperBound;n.dictIndex=n.lowerBound<=n.upperBound?e+=1:e-=1)n.dict.push(String.fromCharCode(n.dictIndex))})),this.dict=this.dict.sort((function(){return Math.random()-.5})),this.dictLength=this.dict.length,this.counter=0,this.debug=c.debug,this.log(this.dict),this.log("Generator instantiated with Dictionary Size ".concat(this.dictLength))}}])}));
//# sourceMappingURL=short-unique-id.min.js.map
{
"name": "short-unique-id",
"version": "1.1.1",
"description": "Short UUID Generator with browser and ES6 import support",
"version": "2.0.0",
"main": "dist/short-unique-id.min.js",
"license": "MIT",
"module": "src/index.js",
"scripts": {
"prepublish": "npm run build",
"build": "npm run lint && npm run test && npm run build:dist",
"build:dist": "npm run build:lib && uglifyjs ./lib/short-unique-id.js > ./dist/short-unique-id.min.js",
"build:lib": "buble ./src/short-unique-id.js > ./lib/short-unique-id.js",
"test": "npm run build:lib && jasmine",
"lint": "eslint -c .eslintrc.json ./src"
"build": "webpack --mode production",
"test": "jest",
"lint": "eslint --format codeframe --ext mjs,js src test",
"dist:update": "rm -rf ./dist && cp -r ./build ./dist",
"dist:commit": "git add ./dist && git commit -m \"dist updated\"",
"deploy": "yarn test && yarn build && yarn dist:update && yarn dist:commit && yarn publish"
},
"repository": {
"type": "git",
"url": "git+https://github.com/jeanlescure/short-unique-id.git"
},
"keywords": [
"short",
"uuid",
"short-uid",
"short-uuid",
"node",
"es6",
"browser"
],
"author": "Jean M. Lescure",
"license": "MIT",
"bugs": {
"url": "https://github.com/jeanlescure/short-unique-id/issues"
},
"homepage": "https://github.com/jeanlescure/short-unique-id#readme",
"devDependencies": {
"buble": "^0.15.2",
"eslint": "^3.19.0",
"eslint-config-airbnb-base": "11.1.3",
"eslint-plugin-html": "2.0.1",
"eslint-plugin-import": "2.2.0",
"eslint-plugin-jsdoc": "3.0.2",
"jasmine": "^2.6.0",
"uglify-js": "^3.0.4"
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@neutrinojs/airbnb-base": "^9.1.0",
"@neutrinojs/jest": "^9.1.0",
"@neutrinojs/library": "^9.1.0",
"babel-jest": "^25.1.0",
"eslint": "^6",
"jest": "^25",
"neutrino": "^9.1.0",
"webpack": "^4",
"webpack-chain": "^6.4.0",
"webpack-cli": "^3"
}
}
# Short Unique ID Generator
## With ES6 imports, Node.js, and browser support
This is a straight up manual transpilation to ES6 of the [short-uid](https://github.com/serendipious/nodejs-short-uid) npm package by [Ankit Kuwadekar](https://github.com/serendipious/).
This started as a straight up manual transpilation to ES6 of the [short-uid](https://github.com/serendipious/nodejs-short-uid) npm package by [Ankit Kuwadekar](https://github.com/serendipious/).
## Why?
![image depicting over 5000 weekly npm downloads](/assets/weekly-downloads.png)
The above linked repository has gone stale, no updates in the past 2 years (as of writing this README).
Since my package is now reporting between 4k and 5k+ npm weekly downloads, I've gone ahead and refactored the package using [Neutrino JS](https://neutrinojs.org/).
If used in a ES6 environment it fails to follow good `import` standards.
## V2.x
Even so, the functionality is still useful. So here we are.
Version 2.0 was mainly a refactor of the original branch, so functionality and naming conventions have been kept the same.
Even so, there are still **breaking changes**, mainly the removal of the `lib` build output, as well as changes on how to instantiate the library on the browser.
## Instantiation (Server-side)

@@ -52,6 +54,19 @@

<script>
var uid = new ShortUniqueId();
var ShortUniqueId = window['short-unique-id'].default;
var uid = new ShortUniqueId({debug: true});
</script>
```
## Options
There are three options available on instantiation:
```javascript
const options = {
dictionary: ['Z', 'a', 'p', 'h', 'o', 'd' ...], // User-defined dictionary
skipShuffle: false, // If true, sequentialUUID will iterate over the dictionary in the given order
debug: false, // If true the instance will console.log useful info
};
```
## Usage

@@ -86,3 +101,3 @@

```
npm run lint
yarn lint
```

@@ -95,5 +110,6 @@

```
npm run build
yarn build
yarn dist:update
```
This will update the `short-unique-id.js` file under `./lib`, which will then be minified as the `short-unique-id.min.js` file under the `./dist` directory.
This will generate the `short-unique-id.min.js` file under the `./dist` directory.
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