@techmely/utils
Version:
Collection of helpful JavaScript / TypeScript utils
27 lines (24 loc) • 669 B
JavaScript
import { isNumber } from './chunk-N7YWL7WT.mjs';
// src/sortData.ts
function sortData(a, b, direction = "ASC" /* ASC */, options) {
let result = 0;
const { locale = "vi", shouldIgnoreZero = false } = options || {};
if (shouldIgnoreZero) {
if (a === b) {
return 0;
}
if (a === 0) {
return 1;
}
if (b === 0) {
return -1;
}
}
if (isNumber(a) && isNumber(b)) {
const aParsed = a?.toString() ?? "";
const bParsed = b?.toString() ?? "";
result = isNumber(a) && isNumber(b) ? a - b : aParsed.localeCompare(bParsed, locale);
}
return direction === "ASC" /* ASC */ ? result : -result;
}
export { sortData };