Skip to content

Commit

Permalink
Use globalThis if available (#34)
Browse files Browse the repository at this point in the history
* Use globalThis if available

Use [globalThis](https://developer.mozilla.org/en-US/docs/Web/API/crypto_property) if available.

Closes #29

* Update browser.js

Co-authored-by: Niklas Shepper Persson <[email protected]>

---------

Co-authored-by: Niklas Shepper Persson <[email protected]>
Co-authored-by: Daniel Cousens <[email protected]>
  • Loading branch information
3 people authored Jul 26, 2023
1 parent c967173 commit b4eb412
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function oldBrowser () {
throw new Error('Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11')
}

const crypto = global.crypto || global.msCrypto
const _global = typeof globalThis !== 'undefined' ? globalThis : global
const crypto = _global.crypto || _global.msCrypto

if (crypto && crypto.getRandomValues) {
module.exports = randomBytes
Expand Down Expand Up @@ -46,4 +47,4 @@ function randomBytes (size, cb) {
}

return bytes
}
}

0 comments on commit b4eb412

Please sign in to comment.