Gathering detailed insights and metrics for shortid-extend
Gathering detailed insights and metrics for shortid-extend
Gathering detailed insights and metrics for shortid-extend
Gathering detailed insights and metrics for shortid-extend
npm install shortid-extend
Typescript
Module System
Node Version
NPM Version
71
Supply Chain
98.3
Quality
75
Maintenance
50
Vulnerability
99.6
License
Total Downloads
76,904
Last Day
3
Last Week
158
Last Month
499
Last Year
5,128
Minified
Minified + Gzipped
Latest Version
0.0.3
Package Id
shortid-extend@0.0.3
Unpacked Size
18.30 kB
Size
7.45 kB
File Count
15
NPM Version
6.4.1
Node Version
8.14.0
Cumulative downloads
Total Downloads
Last Day
-82.4%
3
Compared to previous day
Last Week
1.3%
158
Compared to previous week
Last Month
37.1%
499
Compared to previous month
Last Year
-72.2%
5,128
Compared to previous year
Amazingly short non-sequential url-friendly unique id generator.
This is a fork of the original ShortId module (https://github.com/dylang/shortid) from Dylan Greene(https://github.com/dylang) for adapt the module to my work needs.
ShortId-extend creates amazingly short non-sequential url-friendly unique ids. Perfect for url shorteners, MongoDB and Redis ids, and any other id users might see.
** NEW FUNCTIONALITY ** The module have now a config method for override the default settings for the alphabet and the default generated ID Length. IF you configure the module for have this config object overrides the default configuration and have the capability of sets the desired ID lenght also your desired alphabet lenght.
A-Z
, a-z
, 0-9
, _-
cluster
(automatically), custom seeds, custom alphabet.ShortId-extend does not generate cryptographically secure ids, so don't rely on it to make IDs which are impossible to guess.
1const shortid = require('shortid-extend'); 2 3console.log(shortid.generate()); 4// PPBqWA9
Mongoose Unique Id
1_id: { 2 'type': String, 3 'default': shortid.generate 4},
The best way to use shortid
in the browser is via browserify or webpack.
These tools will automatically only include the files necessary for browser compatibility.
All tests will run in the browser as well:
1## build the bundle, then open Mocha in a browser to see the tests run. 2$ grunt build open
1~/projects/shortid ❯ node examples/examples.js 2eWRhpRV 323TplPdS 446Juzcyx 5dBvJIh-H 62WEKaVNO 77oet_d9Z 8dogPzIz8 9nYrnfYEv 10a4vhAoFG 11hwX6aOr7
1var shortid = require('shortid');
shortid.config(object)
Params boolean
disableDefaultAlphabetLength: Disables the default characters length setting.
Params boolean
disableDefaultIdLength: Disables the default generated ID Length.
Params number
idLength: REQUIRED IF disableDefaultIdLength sets to true Desired ID Length.
Example
1shortid.config({ 2 disableDefaultAlphabetLength: true, 3 disableDefaultIdLength: true, 4 idLength: 6 5}) 6
shortid.generate()
Returns string
non-sequential unique id.
Example
1users.insert({ 2 _id: shortid.generate(), 3 name: '...', 4 email: '...' 5});
shortid.characters(string)
Default: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_'
Returns new alphabet as a string
Recommendation: If you don't like _ or -, you can to set new characters to use.
Optional
Change the characters used.
You must provide a string of all 64 unique characters. Order is not important. (You can overwrite this setting with config object)
If you sets
The default characters provided were selected because they are url safe.
Example
1// use $ and @ instead of - and _ 2shortid.characters('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$@');
1// any 64 unicode characters work, but I wouldn't recommend this. 2shortid.characters('ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ①②③④⑤⑥⑦⑧⑨⑩⑪⑫');
shortid.isValid(id)
Returns boolean
Check to see if an id is a valid shortid
. Note: This only means the id could have been generated by shortid
, it doesn't guarantee it.
Example
1shortid.isValid('41XTDbE'); 2// true
1shortid.isValid('i have spaces');
2// false
shortid.worker(integer)
Default: process.env.NODE_UNIQUE_ID || 0
Recommendation: You typically won't want to change this.
Optional
If you are running multiple server processes then you should make sure every one has a unique worker
id. Should be an integer between 0 and 16.
If you do not do this there is very little chance of two servers generating the same id, but it is theoretically possible
if both are generated in the exact same second and are generating the same number of ids that second and a half-dozen random numbers are all exactly the same.
Example
1shortid.worker(1);
shortid.seed(integer)
Default: 1
Recommendation: You typically won't want to change this.
Optional
Choose a unique value that will seed the random number generator so users won't be able to figure out the pattern of the unique ids. Call it just once in your application before using shortId
and always use the same value in your application.
Most developers won't need to use this, it's mainly for testing ShortId.
If you are worried about users somehow decrypting the id then use it as a secret value for increased encryption.
Example
1shortid.seed(1000);
Visit your Github page: https://github.com/dylang
Copyright (c) 2016 Dylan Greene, contributors.
Released under the MIT license.
Screenshots are CC BY-SA (Attribution-ShareAlike).
No vulnerabilities found.
No security vulnerabilities found.