| 1 |
import { unsafeStringify } from './stringify.js'; |
| 2 |
import v1 from './v1.js'; |
| 3 |
import v1ToV6 from './v1ToV6.js'; |
| 4 |
function v6(options, buf, offset) { |
| 5 |
options ??= {}; |
| 6 |
offset ??= 0; |
| 7 |
let bytes = v1({ ...options, _v6: true }, new Uint8Array(16)); |
| 8 |
bytes = v1ToV6(bytes); |
| 9 |
if (buf) { |
| 10 |
if (offset < 0 || offset + 16 > buf.length) { |
| 11 |
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`); |
| 12 |
} |
| 13 |
for (let i = 0; i < 16; i++) { |
| 14 |
buf[offset + i] = bytes[i]; |
| 15 |
} |
| 16 |
return buf; |
| 17 |
} |
| 18 |
return unsafeStringify(bytes); |
| 19 |
} |
| 20 |
export default v6; |