export function stableStringify(value) {
    if (value === undefined ||
        typeof value === "function" ||
        typeof value === "symbol") {
        throw new TypeError("Cannot stable-stringify non-JSON metadata value.");
    }
    if (typeof value === "bigint") {
        throw new TypeError("Cannot stable-stringify bigint metadata value.");
    }
    if (value === null || typeof value !== "object") {
        return JSON.stringify(value);
    }
    if (Array.isArray(value)) {
        return `[${value.map((item) => stableStringify(item)).join(",")}]`;
    }
    const entries = Object.entries(value).sort(([left], [right]) => left.localeCompare(right));
    return `{${entries
        .map(([key, entryValue]) => `${JSON.stringify(key)}:${stableStringify(entryValue)}`)
        .join(",")}}`;
}
export function isRecord(value) {
    return typeof value === "object" && value !== null && !Array.isArray(value);
}
