Node updated. Some todos.

This commit is contained in:
Norm Rasmussen
2024-09-23 20:52:09 -04:00
parent 8bfaca8375
commit f25622067f
2041 changed files with 124145 additions and 110445 deletions

View File

@ -16,7 +16,10 @@
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.uuidv4 = void 0;
exports.uuidv4 = uuidv4;
function bytesToHex(bytes) {
return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');
}
/**
* Generates a random v4 UUID, as specified in RFC4122.
*
@ -36,21 +39,20 @@ function uuidv4() {
}
const randomValues = new Uint8Array(16);
if ('crypto' in globalThis && 'getRandomValues' in globalThis.crypto) {
// Node with
// Node (>=18) with
// https://nodejs.org/dist/latest-v20.x/docs/api/globals.html#crypto_1 or
// browser.
globalThis.crypto.getRandomValues(randomValues);
}
else {
// Node without
// Node (<=16) without
// https://nodejs.org/dist/latest-v20.x/docs/api/globals.html#crypto_1.
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-require-imports
require('crypto').webcrypto.getRandomValues(randomValues);
}
// Set version (4) and variant (RFC4122) bits.
randomValues[6] = (randomValues[6] & 0x0f) | 0x40;
randomValues[8] = (randomValues[8] & 0x3f) | 0x80;
const bytesToHex = (bytes) => bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');
return [
bytesToHex(randomValues.subarray(0, 4)),
bytesToHex(randomValues.subarray(4, 6)),
@ -59,5 +61,4 @@ function uuidv4() {
bytesToHex(randomValues.subarray(10, 16)),
].join('-');
}
exports.uuidv4 = uuidv4;
//# sourceMappingURL=uuid.js.map