LendAndRegret/node_modules/es-toolkit/dist/compat/_internal/compareValues.js
2026-05-02 17:27:43 +08:00

38 lines
862 B
JavaScript

'use strict';
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
function getPriority(a) {
if (typeof a === 'symbol') {
return 1;
}
if (a === null) {
return 2;
}
if (a === undefined) {
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;
};
exports.compareValues = compareValues;