{"version":3,"file":"compare-values.cjs","names":[],"sources":["../../src/utils/compare-values.ts"],"sourcesContent":["/**\n * One collator for every string comparison a table sort makes.\n *\n * `localeCompare(other, undefined, { numeric: true })` builds a collator per\n * call — passing an options bag opts out of the engine's cached-default fast\n * path — and a sort makes O(n log n) of these. Measured at 200k comparisons:\n * 453 ms through `localeCompare` against 25 ms through a hoisted collator.\n */\nconst TEXT_COLLATOR = new Intl.Collator(undefined, { numeric: true });\n\n/**\n * Compare two arbitrary cell values with stable, type-aware ordering.\n *\n * The comparator every table in the SDK sorts with, so `DataTable` and\n * `VirtualTable` agree on what \"sorted\" means. The type-aware branches exist\n * because the naive `String(a) < String(b)` gets the two most common cases wrong:\n * numbers would sort `10` before `9`, and dates would sort by their formatted\n * text. Strings fall back to `localeCompare` with `numeric: true`, so `\"item 2\"`\n * lands before `\"item 10\"`.\n *\n * `null` and `undefined` sort first, together — a missing value is not smaller\n * than another missing value.\n *\n * @param a - First value.\n * @param b - Second value.\n * @returns Negative when `a < b`, positive when `a > b`, zero when equal.\n */\nexport function compareValues(a: unknown, b: unknown): number {\n    if (a == null && b == null) return 0;\n    if (a == null) return -1;\n    if (b == null) return 1;\n    if (typeof a === \"number\" && typeof b === \"number\") return a - b;\n    if (a instanceof Date && b instanceof Date) return a.getTime() - b.getTime();\n    if (typeof a === \"boolean\" && typeof b === \"boolean\") return Number(a) - Number(b);\n    return TEXT_COLLATOR.compare(String(a), String(b));\n}\n"],"mappings":"AAQA,IAAM,EAAgB,IAAI,KAAK,SAAS,IAAA,GAAW,CAAE,QAAS,EAAK,CAAC,EAmBpE,SAAgB,EAAc,EAAY,EAAoB,CAO1D,OANI,GAAK,MAAQ,GAAK,KAAa,EAC/B,GAAK,KAAa,GAClB,GAAK,KAAa,EAClB,OAAO,GAAM,UAAY,OAAO,GAAM,SAAiB,EAAI,EAC3D,aAAa,MAAQ,aAAa,KAAa,EAAE,QAAQ,EAAI,EAAE,QAAQ,EACvE,OAAO,GAAM,WAAa,OAAO,GAAM,UAAkB,OAAO,CAAC,EAAI,OAAO,CAAC,EAC1E,EAAc,QAAQ,OAAO,CAAC,EAAG,OAAO,CAAC,CAAC,CACrD"}