Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

get-random-values

kenany904.6kMIT3.0.0TypeScript support: included

window.crypto.getRandomValues with fallback to Node.js crypto

crypto

readme

get-random-values

window.crypto.getRandomValues or window.msCrypto.getRandomValues or require('crypto').randomBytes or an Error.

Example

var getRandomValues = require('get-random-values');

var array = new Uint32Array(10);
getRandomValues(array);
// => [
// =>   183,
// =>   76,
// =>   18,
// =>   177,
// =>   73,
// =>   9,
// =>   50,
// =>   248,
// =>   216,
// =>   104
// => ]

Installation

$ npm install get-random-values

API

var getRandomValues = require('get-random-values');

getRandomValues(buf)

Fills integer-based TypedArray buf with cryptographically random numbers. Checks for and uses the first of the following:

  • window.crypto.getRandomValues
  • window.msCrypto.getRandomValues
  • Node.js crypto

If none of the above are available, then an Error is thrown.

Throws QuotaExceededError if buf.length > 65536 (even if Node.js crypto, 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.

changelog

3.0.0 (2023-09-21)

⚠ BREAKING CHANGES

  • Node.js v14 and v16 are no longer supported.

Features

  • drop Node.js v14 and v16 (329c91b)

2.1.0 (2023-03-26)

Features

  • add TypeScript declarations (9a7f39f)

2.0.0 (2022-06-25)

⚠ BREAKING CHANGES

  • Node.js v10 and v12 are no longer supported.

Features

  • drop Node.js v10 and v12 support (1e727b9)

1.2.2 (2020-08-25)

Bug Fixes

  • update copyright year to 2020 (4761fef)

1.2.1 (2020-08-25)

Bug Fixes