@langchain/core
Version:
Core LangChain.js abstractions and schemas
34 lines (33 loc) • 1.4 kB
JavaScript
import parse from "./parse.js";
import { unsafeStringify } from "./stringify.js";
//#region src/utils/uuid/v35.ts
function stringToBytes(str) {
str = unescape(encodeURIComponent(str));
const bytes = new Uint8Array(str.length);
for (let i = 0; i < str.length; ++i) bytes[i] = str.charCodeAt(i);
return bytes;
}
const DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
const URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
function v35(version, hash, value, namespace, buf, offset) {
const valueBytes = typeof value === "string" ? stringToBytes(value) : value;
const namespaceBytes = typeof namespace === "string" ? parse(namespace) : namespace;
if (typeof namespace === "string") namespace = parse(namespace);
if (namespace?.length !== 16) throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");
let bytes = new Uint8Array(16 + valueBytes.length);
bytes.set(namespaceBytes);
bytes.set(valueBytes, namespaceBytes.length);
bytes = hash(bytes);
bytes[6] = bytes[6] & 15 | version;
bytes[8] = bytes[8] & 63 | 128;
if (buf) {
offset ??= 0;
if (offset < 0 || offset + 16 > buf.length) throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
for (let i = 0; i < 16; ++i) buf[offset + i] = bytes[i];
return buf;
}
return unsafeStringify(bytes);
}
//#endregion
export { DNS, URL, v35 as default };
//# sourceMappingURL=v35.js.map