@azure/core-util
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -5,6 +5,11 @@ // Copyright (c) Microsoft Corporation. | ||
import { randomUUID as v4RandomUUID } from "crypto"; | ||
import { generateUUID } from "./uuidUtils.native"; | ||
// NOTE: This is a workaround until we can use `globalThis.crypto.randomUUID` in Node.js 19+. | ||
const uuidFunction = typeof ((_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.crypto) === null || _a === void 0 ? void 0 : _a.randomUUID) === "function" | ||
let uuidFunction = typeof ((_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.crypto) === null || _a === void 0 ? void 0 : _a.randomUUID) === "function" | ||
? globalThis.crypto.randomUUID.bind(globalThis.crypto) | ||
: v4RandomUUID; | ||
// Not defined in earlier versions of Node.js 14 | ||
if (!uuidFunction) { | ||
uuidFunction = generateUUID; | ||
} | ||
/** | ||
@@ -11,0 +16,0 @@ * Generated Universally Unique Identifier |
@@ -207,7 +207,43 @@ 'use strict'; | ||
// Licensed under the MIT license. | ||
/** | ||
* Generated Universally Unique Identifier | ||
* | ||
* @returns RFC4122 v4 UUID. | ||
*/ | ||
function generateUUID() { | ||
let uuid = ""; | ||
for (let i = 0; i < 32; i++) { | ||
// Generate a random number between 0 and 15 | ||
const randomNumber = Math.floor(Math.random() * 16); | ||
// Set the UUID version to 4 in the 13th position | ||
if (i === 12) { | ||
uuid += "4"; | ||
} | ||
else if (i === 16) { | ||
// Set the UUID variant to "10" in the 17th position | ||
uuid += (randomNumber & 0x3) | 0x8; | ||
} | ||
else { | ||
// Add a random hexadecimal digit to the UUID string | ||
uuid += randomNumber.toString(16); | ||
} | ||
// Add hyphens to the UUID string at the appropriate positions | ||
if (i === 7 || i === 11 || i === 15 || i === 19) { | ||
uuid += "-"; | ||
} | ||
} | ||
return uuid; | ||
} | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
var _a; | ||
// NOTE: This is a workaround until we can use `globalThis.crypto.randomUUID` in Node.js 19+. | ||
const uuidFunction = typeof ((_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.crypto) === null || _a === void 0 ? void 0 : _a.randomUUID) === "function" | ||
let uuidFunction = typeof ((_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.crypto) === null || _a === void 0 ? void 0 : _a.randomUUID) === "function" | ||
? globalThis.crypto.randomUUID.bind(globalThis.crypto) | ||
: crypto.randomUUID; | ||
// Not defined in earlier versions of Node.js 14 | ||
if (!uuidFunction) { | ||
uuidFunction = generateUUID; | ||
} | ||
/** | ||
@@ -214,0 +250,0 @@ * Generated Universally Unique Identifier |
{ | ||
"name": "@azure/core-util", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Core library for shared utility methods", | ||
@@ -5,0 +5,0 @@ "sdk-type": "client", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
87205
902