UNPKG

@carbon/ibm-products

Version:

Carbon for IBM Products

21 lines (15 loc) 704 B
/** * Copyright IBM Corp. 2020, 2025 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); // https://stackoverflow.com/a/2117523 function uuidv4() { let prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; const randomValues = c => typeof crypto !== 'undefined' ? crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4 : Math.random() * 16 >> c / 4; return `${prefix}${([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ randomValues(c)).toString(16))}`; } exports.default = uuidv4;