Installations
npm install js-shortid
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
5.6.0
NPM Version
3.6.0
Score
68
Supply Chain
58.2
Quality
74.9
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
zzzhan
Download Statistics
Total Downloads
227,904
Last Day
25
Last Week
119
Last Month
833
Last Year
39,560
GitHub Statistics
172 Stars
9 Commits
18 Forks
9 Watching
1 Branches
2 Contributors
Bundle Size
1.20 kB
Minified
667.00 B
Minified + Gzipped
Package Meta Information
Latest Version
0.1.1
Package Id
js-shortid@0.1.1
Size
1.45 kB
NPM Version
3.6.0
Node Version
5.6.0
Total Downloads
Cumulative downloads
Total Downloads
227,904
Last day
-16.7%
25
Compared to previous day
Last week
-40.5%
119
Compared to previous week
Last month
7.3%
833
Compared to previous month
Last year
-45.1%
39,560
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
js-shortid
Short id generator. UUID generator. Url-friendly. Non-predictable.
Quick Start
1npm test
Install
If you are using bower, you can download the source like this:
1bower install js-shortid --save
js-shortid
is available in the npm repository.
1npm install js-shortid --save
Usage
-
node.js:
1var shortid=require('shortid'); 2console.log(shortid.gen());
-
browser:
1var sid = shortid.gen(); 2console.log(sid);
Short ID Samples
R6zw8Hly
R6AhD4Jw
R6Cip4M3
R6Ej09A1
R6Fjw3Q4
R6FP04jv
R6IlvZRb
R6LCSXn8
R6NT1Syx
R6O8RN67
Overview
The solution of shortid is clearly the simplest. It is constructed by the character strings:timeseq
+salts
.
The timeseq
is a time sequence since 2016-04-11(default initial time), and converted it to Base 62 string.The time sequence can be increased per millisecond, per second, per minute so on that depends on the option value interval
, default value is 1
(increase per millisecond).
The salts
is constructed by salt1+salt2+...
, each salt
is a random number and converted to Base 62 string(only two charaters).How many salts
will be append to that depends on the option values salts
,default is 2
(four charaters).More salts
of the id more closed to be a UUID, but more longer of the id.
Generally,if the timeseq
is increased per millisecond and the salts is 4
,the id is almost closed to a UUID.
Options
options.salts
Type: Integer
Default value: '2'
The value that is used to generate the salts
count.
options.interval
Type: Integer
Default value: '1'
The value that is the timeseq
increased millisecond interval.1000
is increased per second,1000*60
is per minute, so on.If less than zero, there are not timeseq
.
options.initTime
Type: Long
Default value: '1460332800000'
The value that is the epoch of the timeseq
.The default is millisecond of 2016-04-11
.
Options Usage Examples
General
1var inst = shortid.inst({salts:3,interval:1000}); 2console.log(inst.gen());
Quick Style
1//default option {salts:2,interval:1} 2console.log(shortid.gen()); 3//custom option 4console.log(shortid.gen({salts:3,interval:1000})); 5//default option {salts:4,interval:1} 6console.log(shortid.uuid());
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 1/8 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 2 are checked with a SAST tool
Score
2.7
/10
Last Scanned on 2025-01-20
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More