get-random-values
Advanced tools
Comparing version 1.1.1 to 1.2.0
14
index.js
@@ -6,8 +6,11 @@ var window = require('global/window'); | ||
if (window.crypto && window.crypto.getRandomValues) { | ||
window.crypto.getRandomValues(buf); | ||
return window.crypto.getRandomValues(buf); | ||
} | ||
else if (typeof window.msCrypto === 'object' && typeof window.msCrypto.getRandomValues === 'function') { | ||
window.msCrypto.getRandomValues(buf); | ||
if (typeof window.msCrypto === 'object' && typeof window.msCrypto.getRandomValues === 'function') { | ||
return window.msCrypto.getRandomValues(buf); | ||
} | ||
else if (nodeCrypto.randomBytes) { | ||
if (nodeCrypto.randomBytes) { | ||
if (!(buf instanceof Uint8Array)) { | ||
throw new TypeError('expected Uint8Array'); | ||
} | ||
if (buf.length > 65536) { | ||
@@ -24,2 +27,3 @@ var e = new Error(); | ||
buf.set(bytes); | ||
return buf; | ||
} | ||
@@ -31,2 +35,2 @@ else { | ||
module.exports = getRandomValues; | ||
module.exports = getRandomValues; |
@@ -1,2 +0,2 @@ | ||
Copyright 2014 Kenan Yildirim <http://kenany.me/> | ||
Copyright 2014–2016 Kenan Yildirim <http://kenany.me/> | ||
@@ -18,2 +18,2 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
{ | ||
"name": "get-random-values", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "`window.crypto.getRandomValues` with fallback to Node.js crypto", | ||
@@ -26,20 +26,10 @@ "keywords": [ | ||
"devDependencies": { | ||
"lodash.foreach": "^2.4.1", | ||
"lodash.isfunction": "^2.4.1", | ||
"tape": "^2.14.0" | ||
"is-browser": "^2.0.1", | ||
"lodash.foreach": "^3.0.3", | ||
"lodash.isfunction": "^3.0.6", | ||
"tape": "^4.4.0" | ||
}, | ||
"browser": { | ||
"crypto": false | ||
}, | ||
"testling": { | ||
"files": "test/*.js", | ||
"browsers": [ | ||
"chrome/11..latest", | ||
"firefox/21..latest", | ||
"safari/4.0..latest", | ||
"opera/15.0..latest", | ||
"iphone/6", | ||
"ipad/6" | ||
] | ||
} | ||
} | ||
} |
@@ -9,4 +9,2 @@ # get-random-values | ||
[![testling badge](https://ci.testling.com/KenanY/get-random-values.png)](https://ci.testling.com/KenanY/get-random-values) | ||
## Example | ||
@@ -57,2 +55,5 @@ | ||
Throws _QuotaExceededError_ if `buf.length > 65536` (even if Node.js crypto, | ||
which doesn't have that limit, is being used). | ||
which doesn't have that limit, is being used). | ||
`buf` **must** be a _Uint8Array_ if Node.js crypto is used, otherwise a | ||
_TypeError_ will be thrown. |
31
58
4219
4