UNPKG

848 BJavaScriptView Raw
1/**
2 * Convert array of 16 byte values to UUID string format of the form:
3 * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
4 */
5const byteToHex = [];
6
7for (let i = 0; i < 256; ++i) {
8 byteToHex.push((i + 0x100).toString(16).substr(1));
9}
10
11function bytesToUuid(buf, offset) {
12 const i = offset || 0;
13 const bth = byteToHex; // Note: Be careful editing this code! It's been tuned for performance
14 // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
15
16 return (bth[buf[i + 0]] + bth[buf[i + 1]] + bth[buf[i + 2]] + bth[buf[i + 3]] + '-' + bth[buf[i + 4]] + bth[buf[i + 5]] + '-' + bth[buf[i + 6]] + bth[buf[i + 7]] + '-' + bth[buf[i + 8]] + bth[buf[i + 9]] + '-' + bth[buf[i + 10]] + bth[buf[i + 11]] + bth[buf[i + 12]] + bth[buf[i + 13]] + bth[buf[i + 14]] + bth[buf[i + 15]]).toLowerCase();
17}
18
19export default bytesToUuid;
\No newline at end of file