[d24f17c] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | exports.__esModule = true;
|
---|
| 4 | exports["default"] = void 0;
|
---|
| 5 | var _ramda = require("ramda");
|
---|
| 6 | var _sortByProps = _interopRequireDefault(require("./sortByProps"));
|
---|
| 7 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 8 | /**
|
---|
| 9 | * Sort a list of objects by a property.
|
---|
| 10 | *
|
---|
| 11 | * @func sortByProp
|
---|
| 12 | * @memberOf RA
|
---|
| 13 | * @since {@link https://char0n.github.io/ramda-adjunct/3.4.0|v3.4.0}
|
---|
| 14 | * @category List
|
---|
| 15 | * @sig k -> [{k: v}] -> [{k: v}]
|
---|
| 16 | * @param {Array.<string>} prop The property in the list param to sort by
|
---|
| 17 | * @param {Array.<object>} list A list of objects to be sorted
|
---|
| 18 | * @return {Array.<object>} A new list sorted by the property in the prop param
|
---|
| 19 | * @example
|
---|
| 20 | *
|
---|
| 21 | * // sorting list of tuples
|
---|
| 22 | * const sortByFirstItem = sortByProp(0);
|
---|
| 23 | * const listOfTuples = [[-1, 1], [-2, 2], [-3, 3]];
|
---|
| 24 | * sortByFirstItem(listOfTuples); // => [[-3, 3], [-2, 2], [-1, 1]]
|
---|
| 25 | *
|
---|
| 26 | * // sorting list of objects
|
---|
| 27 | * const sortByName = sortByProp('name');
|
---|
| 28 | * const alice = {
|
---|
| 29 | * name: 'ALICE',
|
---|
| 30 | * age: 101,
|
---|
| 31 | * };
|
---|
| 32 | * const bob = {
|
---|
| 33 | * name: 'Bob',
|
---|
| 34 | * age: -10,
|
---|
| 35 | * };
|
---|
| 36 | * const clara = {
|
---|
| 37 | * name: 'clara',
|
---|
| 38 | * age: 314.159,
|
---|
| 39 | * };
|
---|
| 40 | * const people = [clara, bob, alice];
|
---|
| 41 | * sortByName(people); // => [alice, bob, clara]
|
---|
| 42 | */
|
---|
| 43 |
|
---|
| 44 | var addValueInAnArray = (0, _ramda.append)(_ramda.__, []);
|
---|
| 45 | var sortByProp = (0, _ramda.useWith)(_sortByProps["default"], [addValueInAnArray, _ramda.identity]);
|
---|
| 46 | var _default = sortByProp;
|
---|
| 47 | exports["default"] = _default; |
---|