1 | "use strict";
|
---|
2 |
|
---|
3 | exports.__esModule = true;
|
---|
4 | exports["default"] = void 0;
|
---|
5 | var _ramda = require("ramda");
|
---|
6 | var pathToAscendSort = (0, _ramda.pipe)(_ramda.path, _ramda.ascend);
|
---|
7 | var mapPathsToAscendSort = (0, _ramda.map)(pathToAscendSort);
|
---|
8 |
|
---|
9 | /**
|
---|
10 | * Sort a list of objects by a list of paths (if first path value is equivalent, sort by second, etc).
|
---|
11 | *
|
---|
12 | * @func sortByPaths
|
---|
13 | * @memberOf RA
|
---|
14 | * @since {@link https://char0n.github.io/ramda-adjunct/3.1.0|v3.1.0}
|
---|
15 | * @category List
|
---|
16 | * @sig [[k]] -> [{k: v}] -> [{k: v}]
|
---|
17 | * @param {Array.<Array.<string>>} paths A list of paths in the list param to sort by
|
---|
18 | * @param {Array.<object>} list A list of objects to be sorted
|
---|
19 | * @return {Array.<object>} A new list sorted by the paths in the paths param
|
---|
20 | * @example
|
---|
21 | *
|
---|
22 | * const alice = {
|
---|
23 | * name: 'Alice',
|
---|
24 | * address: {
|
---|
25 | * street: 31,
|
---|
26 | * zipCode: 97777,
|
---|
27 | * },
|
---|
28 | * };
|
---|
29 | * const bob = {
|
---|
30 | * name: 'Bob',
|
---|
31 | * address: {
|
---|
32 | * street: 31,
|
---|
33 | * zipCode: 55555,
|
---|
34 | * },
|
---|
35 | * };
|
---|
36 | * const clara = {
|
---|
37 | * name: 'Clara',
|
---|
38 | * address: {
|
---|
39 | * street: 32,
|
---|
40 | * zipCode: 90210,
|
---|
41 | * },
|
---|
42 | * };
|
---|
43 | * const people = [clara, bob, alice]
|
---|
44 | *
|
---|
45 | * RA.sortByPaths([
|
---|
46 | * ['address', 'street'],
|
---|
47 | * ['address', 'zipCode'],
|
---|
48 | * ], people); // => [bob, alice, clara]
|
---|
49 | *
|
---|
50 | * RA.sortByPaths([
|
---|
51 | * ['address', 'zipCode'],
|
---|
52 | * ['address', 'street'],
|
---|
53 | * ], people); // => [bob, clara, alice]
|
---|
54 | */
|
---|
55 |
|
---|
56 | var sortByPaths = (0, _ramda.useWith)(_ramda.sortWith, [mapPathsToAscendSort, _ramda.identity]);
|
---|
57 | var _default = sortByPaths;
|
---|
58 | exports["default"] = _default; |
---|