UNPKG

declarative-js

Version:

_declarative-js_ is modern JavaScript library, that helps to: - tackle array transformation with built in JavaScript array api (e.g. `array.filter(toBe.unique())`), - provide a type-level solution for representing optional values instead of null referen

99 lines (98 loc) 2.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function comparatorValue(order, value) { var index = order.indexOf(value); return index === -1 ? order.length : index; } /** * @ignore * @internal */ function sortByConditions() { var conditions = []; for (var _i = 0; _i < arguments.length; _i++) { conditions[_i] = arguments[_i]; } return function (a, b) { for (var index = 0; index < conditions.length; index++) { var _a = conditions[index], order = _a.order, toValue = _a.toValue; var aa = comparatorValue(order, toValue(a)); var bb = comparatorValue(order, toValue(b)); if (aa !== bb) { return aa > bb ? 1 : -1; } } return 0; }; } exports.sortByConditions = sortByConditions; /** * @ignore */ function sortByPropertyAndPriority(key, values) { return function (a, b) { var aa = comparatorValue(values, a[key]); var bb = comparatorValue(values, b[key]); if (aa !== bb) { return aa > bb ? 1 : -1; } return 0; }; } exports.sortByPropertyAndPriority = sortByPropertyAndPriority; /** * @ignore */ function sortByGetters(numbers) { return function () { var mappersArr = []; for (var _i = 0; _i < arguments.length; _i++) { mappersArr[_i] = arguments[_i]; } return function (a, b) { for (var index = 0; index < mappersArr.length; index++) { var mapper = mappersArr[index]; var aa = mapper(a); var bb = mapper(b); if (aa !== bb) { return aa > bb ? numbers.true : numbers.false; } } return 0; }; }; } exports.sortByGetters = sortByGetters; /** * @ignore */ function sortByKeyValues(numbers) { return function () { var keys = []; for (var _i = 0; _i < arguments.length; _i++) { keys[_i] = arguments[_i]; } return function (a, b) { for (var index = 0; index < keys.length; index++) { var key = keys[index]; var aa = a[key]; var bb = b[key]; if (aa !== bb) { return aa > bb ? numbers.true : numbers.false; } } return 0; }; }; } exports.sortByKeyValues = sortByKeyValues;