import { parse as parse$1, stringify as stringify$1 } from "json-custom-numbers";
import { readonly } from "./valita.js";
import { lazy, record, union, null as _null, string, number, bigint, boolean, array } from "@badrap/valita";
function numberParser(_, v2) {
  const n = +v2;
  if (n >= Number.MIN_SAFE_INTEGER && n <= Number.MAX_SAFE_INTEGER) return n;
  if (v2.indexOf(".") !== -1 || v2.indexOf("e") !== -1 || v2.indexOf("E") !== -1)
    return n;
  return BigInt(v2);
}
const jsonValueSchema = lazy(() => {
  const jsonObjectSchema2 = readonly(record(jsonValueSchema));
  return union(
    _null(),
    string(),
    number(),
    bigint(),
    boolean(),
    readonly(array(jsonValueSchema)),
    jsonObjectSchema2
  );
});
const jsonObjectSchema = readonly(record(jsonValueSchema));
function parse(str, reviver) {
  return parse$1(str, reviver, numberParser);
}
function customSerializer(_, v2, type) {
  if (type === "bigint") return v2.toString();
}
function stringify(obj, replacer, indent) {
  return stringify$1(obj, replacer, indent, customSerializer);
}
const BigIntJSON = {
  parse,
  stringify
};
export {
  BigIntJSON,
  jsonObjectSchema,
  jsonValueSchema,
  parse,
  stringify
};
//# sourceMappingURL=bigint-json.js.map
