UNPKG

es-toolkit

Version:

A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.

23 lines (22 loc) 617 B
//#region src/compat/_internal/compareValues.ts function getPriority(a) { if (typeof a === "symbol") return 1; if (a === null) return 2; if (a === void 0) return 3; if (a !== a) return 4; return 0; } const compareValues = (a, b, order) => { if (a !== b) { const aPriority = getPriority(a); const bPriority = getPriority(b); if (aPriority === bPriority && aPriority === 0) { if (a < b) return order === "desc" ? 1 : -1; if (a > b) return order === "desc" ? -1 : 1; } return order === "desc" ? bPriority - aPriority : aPriority - bPriority; } return 0; }; //#endregion export { compareValues };