Skip to content

Commit 0304f1d

Browse files
authored
Merge pull request #48 from giuseppeg/fix-support-detection-node
Fix `crypto` support detection doesn't work with jest
2 parents a372928 + 9531b6a commit 0304f1d

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,18 @@ function factory(prng) {
8181

8282
/* istanbul ignore next */
8383
function _prng(root) {
84+
var crypto = root && (root.crypto || root.msCrypto)
8485

85-
if (root) {
86+
if (crypto) {
8687
try {
87-
var crypto = root.crypto || root.msCrypto
8888
return function() {
8989
return crypto.getRandomValues(new Uint16Array(1))[0] / 0xFFFF
9090
}
9191
}
9292
catch (e) {}
9393
} else {
9494
try {
95-
var crypto = require("crypto")
95+
crypto = require("crypto")
9696
return function() {
9797
return crypto.randomBytes(2).readUInt16LE() / 0xFFFF
9898
}

0 commit comments

Comments
 (0)