Security News
npm Updates Search Experience with New Objective Sorting Options
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
Amazingly short non-sequential human-friendly unique id generator.
ShortId32 creates amazingly short non-sequential human-friendly unique ids. Perfect for url shorteners, and any other id users might see.
A-Z
, 0-9
, excluding the commonly confused 01OI
cluster
(automatically), custom seeds, custom alphabet.var shortid = require('shortid32');
console.log(shortid.generate());
//PPBQWA9
The best way to use shortid32
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:
## build the bundle, then open Mocha in a browser to see the tests run.
$ grunt build open
~/projects/shortid ❯ node examples/examples.js
WKTQBXJF
QKCTWBXJF
WKZVQMXJP
Q3ATWB5CF
QK5VQMXCP
WKQVQMXJF
Q3FTQB5CP
WK6VWM5JF
QKGTWBXCF
W3TVWBXJP
var shortid = require('shortid32');
shortid.generate()
Returns string
non-sequential unique id.
Example
users.insert({
_id: shortid.generate()
name: ...
email: ...
});
characters(string)
Default: '23456789ABCDEFGHJKLMNPQRSTUVWXYZ'
Returns new alphabet as a string
Optional
Change the characters used.
You must provide a string of all 32 unique characters. Order is not important.
The default characters provided were selected because they are human friendly.
Example
// any 32 unicode characters work, but I wouldn't recommend this.
shortid.characters('ⒶⒷⒸⒹⒺⒻⒼⒽⒿⓀⓁⓂⓃⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏ②③④⑤⑥⑦⑧⑨');
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
shortid.isValid('43XTDBE');
// true
shortid.isValid('i have spaces');
// 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 theatrically 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
shortId.seed(1000);
shortid.seed(float)
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
shortId.seed(1000);
This is a modification of shortid
. The original author of that software is Dylan Greene.
Copyright (c) 2015 Dylan Greene, contributors.
Released under the MIT license.
Screenshots are CC BY-SA (Attribution-ShareAlike).
FAQs
Amazingly short non-sequential human-friendly unique id generator.
The npm package shortid36 receives a total of 0 weekly downloads. As such, shortid36 popularity was classified as not popular.
We found that shortid36 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.