Comparing version 1.0.5 to 1.0.6
@@ -6,4 +6,6 @@ /* | ||
*/ | ||
var randomBytes = require('crypto').randomBytes | ||
var randomBytes = require('crypto').randomBytes; | ||
var DEBUG = false; | ||
// Older (pre 0.6) versions of Node don't have a randomBytes function | ||
@@ -34,2 +36,11 @@ if (!randomBytes) { | ||
function toString(buffer) { | ||
var str = ''; | ||
var i; | ||
for(i = 0; i < buffer.length; i++) { | ||
str = str + ALPHABET_SHUFFLED[buffer[i]]; | ||
} | ||
return str; | ||
} | ||
/** | ||
@@ -41,3 +52,3 @@ * Generate the id | ||
var seconds = Date.now() - LESS_TIME >> 10; //divide by 10 to get seconds | ||
var seconds = Math.round((Date.now() - LESS_TIME) * 0.01); // using >> got us negative numbers somehow | ||
@@ -59,16 +70,22 @@ counter = seconds == previousSeconds ? counter + 1 : 0; | ||
encode(options.version); | ||
DEBUG && console.log('just version', toString(buffer)); | ||
encode(options.worker); | ||
DEBUG && console.log('worker', toString(buffer)); | ||
if (counter > 0) { | ||
encode(counter); | ||
DEBUG && console.log('counter', toString(buffer)); | ||
} | ||
encode(seconds); //seconds since this module was created. >> 10 removes the milliseconds more or less. | ||
DEBUG && console.log('seconds', toString(buffer), seconds); | ||
previousSeconds = seconds; | ||
var str = ''; | ||
var i; | ||
for(i = 0; i < buffer.length; i++) { | ||
str = str + ALPHABET_SHUFFLED[buffer[i]]; | ||
} | ||
return str; | ||
return toString(buffer); | ||
} | ||
@@ -75,0 +92,0 @@ |
{ | ||
"name":"shortid", | ||
"version":"1.0.5", | ||
"version":"1.0.6", | ||
"description":"Amazingly short non-sequential url-friendly unique id generator.", | ||
@@ -5,0 +5,0 @@ "keywords": ["short", "tiny", "id", "uuid", "bitly", "shorten", "mongoid", "shortid", "tinyid", "id"], |
Sorry, the diff of this file is not supported yet
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
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
30384
182