Skip to content

Commit 522d887

Browse files
committed
Use web crypto global and add Node >=20 to engines
1 parent 348b1ff commit 522d887

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

index.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,7 @@ function escapeUnsafeChars(unsafeChar) {
3333
}
3434

3535
function generateUID() {
36-
var bytes;
37-
if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
38-
bytes = crypto.getRandomValues(new Uint8Array(UID_LENGTH));
39-
} else {
40-
try {
41-
var nodeCrypto = require('crypto');
42-
bytes = nodeCrypto.randomBytes(UID_LENGTH);
43-
} catch {
44-
// We'll throw an error later
45-
}
46-
}
47-
if (!bytes) {
48-
throw new Error('Secure random number generation is not supported by this platform.');
49-
}
36+
var bytes = crypto.getRandomValues(new Uint8Array(UID_LENGTH));
5037
var result = '';
5138
for(var i=0; i<UID_LENGTH; ++i) {
5239
result += bytes[i].toString(16);

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@
2626
"homepage": "https://github.com/yahoo/serialize-javascript",
2727
"devDependencies": {
2828
"benchmark": "^2.1.4"
29+
},
30+
"engines": {
31+
"node": ">=20.0.0"
2932
}
3033
}

0 commit comments

Comments
 (0)