* Type ordering for deterministic cross-type comparisons: * undefined < null < boolean < number < string < object * * When comparing values of different types that cannot be coerced, * this ordering is used to provide stable, predictable results.
(value: unknown)
| 27 | * this ordering is used to provide stable, predictable results. |
| 28 | */ |
| 29 | function getTypeOrder(value: unknown): number { |
| 30 | if (value === undefined) return 0; |
| 31 | if (value === null) return 1; |
| 32 | if (typeof value === "boolean") return 2; |
| 33 | if (typeof value === "number") return 3; |
| 34 | if (typeof value === "string") return 4; |
| 35 | if (typeof value === "object") return 5; |
| 36 | return 6; // symbol, function, bigint, etc. |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Compares two values and returns a number indicating their relative order. |