UNPKG

@bitrix24/b24jssdk

Version:

Bitrix24 REST API JavaScript SDK

55 lines (53 loc) 2.08 kB
/** * @package @bitrix24/b24jssdk * @version 1.1.0 * @copyright (c) 2026 Bitrix24 * @license MIT * @see https://github.com/bitrix24/b24jssdk * @see https://bitrix24.github.io/b24jssdk/ */ var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); const byteToHex = []; for (let i = 0; i < 256; ++i) { byteToHex.push((i + 256).toString(16).slice(1)); } function sfc32(a, b, c, d) { return () => { a |= 0; b |= 0; c |= 0; d |= 0; const t = (a + b | 0) + d | 0; d = d + 1 | 0; a = b ^ b >>> 9; b = c + (c << 3) | 0; c = (c << 21 | c >>> 11) + t | 0; return t >>> 0; }; } __name(sfc32, "sfc32"); function uuidv7() { const bytes = new Uint8Array(16); const timestamp = BigInt(Date.now()); const perf = BigInt(Math.floor(performance.now() * 1e3) % 65535); const combinedTime = timestamp << 16n | perf; bytes[0] = Number(combinedTime >> 40n & 0xFFn); bytes[1] = Number(combinedTime >> 32n & 0xFFn); bytes[2] = Number(combinedTime >> 24n & 0xFFn); bytes[3] = Number(combinedTime >> 16n & 0xFFn); bytes[4] = Number(combinedTime >> 8n & 0xFFn); bytes[5] = Number(combinedTime & 0xFFn); const seed = (Math.random() * 4294967295 ^ Date.now() ^ performance.now()) >>> 0; const rand = sfc32(2654435769, 608135816, 3084996962, seed); const randView = new DataView(bytes.buffer); randView.setUint32(6, rand()); randView.setUint32(10, rand()); randView.setUint16(14, rand()); bytes[6] = 112 | bytes[6] & 15; bytes[8] = 128 | bytes[8] & 63; return (byteToHex[bytes[0]] + byteToHex[bytes[1]] + byteToHex[bytes[2]] + byteToHex[bytes[3]] + "-" + byteToHex[bytes[4]] + byteToHex[bytes[5]] + "-" + byteToHex[bytes[6]] + byteToHex[bytes[7]] + "-" + byteToHex[bytes[8]] + byteToHex[bytes[9]] + "-" + byteToHex[bytes[10]] + byteToHex[bytes[11]] + byteToHex[bytes[12]] + byteToHex[bytes[13]] + byteToHex[bytes[14]] + byteToHex[bytes[15]]).toLowerCase(); } __name(uuidv7, "uuidv7"); export { uuidv7 as default }; //# sourceMappingURL=uuidv7.mjs.map