@carbon/ibm-products
Version:
Carbon for IBM Products
21 lines (19 loc) • 738 B
JavaScript
/**
* Copyright IBM Corp. 2020, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
//#region src/global/js/utils/uuidv4.js
/**
* Copyright IBM Corp. 2024, 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.
*/
function uuidv4(prefix = "") {
const randomValues = (c) => typeof crypto !== "undefined" ? crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4 : Math.random() * 16 >> c / 4;
return `${prefix}${"10000000-1000-4000-8000-100000000000".replace(/[018]/g, (c) => (c ^ randomValues(c)).toString(16))}`;
}
//#endregion
exports.default = uuidv4;