import { JSONStringify, RangeError, TypeError, } from "ext:core/primordials"; import { op_fjson_apply, op_fjson_parse, op_fjson_stringify, } from "ext:core/ops"; const JSONParse = JSON.parse; const ParseError = SyntaxError; export function parse(source: string): unknown { const result = op_fjson_parse(`${source}`); if (result[1] !== null) throw new ParseError(result[1]); return JSONParse(result[0]); } export function stringify(value: unknown): string { const json = JSONStringify(value); if (json === undefined) throw new TypeError("Value is not JSON serializable"); const result = op_fjson_stringify(json); if (result[1] !== null) { const ErrorClass = result[2] ? RangeError : TypeError; throw new ErrorClass(result[1]); } return result[0]; } export function apply(source: string, ...overrides: Record[]): string { return op_fjson_apply(`${source}`, overrides); }