@actinc/dls
Version:
Design Language System (DLS) for ACT & Encoura front-end projects.
34 lines • 1.19 kB
JavaScript
/**
* Copyright (c) ACT, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import isString from 'lodash/isString';
import SORT_DIRECTION_TYPES from "../../constants/SORT_DIRECTION_TYPES";
export function sort(_a) {
var sortBy = _a.sortBy, sortDirection = _a.sortDirection;
return function (_a, _b) {
var _c = sortBy, itemA = _a[_c];
var _d = sortBy, itemB = _b[_d];
if (itemA === null || itemB === null)
return 0;
var normalizedItemA = itemA;
var normalizedItemB = itemB;
if (isString(itemA)) {
normalizedItemA = itemA.trim().toLowerCase();
}
if (isString(itemB)) {
normalizedItemB = itemB.trim().toLowerCase();
}
if (normalizedItemA < normalizedItemB) {
return sortDirection === SORT_DIRECTION_TYPES.ASCENDING ? -1 : 1;
}
if (normalizedItemA > normalizedItemB) {
return sortDirection === SORT_DIRECTION_TYPES.ASCENDING ? 1 : -1;
}
return 0;
};
}
export default sort;
//# sourceMappingURL=index.js.map