{"version":3,"file":"compare.mjs","names":[],"sources":["../src/compare.ts"],"sourcesContent":["/* ===========================================================\n    COMPARE\n      - EQUALS\n      - COVER\n      - LESS\n      - FACTORY FUNCTIONS\n=========================================================== */\nimport { Atomic } from \"@typia/interface\";\n\nimport { NoTransformConfigurationError } from \"./transformers/NoTransformConfigurationError\";\n\n/**\n * The partial form of `T` that `typia.compare.cover` matches against.\n *\n * Atomics, null, undefined and functions stay as they are, an array becomes an\n * array of covered elements and every property of an object becomes optional\n * and covered in turn.\n *\n * @evidence contracts/common.md#principled-implementation The mapped type keeps atomics, null, undefined and functions as they are, turns an array or tuple into an array of covered elements and an object into a record whose properties are optional and covered recursively. The array branch transforms element types without encoding the original tuple length; identical compared array lengths are enforced separately by the runtime transform.\n * @evidence contracts/common.md#clear-and-simple-design One recursive conditional alias used by the `cover` signature.\n * @evidence contracts/common.md#prohibited-implementation-shortcuts A type-level description with no runtime effect; the transform decides what the call compares.\n * @evidence contracts/common.md#meaningful-documentation A comment states what the alias describes and how it relates to the cover operation.\n */\nexport type Cover<T> = T extends Atomic.Type | null | undefined\n  ? T\n  : T extends (...args: any[]) => any\n    ? T\n    : T extends readonly (infer U)[]\n      ? Cover<U>[]\n      : T extends object\n        ? { [K in keyof T]?: Cover<T[K]> }\n        : T;\n\n/* -----------------------------------------------------------\n    EQUALS\n----------------------------------------------------------- */\n/**\n * Compares two values of type `T`.\n *\n * Performs a type-directed deep equality comparison. Object properties are\n * compared by the declared structure of `T`; extra runtime properties are not\n * part of the comparison. When `T` (or a nested object type) declares an\n * `equals(y: T): boolean` method, that method is used instead of the structural\n * comparison.\n *\n * @template T Type of values to compare\n *\n * @param x Left value\n * @param y Right value\n *\n * @returns Whether both values are equal by structure\n */\nexport function equals<T>(x: T, y: T): boolean;\n\n/** @internal */\nexport function equals(): never {\n  NoTransformConfigurationError(\"compare.equals\");\n}\n\n/**\n * Compares whether `x` covers the defined structure of `y`.\n *\n * Object properties whose value is `undefined` in `y` are ignored. Arrays and\n * tuples still require identical lengths and compare element-by-element.\n *\n * @template T Type of value to compare\n *\n * @param x Full value\n * @param y Partial value to match\n *\n * @returns Whether `x` covers `y`\n */\nexport function cover<T>(x: T, y: Cover<T>): boolean;\n\n/** @internal */\nexport function cover(): never {\n  NoTransformConfigurationError(\"compare.cover\");\n}\n\n/* -----------------------------------------------------------\n    LESS\n----------------------------------------------------------- */\n/**\n * Tests whether `x` precedes `y`.\n *\n * Performs a type-directed lexicographic comparison: the properties of `T` are\n * walked in declaration order, depth-first, and the scalar leaves (`number` /\n * `boolean` / `string` / `bigint`) are compared one by one. The result is\n * decided by the first leaf where `x` and `y` differ; if every leaf is equal,\n * the result is `false` (equal is not \"less\"). When `T` (or a nested object\n * type) declares a `less(y: T): boolean` method, that method is used instead of\n * the structural comparison.\n *\n * The ordering is total and deterministic, so it composes into an\n * `Array.prototype.sort` comparator:\n *\n * ```ts\n * const cmp = (a: T, b: T): number =>\n *   typia.compare.less(a, b) ? -1 : typia.compare.less(b, a) ? 1 : 0;\n * ```\n *\n * @template T Type of values to compare\n *\n * @param x Left value\n * @param y Right value\n *\n * @returns Whether `x` precedes `y`\n */\nexport function less<T>(x: T, y: T): boolean;\n\n/** @internal */\nexport function less(): never {\n  NoTransformConfigurationError(\"compare.less\");\n}\n\n/* -----------------------------------------------------------\n    FACTORY FUNCTIONS\n----------------------------------------------------------- */\n/**\n * Creates reusable {@link equals} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createEquals(): never;\n\n/**\n * Creates reusable {@link equals} function.\n *\n * @template T Type of values to compare\n *\n * @returns Reusable equality function\n */\nexport function createEquals<T>(): (x: T, y: T) => boolean;\n\n/** @internal */\nexport function createEquals(): never {\n  NoTransformConfigurationError(\"compare.createEquals\");\n}\n\n/**\n * Creates reusable {@link cover} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createCover(): never;\n\n/**\n * Creates reusable {@link cover} function.\n *\n * @template T Type of value to compare\n *\n * @returns Reusable cover function\n */\nexport function createCover<T>(): (x: T, y: Cover<T>) => boolean;\n\n/** @internal */\nexport function createCover(): never {\n  NoTransformConfigurationError(\"compare.createCover\");\n}\n\n/**\n * Creates reusable {@link less} function.\n *\n * @danger You must configure the generic argument `T`\n */\nexport function createLess(): never;\n\n/**\n * Creates reusable {@link less} function.\n *\n * @template T Type of values to compare\n *\n * @returns Reusable ordering function\n */\nexport function createLess<T>(): (x: T, y: T) => boolean;\n\n/** @internal */\nexport function createLess(): never {\n  NoTransformConfigurationError(\"compare.createLess\");\n}\n"],"mappings":";;;;;;;;;;;;AAuDA,SAAgB,SAAgB;CAC9B,8BAA8B,gBAAgB;AAChD;;AAkBA,SAAgB,QAAe;CAC7B,8BAA8B,eAAe;AAC/C;;AAkCA,SAAgB,OAAc;CAC5B,8BAA8B,cAAc;AAC9C;;AAsBA,SAAgB,eAAsB;CACpC,8BAA8B,sBAAsB;AACtD;;AAmBA,SAAgB,cAAqB;CACnC,8BAA8B,qBAAqB;AACrD;;AAmBA,SAAgB,aAAoB;CAClC,8BAA8B,oBAAoB;AACpD"}