UNPKG

dtable-utils

Version:

dtable common utils

23 lines (20 loc) 641 B
import { SORT_TYPE } from '../../constants/sort.js'; /** * Sort checkbox * @param {bool} leftChecked * @param {bool} rightChecked * @param {string} sortType e.g. 'up' | 'down * @returns number */ var sortCheckbox = function sortCheckbox(leftChecked, rightChecked, sortType) { var normalizedCurrChecked = leftChecked ? 1 : -1; var normalizedNextChecked = rightChecked ? 1 : -1; if (normalizedCurrChecked > normalizedNextChecked) { return sortType === SORT_TYPE.UP ? 1 : -1; } if (normalizedCurrChecked < normalizedNextChecked) { return sortType === SORT_TYPE.UP ? -1 : 1; } return 0; }; export { sortCheckbox };