agsamantha/node_modules/uuid/dist/v6.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-10-02 20:15:21 +00:00
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = v6;
var _stringify = require("./stringify.js");
var _v = _interopRequireDefault(require("./v1.js"));
var _v1ToV = _interopRequireDefault(require("./v1ToV6.js"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
*
* @param {object} options
* @param {Uint8Array=} buf
* @param {number=} offset
* @returns
*/
function v6(options = {}, buf, offset = 0) {
// v6 is v1 with different field layout, so we start with a v1 UUID, albeit
// with slightly different behavior around how the clock_seq and node fields
// are randomized, which is why we call v1 with _v6: true.
let bytes = (0, _v.default)({
...options,
_v6: true
}, new Uint8Array(16));
// Reorder the fields to v6 layout.
bytes = (0, _v1ToV.default)(bytes);
// Return as a byte array if requested
if (buf) {
for (let i = 0; i < 16; i++) {
buf[offset + i] = bytes[i];
}
return buf;
}
return (0, _stringify.unsafeStringify)(bytes);
}