Comparing version 2.2.6 to 2.2.7
@@ -6,13 +6,5 @@ 'use strict'; | ||
var decode = require('./decode'); | ||
var build = require('./build'); | ||
var isValid = require('./is-valid'); | ||
// Ignore all milliseconds before a certain time to reduce the size of the date entropy without sacrificing uniqueness. | ||
// This number should be updated every year or so to keep the generated id short. | ||
// To regenerate `new Date() - 0` and bump the version. Always bump the version! | ||
var REDUCE_TIME = 1459707606518; | ||
// don't change unless we change the algos or REDUCE_TIME | ||
// must be an integer and less than 16 | ||
var version = 6; | ||
// if you are using cluster or multiple servers use this to make each instance | ||
@@ -24,37 +16,3 @@ // has a unique value for worker | ||
// Counter is used when shortid is called multiple times in one second. | ||
var counter; | ||
// Remember the last time shortid was called in case counter is needed. | ||
var previousSeconds; | ||
/** | ||
* Generate unique id | ||
* Returns string id | ||
*/ | ||
function generate() { | ||
var str = ''; | ||
var seconds = Math.floor((Date.now() - REDUCE_TIME) * 0.001); | ||
if (seconds === previousSeconds) { | ||
counter++; | ||
} else { | ||
counter = 0; | ||
previousSeconds = seconds; | ||
} | ||
str = str + encode(alphabet.lookup, version); | ||
str = str + encode(alphabet.lookup, clusterWorkerId); | ||
if (counter > 0) { | ||
str = str + encode(alphabet.lookup, counter); | ||
} | ||
str = str + encode(alphabet.lookup, seconds); | ||
return str; | ||
} | ||
/** | ||
* Set the seed. | ||
@@ -94,2 +52,9 @@ * Highly recommended if you don't want people to try to figure out your id schema. | ||
/** | ||
* Generate unique id | ||
* Returns string id | ||
*/ | ||
function generate() { | ||
return build(clusterWorkerId); | ||
} | ||
@@ -96,0 +61,0 @@ // Export all other functions as properties of the generate function |
{ | ||
"name": "shortid", | ||
"version": "2.2.6", | ||
"version": "2.2.7", | ||
"description": "Amazingly short non-sequential url-friendly unique id generator.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -185,3 +185,3 @@ ## shortid [![Build Status](http://img.shields.io/travis/dylang/shortid.svg)](https://travis-ci.org/dylang/shortid) [![shortid](http://img.shields.io/npm/dm/shortid.svg)](https://www.npmjs.org/package/shortid) | ||
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 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. | ||
@@ -188,0 +188,0 @@ |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
22751
17
317
1