UNPKG

jsoncmp

Version:

Fast and type-safe deep comparison for JSON-compatible data.

32 lines (30 loc) 1.13 kB
/** * A value that is valid in a JSON structure: string, number, boolean, null, * array of JSON values or a plain object with JSON values. */ type JSONCmpValue = number | string | boolean | null | JSONCmpArray | JSONCmpObject; /** * An array of JSON-compatible values. */ type JSONCmpArray = JSONCmpValue[]; /** * A plain object whose property values are all JSON-compatible. */ interface JSONCmpObject { [key: string]: JSONCmpValue | undefined; } /** * Compares two JSON-compatible values for deep structural equality. * * This function supports only the following value types: * number, string, boolean, null, arrays, and plain objects (no functions, symbols, etc.). * * The comparison is optimized based on runtime heuristics for V8 and JavaScriptCore. * * @param target - The first value to compare * @param source - The second value to compare * @returns `true` if both values are structural identical, otherwise `false` */ declare function jsoncmp(target: JSONCmpValue, source: JSONCmpValue): boolean; export { jsoncmp as default }; export type { JSONCmpArray, JSONCmpObject, JSONCmpValue };