@applitools/utils
Advanced tools
+48
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.uuid = void 0; | ||
| const isNode = () => typeof process !== 'undefined' && process.versions != null && process.versions.node != null; | ||
| const isWebCryptoAvailable = () => typeof window !== 'undefined' && window.crypto != null && typeof window.crypto.randomUUID === 'function'; | ||
| const generateNodeUUID = () => { | ||
| // We use a dynamic require('crypto') here to ensure this code doesn't break | ||
| // when bundled for a browser environment, which does not have a 'crypto' module. | ||
| // A static, top-level `import crypto from 'crypto'` would cause bundler errors. | ||
| const cryptoModule = 'crypto'; | ||
| const crypto = require(cryptoModule); | ||
| // Use the modern, fast method if available (Node.js >= 14.17.0) | ||
| if (typeof crypto.randomUUID === 'function') { | ||
| return crypto.randomUUID(); | ||
| } | ||
| // Fallback for older Node.js versions using the still-secure randomBytes. | ||
| const bytes = crypto.randomBytes(16); | ||
| // Set the version to 4 as per RFC 4122 | ||
| bytes[6] = (bytes[6] & 0x0f) | 0x40; | ||
| // Set the variant to RFC 4122 | ||
| bytes[8] = (bytes[8] & 0x3f) | 0x80; | ||
| const hex = bytes.toString('hex'); | ||
| return [ | ||
| hex.substring(0, 8), | ||
| hex.substring(8, 12), | ||
| hex.substring(12, 16), | ||
| hex.substring(16, 20), | ||
| hex.substring(20), | ||
| ].join('-'); | ||
| }; | ||
| const generateFallbackUUID = () => { | ||
| return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => { | ||
| const r = (Math.random() * 16) | 0; | ||
| const v = c === 'x' ? r : (r & 0x3) | 0x8; | ||
| return v.toString(16); | ||
| }); | ||
| }; | ||
| /** | ||
| * Generates a UUID v4 string (cryptographically secure if possible). | ||
| */ | ||
| const uuid = () => { | ||
| if (isNode()) | ||
| return generateNodeUUID(); | ||
| if (isWebCryptoAvailable()) | ||
| return window.crypto.randomUUID(); | ||
| return generateFallbackUUID(); | ||
| }; | ||
| exports.uuid = uuid; |
| /** | ||
| * Generates a UUID v4 string (cryptographically secure if possible). | ||
| */ | ||
| export declare const uuid: () => string; |
+7
-0
| # Changelog | ||
| ## [1.11.1](https://github.com/Applitools-Dev/sdk/compare/js/utils@1.11.0...js/utils@1.11.1) (2025-08-12) | ||
| ### Bug Fixes | ||
| * downgrade uuid to 9.0.1 ([#3169](https://github.com/Applitools-Dev/sdk/issues/3169)) ([30be8e3](https://github.com/Applitools-Dev/sdk/commit/30be8e35802b2c8bc970f62fdbd2d128f5a77fb7)) | ||
| ## [1.11.0](https://github.com/Applitools-Dev/sdk/compare/js/utils@1.10.0...js/utils@1.11.0) (2025-08-05) | ||
@@ -4,0 +11,0 @@ |
+2
-2
@@ -29,3 +29,3 @@ "use strict"; | ||
| const types = __importStar(require("./types")); | ||
| const uuid_1 = require("uuid"); | ||
| const uuid_1 = require("./uuid"); | ||
| function getEnvValue(name, type) { | ||
@@ -67,3 +67,3 @@ if (!process) | ||
| function guid() { | ||
| return (0, uuid_1.v4)(); | ||
| return (0, uuid_1.uuid)(); | ||
| } | ||
@@ -70,0 +70,0 @@ exports.guid = guid; |
+1
-5
| { | ||
| "name": "@applitools/utils", | ||
| "version": "1.11.0", | ||
| "version": "1.11.1", | ||
| "keywords": [ | ||
@@ -60,7 +60,3 @@ "applitools", | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@types/uuid": "^9.0.1", | ||
| "uuid": "^11.1.0" | ||
| } | ||
| } |
97142
2.39%0
-100%33
6.45%1756
3.05%12
9.09%- Removed
- Removed
- Removed
- Removed