UNPKG

843 BJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.unique = unique;
7exports.objectSortedEntries = objectSortedEntries;
8exports.objectSortedEntriesDeep = objectSortedEntriesDeep;
9
10function unique(array) {
11 return [...new Set(array)];
12}
13
14function objectSortedEntries(obj) {
15 return Object.entries(obj).sort(([keyA], [keyB]) => keyA.localeCompare(keyB));
16}
17
18function objectSortedEntriesDeep(object) {
19 let sortedEntries = objectSortedEntries(object);
20
21 for (let i = 0; i < sortedEntries.length; i++) {
22 sortedEntries[i][1] = sortEntry(sortedEntries[i][1]);
23 }
24
25 return sortedEntries;
26}
27
28function sortEntry(entry) {
29 if (Array.isArray(entry)) {
30 return entry.map(sortEntry);
31 }
32
33 if (typeof entry === 'object' && entry != null) {
34 return objectSortedEntriesDeep(entry);
35 }
36
37 return entry;
38}
\No newline at end of file