generate-uid
Advanced tools
Comparing version 0.1.5 to 0.1.6
23
index.js
@@ -12,7 +12,7 @@ var generateuid=(function () { | ||
if (isNode) { | ||
return nodeRandom(count) | ||
return nodeRandom(count); | ||
} else { | ||
var crypto = window.crypto || window.msCrypto | ||
if (!crypto) throw new Error("Your browser does not support window.crypto.") | ||
return browserRandom(count) | ||
var crypto = window.crypto || window.msCrypto; | ||
if (!crypto) throw new Error("Your browser does not support window.crypto."); | ||
return browserRandom(count); | ||
} | ||
@@ -23,10 +23,10 @@ } | ||
var buf = crypto.randomBytes(count); | ||
return [].slice.call(buf) | ||
return [].slice.call(buf); | ||
} | ||
function browserRandom(count) { | ||
var nativeArr = new Uint8Array(count) | ||
var crypto = window.crypto || window.msCrypto | ||
crypto.getRandomValues(nativeArr) | ||
return [].slice.call(nativeArr) | ||
var nativeArr = new Uint8Array(count); | ||
var crypto = window.crypto || window.msCrypto; | ||
crypto.getRandomValues(nativeArr); | ||
return [].slice.call(nativeArr); | ||
} | ||
@@ -93,3 +93,6 @@ | ||
function _uid(cryptoBytes=false) { | ||
function _uid(cryptoBytes) { | ||
if(typeof cryptoBytes=="undefined"){ | ||
cryptoBytes=false; | ||
} | ||
var now = Date.now(); | ||
@@ -96,0 +99,0 @@ var timestamp = now;//(now).toString(16); |
{ | ||
"name": "generate-uid", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "generate unique id", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
3512
96