get-random-values 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## [4.0.0](https://github.com/kenany/get-random-values/compare/3.0.0...4.0.0) (2025-08-13)
2
+
3
+ ### ⚠ BREAKING CHANGES
4
+
5
+ * Node.js v18 is no longer supported.
6
+
7
+ ### Features
8
+
9
+ * drop Node.js v18 support ([ddef386](https://github.com/kenany/get-random-values/commit/ddef386fc0bc842f1e6eed6beac8dea6947f3655))
10
+
1
11
  ## [3.0.0](https://github.com/kenany/get-random-values/compare/2.1.0...3.0.0) (2023-09-21)
2
12
 
3
13
 
package/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2014–2023 Kenan Yildirim <https://kenany.me/>
1
+ Copyright 2014–2025 Kenan Yildirim <https://kenany.me/>
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of
4
4
  this software and associated documentation files (the "Software"), to deal in
package/README.md CHANGED
@@ -6,9 +6,9 @@
6
6
  ## Example
7
7
 
8
8
  ``` javascript
9
- var getRandomValues = require('get-random-values');
9
+ const getRandomValues = require('get-random-values');
10
10
 
11
- var array = new Uint32Array(10);
11
+ const array = new Uint32Array(10);
12
12
  getRandomValues(array);
13
13
  // => [
14
14
  // => 183,
@@ -33,7 +33,7 @@ $ npm install get-random-values
33
33
  ## API
34
34
 
35
35
  ``` javascript
36
- var getRandomValues = require('get-random-values');
36
+ const getRandomValues = require('get-random-values');
37
37
  ```
38
38
 
39
39
  ### `getRandomValues(buf)`
package/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export = getRandomValues;
2
2
  /**
3
- * @template {ArrayBufferView | null} T
3
+ * @template {ArrayBufferView<ArrayBufferLike>} T
4
4
  * @param {T} buf
5
5
  * @returns {T}
6
6
  */
7
- declare function getRandomValues<T extends ArrayBufferView | null>(buf: T): T;
7
+ declare function getRandomValues<T extends ArrayBufferView<ArrayBufferLike>>(buf: T): T;
package/index.js CHANGED
@@ -1,41 +1,46 @@
1
- /* eslint-disable no-var, operator-linebreak */
2
-
3
- var window = require('global/window');
4
- var nodeCrypto = require('crypto');
1
+ const window = require('global/window');
2
+ const nodeCrypto = require('node:crypto');
5
3
 
6
4
  /**
7
- * @template {ArrayBufferView | null} T
5
+ * @template {ArrayBufferView<ArrayBufferLike>} T
8
6
  * @param {T} buf
9
7
  * @returns {T}
10
8
  */
11
9
  function getRandomValues(buf) {
12
- if (window.crypto && window.crypto.getRandomValues) {
10
+ if (window.crypto?.getRandomValues) {
13
11
  return window.crypto.getRandomValues(buf);
14
12
  }
15
- if (typeof window.msCrypto === 'object' && typeof window.msCrypto.getRandomValues === 'function') {
13
+
14
+ if (
15
+ typeof window.msCrypto === 'object' &&
16
+ typeof window.msCrypto.getRandomValues === 'function'
17
+ ) {
16
18
  return window.msCrypto.getRandomValues(buf);
17
19
  }
20
+
18
21
  if (nodeCrypto.randomBytes) {
19
22
  if (!(buf instanceof Uint8Array)) {
20
23
  throw new TypeError('expected Uint8Array');
21
24
  }
22
- if (buf.length > 65536) {
23
- var e = new Error();
25
+ if (buf.length > 65_536) {
26
+ const e = new Error(
27
+ "Failed to execute 'getRandomValues' on 'Crypto': The " +
28
+ "ArrayBufferView's byte length (" +
29
+ buf.length +
30
+ ') exceeds the ' +
31
+ 'number of bytes of entropy available via this API (65536).'
32
+ );
24
33
  // @ts-expect-error
25
34
  e.code = 22;
26
- e.message = 'Failed to execute \'getRandomValues\' on \'Crypto\': The ' +
27
- 'ArrayBufferView\'s byte length (' + buf.length + ') exceeds the ' +
28
- 'number of bytes of entropy available via this API (65536).';
29
35
  e.name = 'QuotaExceededError';
30
36
  throw e;
31
37
  }
32
- var bytes = nodeCrypto.randomBytes(buf.length);
38
+ const bytes = nodeCrypto.randomBytes(buf.length);
33
39
  buf.set(bytes);
34
40
  return buf;
35
41
  }
36
- else {
37
- throw new Error('No secure random number generator available.');
38
- }
42
+
43
+ throw new Error('No secure random number generator available.');
39
44
  }
40
45
 
41
46
  module.exports = getRandomValues;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "get-random-values",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "description": "`window.crypto.getRandomValues` with fallback to Node.js crypto",
5
5
  "keywords": [
6
6
  "crypto"
@@ -20,11 +20,11 @@
20
20
  "test": "test"
21
21
  },
22
22
  "engines": {
23
- "node": "18 || >=20"
23
+ "node": "20 || 22 || >=24"
24
24
  },
25
25
  "scripts": {
26
26
  "clean": "rimraf --glob test/**/*.d.ts *.d.ts",
27
- "lint": "eslint .",
27
+ "lint": "biome check .",
28
28
  "release": "semantic-release",
29
29
  "type-coverage": "type-coverage --at-least 100 --detail --strict",
30
30
  "prebuild": "npm run clean",
@@ -38,21 +38,21 @@
38
38
  "global": "^4.4.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@kenan/eslint-config": "^11.0.1",
41
+ "@biomejs/biome": "2.1.4",
42
42
  "@semantic-release/changelog": "^6.0.3",
43
43
  "@semantic-release/git": "^10.0.1",
44
- "@tsconfig/node18": "^18.2.2",
45
- "@types/lodash.isfunction": "^3.0.7",
46
- "@types/tape": "^5.6.1",
47
- "conventional-changelog-conventionalcommits": "^7.0.2",
48
- "eslint": "^8.49.0",
44
+ "@tsconfig/node20": "20.1.6",
45
+ "@types/lodash.isfunction": "^3.0.9",
46
+ "@types/tape": "^5.8.1",
47
+ "conventional-changelog-conventionalcommits": "^9.1.0",
49
48
  "is-browser": "^2.1.0",
50
49
  "lodash.isfunction": "^3.0.9",
51
- "rimraf": "^5.0.1",
52
- "semantic-release": "^22.0.1",
53
- "tape": "^5.6.6",
54
- "type-coverage": "^2.26.3",
55
- "typescript": "^5.2.2"
50
+ "rimraf": "^6.0.1",
51
+ "semantic-release": "^24.2.7",
52
+ "tape": "^5.9.0",
53
+ "type-coverage": "^2.29.7",
54
+ "typescript": "^5.8.3",
55
+ "ultracite": "5.1.2"
56
56
  },
57
57
  "browser": {
58
58
  "crypto": false