const byteToHex = [];
const REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
for (let i = 0; i < 256; ++i) {
byteToHex.push((i + 0x100).toString(16).slice(1));
}
function validate(uuid) {
return typeof uuid === 'string' && REGEX.test(uuid);
}
function unsafeStringifyWithLower(arr, offset = 0) {
return (
byteToHex[arr[offset + 0]] +
byteToHex[arr[offset + 1]] +
byteToHex[arr[offset + 2]] +
byteToHex[arr[offset + 3]] +
'-' +
byteToHex[arr[offset + 4]] +
byteToHex[arr[offset + 5]] +
'-' +
byteToHex[arr[offset + 6]] +
byteToHex[arr[offset + 7]] +
'-' +
byteToHex[arr[offset + 8]] +
byteToHex[arr[offset + 9]] +
'-' +
byteToHex[arr[offset + 10]] +
byteToHex[arr[offset + 11]] +
byteToHex[arr[offset + 12]] +
byteToHex[arr[offset + 13]] +
byteToHex[arr[offset + 14]] +
byteToHex[arr[offset + 15]]
).toLowerCase();
}
function unsafeStringifyWithoutLower(arr, offset = 0) {
return (
byteToHex[arr[offset + 0]] +
byteToHex[arr[offset + 1]] +
byteToHex[arr[offset + 2]] +
byteToHex[arr[offset + 3]] +
'-' +
byteToHex[arr[offset + 4]] +
byteToHex[arr[offset + 5]] +
'-' +
byteToHex[arr[offset + 6]] +
byteToHex[arr[offset + 7]] +
'-' +
byteToHex[arr[offset + 8]] +
byteToHex[arr[offset + 9]] +
'-' +
byteToHex[arr[offset + 10]] +
byteToHex[arr[offset + 11]] +
byteToHex[arr[offset + 12]] +
byteToHex[arr[offset + 13]] +
byteToHex[arr[offset + 14]] +
byteToHex[arr[offset + 15]]
);
}
function stringifyV1(arr, offset = 0) {
const uuid = unsafeStringifyWithLower(arr, offset);
if (!validate(uuid)) {
throw TypeError('Stringified UUID is invalid');
}
return uuid;
}
function stringifyV2(arr, offset = 0) {
const uuid = unsafeStringifyWithoutLower(arr, offset);
if (!validate(uuid)) {
throw TypeError('Stringified UUID is invalid');
}
return uuid;
}
function stringifyV3(arr, offset = 0) {
const uuid = unsafeStringifyWithoutLower(arr, offset).toLowerCase();
if (!validate(uuid)) {
throw TypeError('Stringified UUID is invalid');
}
return uuid;
}
const arr0 = [ 3, 40, 59, 47, 22, 224, 64, 77, 128, 102, 91, 169, 76, 248, 1, 70]
const arr1 = [212, 78, 50, 20, 193, 216, 64, 205, 128, 108, 7, 232, 156, 122, 194, 127]
const arr2 = [195, 134, 237, 159, 29, 92, 64, 173, 128, 71, 146, 180, 222, 111, 192, 148]
const arr3 = [100, 139, 125, 55, 172, 9, 64, 28, 128, 86, 110, 141, 153, 30, 211, 162]
const arr4 = [225, 121, 244, 123, 155, 21, 64, 54, 128, 90, 25, 183, 93, 177, 131, 43]
const arr5 = [ 39, 241, 115, 24, 80, 106, 64, 181, 128, 132, 116, 27, 179, 149, 242, 138]
const arr6 = [105, 171, 60, 124, 8, 74, 64, 14, 128, 97, 85, 210, 220, 189, 98, 164]
const arr7 = [238, 160, 161, 151, 182, 120, 64, 87, 128, 103, 247, 69, 94, 89, 230, 154]
const arr8 = [104, 174, 48, 51, 117, 207, 64, 57, 128, 209, 143, 15, 19, 187, 64, 255]
const arr9 = [158, 53, 73, 107, 10, 33, 64, 58, 128, 252, 135, 226, 72, 200, 16, 68]