@oscarpalmer/atoms 0.74.1 → 0.76.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/js/array/chunk.cjs +18 -0
- package/dist/js/array/{chunk.mjs → chunk.js} +2 -2
- package/dist/js/array/compact.cjs +6 -0
- package/dist/js/array/{compact.mjs → compact.js} +0 -1
- package/dist/js/array/count.cjs +14 -0
- package/dist/js/array/count.js +14 -0
- package/dist/js/array/exists.cjs +14 -0
- package/dist/js/array/exists.js +14 -0
- package/dist/js/array/filter.cjs +14 -0
- package/dist/js/array/filter.js +14 -0
- package/dist/js/array/find.cjs +14 -0
- package/dist/js/array/find.js +14 -0
- package/dist/js/array/group-by.cjs +35 -0
- package/dist/js/array/group-by.js +35 -0
- package/dist/js/array/index-of.cjs +14 -0
- package/dist/js/array/index-of.js +14 -0
- package/dist/js/array/index.cjs +40 -0
- package/dist/js/array/index.js +34 -381
- package/dist/js/array/insert.cjs +31 -0
- package/dist/js/array/insert.js +31 -0
- package/dist/js/array/models.cjs +1 -0
- package/dist/js/array/models.js +1 -0
- package/dist/js/array/shuffle.cjs +13 -0
- package/dist/js/array/{shuffle.mjs → shuffle.js} +2 -3
- package/dist/js/array/sort.cjs +53 -0
- package/dist/js/array/{sort.mjs → sort.js} +13 -9
- package/dist/js/array/splice.cjs +14 -0
- package/dist/js/array/splice.js +14 -0
- package/dist/js/array/to-map.cjs +27 -0
- package/dist/js/array/to-map.js +27 -0
- package/dist/js/array/to-record.cjs +12 -0
- package/dist/js/array/to-record.js +12 -0
- package/dist/js/array/unique.cjs +7 -0
- package/dist/js/array/unique.js +7 -0
- package/dist/js/colour/base.cjs +18 -0
- package/dist/js/colour/{base.mjs → base.js} +4 -3
- package/dist/js/colour/functions.cjs +96 -0
- package/dist/js/colour/{functions.mjs → functions.js} +18 -19
- package/dist/js/colour/hex.cjs +56 -0
- package/dist/js/colour/{hex.mjs → hex.js} +34 -15
- package/dist/js/colour/hsl.cjs +85 -0
- package/dist/js/colour/{hsl.mjs → hsl.js} +40 -12
- package/dist/js/colour/index.cjs +29 -0
- package/dist/js/colour/index.js +14 -272
- package/dist/js/colour/is.cjs +27 -0
- package/dist/js/colour/{is.mjs → is.js} +7 -6
- package/dist/js/colour/rgb.cjs +87 -0
- package/dist/js/colour/{rgb.mjs → rgb.js} +43 -12
- package/dist/js/{emitter.mjs → emitter.cjs} +88 -56
- package/dist/js/emitter.js +85 -56
- package/dist/js/{function.mjs → function.cjs} +66 -46
- package/dist/js/function.js +61 -48
- package/dist/js/index.cjs +136 -0
- package/dist/js/index.js +133 -1724
- package/dist/js/internal/array/callbacks.cjs +23 -0
- package/dist/js/internal/array/callbacks.js +23 -0
- package/dist/js/internal/array/find.cjs +51 -0
- package/dist/js/internal/array/find.js +51 -0
- package/dist/js/internal/value/handle.cjs +21 -0
- package/dist/js/internal/{value-handle.mjs → value/handle.js} +0 -1
- package/dist/js/{is.mjs → is.cjs} +17 -18
- package/dist/js/is.js +15 -27
- package/dist/js/logger.cjs +108 -0
- package/dist/js/logger.js +44 -8
- package/dist/js/{math.mjs → math.cjs} +7 -8
- package/dist/js/math.js +4 -5
- package/dist/js/models.cjs +1 -0
- package/dist/js/models.js +1 -0
- package/dist/js/{number.mjs → number.cjs} +8 -8
- package/dist/js/number.js +5 -5
- package/dist/js/{query.mjs → query.cjs} +18 -18
- package/dist/js/query.js +17 -86
- package/dist/js/{queue.mjs → queue.cjs} +12 -13
- package/dist/js/queue.js +9 -10
- package/dist/js/{random.mjs → random.cjs} +14 -21
- package/dist/js/random.js +9 -26
- package/dist/js/{sized.mjs → sized.cjs} +68 -33
- package/dist/js/sized.js +66 -38
- package/dist/js/string/case.cjs +41 -0
- package/dist/js/string/{case.mjs → case.js} +13 -9
- package/dist/js/string/index.cjs +59 -0
- package/dist/js/string/index.js +30 -100
- package/dist/js/string/template.cjs +21 -0
- package/dist/js/string/{template.mjs → template.js} +4 -5
- package/dist/js/{touch.mjs → touch.cjs} +4 -7
- package/dist/js/touch.js +3 -5
- package/dist/js/value/clone.cjs +76 -0
- package/dist/js/value/{clone.mjs → clone.js} +5 -6
- package/dist/js/value/compare.cjs +59 -0
- package/dist/js/value/{compare.mjs → compare.js} +4 -6
- package/dist/js/value/diff.cjs +75 -0
- package/dist/js/value/{diff.mjs → diff.js} +13 -11
- package/dist/js/value/equal.cjs +106 -0
- package/dist/js/value/{equal.mjs → equal.js} +13 -8
- package/dist/js/value/get.cjs +21 -0
- package/dist/js/value/{get.mjs → get.js} +9 -4
- package/dist/js/value/index.cjs +30 -0
- package/dist/js/value/index.js +19 -510
- package/dist/js/value/merge.cjs +35 -0
- package/dist/js/value/{merge.mjs → merge.js} +7 -6
- package/dist/js/value/set.cjs +25 -0
- package/dist/js/value/{set.mjs → set.js} +3 -4
- package/dist/js/value/smush.cjs +26 -0
- package/dist/js/value/{smush.mjs → smush.js} +3 -4
- package/dist/js/value/unsmush.cjs +39 -0
- package/dist/js/value/{unsmush.mjs → unsmush.js} +10 -7
- package/package.json +50 -47
- package/src/js/array/chunk.ts +6 -5
- package/src/js/array/compact.ts +8 -10
- package/src/js/array/count.ts +39 -19
- package/src/js/array/exists.ts +39 -15
- package/src/js/array/filter.ts +42 -20
- package/src/js/array/find.ts +45 -20
- package/src/js/array/group-by.ts +158 -27
- package/src/js/array/index-of.ts +40 -18
- package/src/js/array/index.ts +10 -9
- package/src/js/array/insert.ts +28 -14
- package/src/js/array/models.ts +18 -15
- package/src/js/array/shuffle.ts +3 -3
- package/src/js/array/sort.ts +32 -34
- package/src/js/array/splice.ts +22 -26
- package/src/js/array/to-map.ts +133 -45
- package/src/js/array/to-record.ts +137 -39
- package/src/js/array/unique.ts +20 -15
- package/src/js/colour/base.ts +3 -3
- package/src/js/colour/functions.ts +4 -6
- package/src/js/colour/hex.ts +5 -5
- package/src/js/colour/hsl.ts +18 -12
- package/src/js/colour/index.ts +1 -1
- package/src/js/colour/is.ts +3 -3
- package/src/js/colour/rgb.ts +17 -11
- package/src/js/emitter.ts +12 -9
- package/src/js/function.ts +17 -17
- package/src/js/index.ts +16 -16
- package/src/js/internal/array/callbacks.ts +33 -0
- package/src/js/internal/{array-find.ts → array/find.ts} +23 -24
- package/src/js/internal/{value-handle.ts → value/handle.ts} +1 -1
- package/src/js/is.ts +2 -2
- package/src/js/logger.ts +14 -14
- package/src/js/math.ts +1 -1
- package/src/js/models.ts +5 -5
- package/src/js/number.ts +2 -2
- package/src/js/query.ts +6 -10
- package/src/js/queue.ts +1 -1
- package/src/js/random.ts +9 -19
- package/src/js/sized.ts +145 -145
- package/src/js/string/case.ts +1 -1
- package/src/js/string/index.ts +13 -7
- package/src/js/string/template.ts +6 -3
- package/src/js/value/clone.ts +3 -7
- package/src/js/value/compare.ts +3 -5
- package/src/js/value/diff.ts +4 -4
- package/src/js/value/equal.ts +2 -2
- package/src/js/value/get.ts +3 -3
- package/src/js/value/index.ts +2 -2
- package/src/js/value/merge.ts +3 -3
- package/src/js/value/set.ts +3 -4
- package/src/js/value/smush.ts +4 -4
- package/src/js/value/unsmush.ts +4 -4
- package/types/array/chunk.d.cts +8 -0
- package/types/array/chunk.d.ts +2 -2
- package/types/array/compact.d.cts +12 -0
- package/types/array/compact.d.ts +4 -4
- package/types/array/count.d.cts +24 -0
- package/types/array/count.d.ts +13 -7
- package/types/array/exists.d.cts +26 -0
- package/types/array/exists.d.ts +11 -3
- package/types/array/filter.d.cts +26 -0
- package/types/array/filter.d.ts +14 -6
- package/types/array/find.d.cts +26 -0
- package/types/array/find.d.ts +14 -6
- package/types/array/group-by.d.cts +58 -0
- package/types/array/group-by.d.ts +49 -5
- package/types/array/index-of.d.cts +26 -0
- package/types/array/index-of.d.ts +14 -6
- package/types/array/index.d.cts +239 -95
- package/types/array/index.d.ts +7 -6
- package/types/array/insert.d.cts +16 -0
- package/types/array/insert.d.ts +10 -5
- package/types/array/models.d.cts +14 -11
- package/types/array/models.d.ts +14 -12
- package/types/array/shuffle.d.cts +8 -0
- package/types/array/shuffle.d.ts +2 -2
- package/types/array/sort.d.cts +24 -0
- package/types/array/sort.d.ts +10 -10
- package/types/array/splice.d.cts +22 -0
- package/types/array/splice.d.ts +4 -4
- package/types/array/to-map.d.cts +61 -0
- package/types/array/to-map.d.ts +42 -20
- package/types/array/to-record.d.cts +61 -0
- package/types/array/to-record.d.ts +42 -20
- package/types/array/unique.d.cts +21 -0
- package/types/array/unique.d.ts +10 -6
- package/types/colour/base.d.cts +153 -0
- package/types/colour/base.d.ts +2 -2
- package/types/colour/functions.d.cts +173 -0
- package/types/colour/functions.d.ts +3 -3
- package/types/colour/hex.d.cts +157 -0
- package/types/colour/hex.d.ts +4 -4
- package/types/colour/hsl.d.cts +157 -0
- package/types/colour/hsl.d.ts +16 -10
- package/types/colour/index.d.cts +28 -16
- package/types/colour/index.d.ts +1 -1
- package/types/colour/is.d.cts +170 -0
- package/types/colour/is.d.ts +3 -3
- package/types/colour/rgb.d.cts +157 -0
- package/types/colour/rgb.d.ts +15 -9
- package/types/emitter.d.cts +11 -8
- package/types/emitter.d.ts +11 -8
- package/types/function.d.cts +10 -10
- package/types/function.d.ts +11 -11
- package/types/index.d.cts +1120 -736
- package/types/index.d.ts +16 -16
- package/types/internal/array/callbacks.d.cts +11 -0
- package/types/internal/array/callbacks.d.ts +2 -0
- package/types/internal/array/find.d.cts +7 -0
- package/types/internal/array/find.d.ts +3 -0
- package/types/internal/value/handle.d.cts +37 -0
- package/types/internal/{value-handle.d.ts → value/handle.d.ts} +1 -1
- package/types/is.d.ts +1 -1
- package/types/logger.d.cts +13 -21
- package/types/logger.d.ts +13 -21
- package/types/math.d.cts +1 -1
- package/types/math.d.ts +1 -1
- package/types/models.d.cts +4 -4
- package/types/models.d.ts +1 -4
- package/types/number.d.cts +2 -2
- package/types/number.d.ts +2 -2
- package/types/query.d.cts +2 -2
- package/types/query.d.ts +3 -3
- package/types/queue.d.cts +1 -1
- package/types/queue.d.ts +1 -1
- package/types/random.d.cts +8 -12
- package/types/random.d.ts +8 -12
- package/types/sized.d.cts +6 -6
- package/types/sized.d.ts +6 -6
- package/types/string/case.d.cts +28 -0
- package/types/string/index.d.cts +30 -27
- package/types/string/index.d.ts +3 -3
- package/types/string/template.d.cts +50 -0
- package/types/string/template.d.ts +4 -1
- package/types/value/clone.d.cts +8 -0
- package/types/value/clone.d.ts +4 -2
- package/types/value/compare.d.cts +8 -0
- package/types/value/diff.d.cts +25 -0
- package/types/value/equal.d.cts +12 -0
- package/types/value/get.d.cts +1319 -0
- package/types/value/get.d.ts +1 -1
- package/types/value/index.d.cts +8 -6
- package/types/value/index.d.ts +2 -2
- package/types/value/merge.d.cts +72 -0
- package/types/value/merge.d.ts +2 -2
- package/types/value/set.d.cts +1011 -0
- package/types/value/set.d.ts +1 -1
- package/types/value/smush.d.cts +1368 -0
- package/types/value/smush.d.ts +2 -2
- package/types/value/unsmush.d.cts +141 -0
- package/types/value/unsmush.d.ts +2 -2
- package/dist/js/array/count.mjs +0 -8
- package/dist/js/array/exists.mjs +0 -8
- package/dist/js/array/filter.mjs +0 -8
- package/dist/js/array/find.mjs +0 -8
- package/dist/js/array/group-by.mjs +0 -33
- package/dist/js/array/index-of.mjs +0 -8
- package/dist/js/array/index.mjs +0 -34
- package/dist/js/array/insert.mjs +0 -22
- package/dist/js/array/models.mjs +0 -0
- package/dist/js/array/splice.mjs +0 -9
- package/dist/js/array/to-map.mjs +0 -27
- package/dist/js/array/to-record.mjs +0 -8
- package/dist/js/array/unique.mjs +0 -8
- package/dist/js/colour/index.mjs +0 -30
- package/dist/js/index.mjs +0 -17
- package/dist/js/internal/array-callbacks.mjs +0 -19
- package/dist/js/internal/array-find.mjs +0 -51
- package/dist/js/logger.mjs +0 -69
- package/dist/js/models.mjs +0 -0
- package/dist/js/string/index.mjs +0 -44
- package/dist/js/value/index.mjs +0 -23
- package/src/js/internal/array-callbacks.ts +0 -28
- package/types/internal/array-callbacks.d.ts +0 -2
- package/types/internal/array-find.d.ts +0 -4
package/dist/js/array/index.js
CHANGED
|
@@ -1,388 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// src/js/array/insert.ts
|
|
18
|
-
function insert(array, index, values) {
|
|
19
|
-
insertValues("splice", array, values, index, 0);
|
|
20
|
-
}
|
|
21
|
-
function insertValues(type, array, values, start, deleteCount) {
|
|
22
|
-
const chunked = chunk(values);
|
|
23
|
-
const lastIndex = chunked.length - 1;
|
|
24
|
-
let index = Number(chunked.length);
|
|
25
|
-
let returned;
|
|
26
|
-
while (--index >= 0) {
|
|
27
|
-
const result = array.splice(start, index === lastIndex ? deleteCount : 0, ...chunked[index]);
|
|
28
|
-
if (returned == null) {
|
|
29
|
-
returned = result;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return type === "splice" ? returned : array.length;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// src/js/array/index.ts
|
|
1
|
+
import { insertValues } from "./insert.js";
|
|
2
|
+
import { insert } from "./insert.js";
|
|
3
|
+
import { chunk } from "./chunk.js";
|
|
4
|
+
import { compact } from "./compact.js";
|
|
5
|
+
import { count } from "./count.js";
|
|
6
|
+
import { exists } from "./exists.js";
|
|
7
|
+
import { filter } from "./filter.js";
|
|
8
|
+
import { find } from "./find.js";
|
|
9
|
+
import { groupBy } from "./group-by.js";
|
|
10
|
+
import { indexOf } from "./index-of.js";
|
|
11
|
+
import { shuffle } from "./shuffle.js";
|
|
12
|
+
import { sort } from "./sort.js";
|
|
13
|
+
import { splice } from "./splice.js";
|
|
14
|
+
import { toMap } from "./to-map.js";
|
|
15
|
+
import { toRecord } from "./to-record.js";
|
|
16
|
+
import { unique } from "./unique.js";
|
|
36
17
|
function flatten(array) {
|
|
37
18
|
return array.flat(Number.POSITIVE_INFINITY);
|
|
38
19
|
}
|
|
39
|
-
function push(array,
|
|
40
|
-
return insertValues("push", array,
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// src/js/array/compact.ts
|
|
44
|
-
function compact(array, strict) {
|
|
45
|
-
return strict === true ? array.filter((item) => !!item) : array.filter((item) => item != null);
|
|
46
|
-
}
|
|
47
|
-
// src/js/internal/array-callbacks.ts
|
|
48
|
-
function getCallbacks(bool, key) {
|
|
49
|
-
if (typeof bool === "function") {
|
|
50
|
-
return { bool };
|
|
51
|
-
}
|
|
52
|
-
if (typeof key === "function") {
|
|
53
|
-
return { key };
|
|
54
|
-
}
|
|
55
|
-
const isString = typeof key === "string";
|
|
56
|
-
if (!isString && typeof key !== "number" || isString && key.includes(".")) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
key: (value) => value?.[key]
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// src/js/internal/array-find.ts
|
|
65
|
-
function findValue(type, array, value, key) {
|
|
66
|
-
const callbacks = getCallbacks(value, key);
|
|
67
|
-
if (callbacks?.bool == null && callbacks?.key == null) {
|
|
68
|
-
return type === "index" ? array.indexOf(value) : array.find((item) => item === value);
|
|
69
|
-
}
|
|
70
|
-
if (callbacks.bool != null) {
|
|
71
|
-
const index = array.findIndex(callbacks.bool);
|
|
72
|
-
return type === "index" ? index : index > -1 ? array[index] : undefined;
|
|
73
|
-
}
|
|
74
|
-
const { length } = array;
|
|
75
|
-
for (let index = 0;index < length; index += 1) {
|
|
76
|
-
const item = array[index];
|
|
77
|
-
if (callbacks.key?.(item, index, array) === value) {
|
|
78
|
-
return type === "index" ? index : item;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return type === "index" ? -1 : undefined;
|
|
82
|
-
}
|
|
83
|
-
function findValues(type, array, value, key) {
|
|
84
|
-
const callbacks = getCallbacks(value, key);
|
|
85
|
-
const { length } = array;
|
|
86
|
-
if (type === "unique" && callbacks?.key == null && length >= 100) {
|
|
87
|
-
return Array.from(new Set(array));
|
|
88
|
-
}
|
|
89
|
-
if (typeof callbacks?.bool === "function") {
|
|
90
|
-
return array.filter(callbacks.bool);
|
|
91
|
-
}
|
|
92
|
-
if (type === "all" && key == null) {
|
|
93
|
-
return array.filter((item) => item === value);
|
|
94
|
-
}
|
|
95
|
-
const hasCallback = typeof callbacks?.key === "function";
|
|
96
|
-
const result = [];
|
|
97
|
-
const values = hasCallback ? [] : result;
|
|
98
|
-
for (let index = 0;index < length; index += 1) {
|
|
99
|
-
const item = array[index];
|
|
100
|
-
const itemKey = hasCallback ? callbacks.key?.(item, index, array) : item;
|
|
101
|
-
if (type === "all" && itemKey === value || type === "unique" && values.indexOf(itemKey) === -1) {
|
|
102
|
-
if (values !== result) {
|
|
103
|
-
values.push(itemKey);
|
|
104
|
-
}
|
|
105
|
-
result.push(item);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return result;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// src/js/array/count.ts
|
|
112
|
-
function count(array, value, key) {
|
|
113
|
-
return findValues("all", array, value, key).length;
|
|
114
|
-
}
|
|
115
|
-
// src/js/array/exists.ts
|
|
116
|
-
function exists(array, value, key) {
|
|
117
|
-
return findValue("index", array, value, key) > -1;
|
|
118
|
-
}
|
|
119
|
-
// src/js/array/filter.ts
|
|
120
|
-
function filter(array, value, key) {
|
|
121
|
-
return findValues("all", array, value, key);
|
|
122
|
-
}
|
|
123
|
-
// src/js/array/find.ts
|
|
124
|
-
function find(array, value, key) {
|
|
125
|
-
return findValue("value", array, value, key);
|
|
126
|
-
}
|
|
127
|
-
// src/js/array/group-by.ts
|
|
128
|
-
function groupBy(array, key) {
|
|
129
|
-
return groupValues(array, key, true, false);
|
|
130
|
-
}
|
|
131
|
-
function groupValues(array, key, arrays, indicable) {
|
|
132
|
-
const callbacks = getCallbacks(undefined, key);
|
|
133
|
-
const hasCallback = typeof callbacks?.key === "function";
|
|
134
|
-
if (!hasCallback && !indicable) {
|
|
135
|
-
return {};
|
|
136
|
-
}
|
|
137
|
-
const record = {};
|
|
138
|
-
const { length } = array;
|
|
139
|
-
for (let index = 0;index < length; index += 1) {
|
|
140
|
-
const value = array[index];
|
|
141
|
-
const key2 = hasCallback ? callbacks?.key?.(value, index, array) ?? index : index;
|
|
142
|
-
if (arrays) {
|
|
143
|
-
const existing = record[key2];
|
|
144
|
-
if (Array.isArray(existing)) {
|
|
145
|
-
existing.push(value);
|
|
146
|
-
} else {
|
|
147
|
-
record[key2] = [value];
|
|
148
|
-
}
|
|
149
|
-
} else {
|
|
150
|
-
record[key2] = value;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return record;
|
|
154
|
-
}
|
|
155
|
-
// src/js/array/index-of.ts
|
|
156
|
-
function indexOf(array, value, key) {
|
|
157
|
-
return findValue("index", array, value, key);
|
|
158
|
-
}
|
|
159
|
-
// src/js/random.ts
|
|
160
|
-
function getRandomFloat(min, max) {
|
|
161
|
-
const minimum = min ?? Number.MIN_SAFE_INTEGER;
|
|
162
|
-
return Math.random() * ((max ?? Number.MAX_SAFE_INTEGER) - minimum) + minimum;
|
|
163
|
-
}
|
|
164
|
-
function getRandomInteger(min, max) {
|
|
165
|
-
return Math.floor(getRandomFloat(min, max));
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// src/js/array/shuffle.ts
|
|
169
|
-
function shuffle(array) {
|
|
170
|
-
const shuffled = array.slice();
|
|
171
|
-
const { length } = shuffled;
|
|
172
|
-
for (let index = 0;index < length; index += 1) {
|
|
173
|
-
const random = getRandomInteger(0, length);
|
|
174
|
-
[shuffled[index], shuffled[random]] = [shuffled[random], shuffled[index]];
|
|
175
|
-
}
|
|
176
|
-
return shuffled;
|
|
177
|
-
}
|
|
178
|
-
// src/js/string/index.ts
|
|
179
|
-
function getString(value) {
|
|
180
|
-
if (typeof value === "string") {
|
|
181
|
-
return value;
|
|
182
|
-
}
|
|
183
|
-
if (typeof value !== "object" || value == null) {
|
|
184
|
-
return String(value);
|
|
185
|
-
}
|
|
186
|
-
const valueOff = value.valueOf?.() ?? value;
|
|
187
|
-
const asString = valueOff?.toString?.() ?? String(valueOff);
|
|
188
|
-
return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
|
|
189
|
-
}
|
|
190
|
-
function join(value, delimiter) {
|
|
191
|
-
return compact(value).map(getString).filter((value2) => value2.trim().length > 0).join(typeof delimiter === "string" ? delimiter : "");
|
|
192
|
-
}
|
|
193
|
-
function words(value) {
|
|
194
|
-
return value.match(/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g) ?? [];
|
|
195
|
-
}
|
|
196
|
-
// src/js/math.ts
|
|
197
|
-
function max(values) {
|
|
198
|
-
return values.length > 0 ? Math.max(...values) : Number.NaN;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// src/js/number.ts
|
|
202
|
-
function getNumber(value) {
|
|
203
|
-
if (typeof value === "number") {
|
|
204
|
-
return value;
|
|
205
|
-
}
|
|
206
|
-
if (typeof value === "symbol") {
|
|
207
|
-
return Number.NaN;
|
|
208
|
-
}
|
|
209
|
-
let parsed = value?.valueOf?.() ?? value;
|
|
210
|
-
if (typeof parsed === "object") {
|
|
211
|
-
parsed = parsed?.toString() ?? parsed;
|
|
212
|
-
}
|
|
213
|
-
if (typeof parsed !== "string") {
|
|
214
|
-
return parsed == null ? Number.NaN : typeof parsed === "number" ? parsed : +parsed;
|
|
215
|
-
}
|
|
216
|
-
if (/^\s*0+\s*$/.test(parsed)) {
|
|
217
|
-
return 0;
|
|
218
|
-
}
|
|
219
|
-
const trimmed = parsed.trim();
|
|
220
|
-
if (trimmed.length === 0) {
|
|
221
|
-
return Number.NaN;
|
|
222
|
-
}
|
|
223
|
-
const isBinary = /^0b[01]+$/i.test(trimmed);
|
|
224
|
-
if (isBinary || /^0o[0-7]+$/i.test(trimmed)) {
|
|
225
|
-
return Number.parseInt(trimmed.slice(2), isBinary ? 2 : 8);
|
|
226
|
-
}
|
|
227
|
-
return +(/^0x[0-9a-f]+$/i.test(trimmed) ? trimmed : trimmed.replace(/_/g, ""));
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// src/js/value/compare.ts
|
|
231
|
-
function compare(first, second) {
|
|
232
|
-
const firstParts = getParts(first);
|
|
233
|
-
const secondParts = getParts(second);
|
|
234
|
-
const length = max([firstParts.length, secondParts.length]);
|
|
235
|
-
const lastIndex = length - 1;
|
|
236
|
-
for (let index = 0;index < length; index += 1) {
|
|
237
|
-
const firstPart = firstParts[index];
|
|
238
|
-
const secondPart = secondParts[index];
|
|
239
|
-
if (firstPart === secondPart) {
|
|
240
|
-
if (index === lastIndex) {
|
|
241
|
-
return 0;
|
|
242
|
-
}
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
if (firstPart == null || typeof firstPart === "string" && firstPart.length === 0) {
|
|
246
|
-
return -1;
|
|
247
|
-
}
|
|
248
|
-
if (secondPart == null || typeof secondPart === "string" && secondPart.length === 0) {
|
|
249
|
-
return 1;
|
|
250
|
-
}
|
|
251
|
-
const firstNumber = getNumber(firstPart);
|
|
252
|
-
const secondNumber = getNumber(secondPart);
|
|
253
|
-
const firstIsNaN = Number.isNaN(firstNumber);
|
|
254
|
-
const secondIsNaN = Number.isNaN(secondNumber);
|
|
255
|
-
if (firstIsNaN || secondIsNaN) {
|
|
256
|
-
if (firstIsNaN && secondIsNaN) {
|
|
257
|
-
return getString(firstPart).localeCompare(getString(secondPart));
|
|
258
|
-
}
|
|
259
|
-
if (firstIsNaN) {
|
|
260
|
-
return 1;
|
|
261
|
-
}
|
|
262
|
-
if (secondIsNaN) {
|
|
263
|
-
return -1;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
if (firstNumber === secondNumber) {
|
|
267
|
-
if (index === lastIndex) {
|
|
268
|
-
return 0;
|
|
269
|
-
}
|
|
270
|
-
continue;
|
|
271
|
-
}
|
|
272
|
-
return firstNumber - secondNumber;
|
|
273
|
-
}
|
|
274
|
-
return join(firstParts).localeCompare(join(secondParts));
|
|
275
|
-
}
|
|
276
|
-
function getParts(value) {
|
|
277
|
-
if (value == null) {
|
|
278
|
-
return [""];
|
|
279
|
-
}
|
|
280
|
-
if (Array.isArray(value)) {
|
|
281
|
-
return value;
|
|
282
|
-
}
|
|
283
|
-
return typeof value === "object" ? [value] : words(getString(value));
|
|
284
|
-
}
|
|
285
|
-
// src/js/is.ts
|
|
286
|
-
function isKey(value) {
|
|
287
|
-
return typeof value === "number" || typeof value === "string";
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
// src/js/array/sort.ts
|
|
291
|
-
function sort(array, first, second) {
|
|
292
|
-
if (array.length < 2) {
|
|
293
|
-
return array;
|
|
294
|
-
}
|
|
295
|
-
if (first == null || typeof first === "boolean") {
|
|
296
|
-
return first === true ? array.sort((first2, second2) => second2 - first2) : array.sort();
|
|
297
|
-
}
|
|
298
|
-
const direction = second === true ? "desc" : "asc";
|
|
299
|
-
const keys = (Array.isArray(first) ? first : [first]).map((key) => {
|
|
300
|
-
const returned = {
|
|
301
|
-
direction,
|
|
302
|
-
callback: undefined
|
|
303
|
-
};
|
|
304
|
-
if (isKey(key)) {
|
|
305
|
-
returned.callback = (value) => value[key];
|
|
306
|
-
} else if (typeof key === "function") {
|
|
307
|
-
returned.callback = key;
|
|
308
|
-
} else if (typeof key?.value === "function" || isKey(key?.value)) {
|
|
309
|
-
returned.direction = key?.direction ?? direction;
|
|
310
|
-
returned.callback = typeof key.value === "function" ? key.value : (value) => value[key.value];
|
|
311
|
-
}
|
|
312
|
-
return returned;
|
|
313
|
-
}).filter((key) => typeof key.callback === "function");
|
|
314
|
-
const { length } = keys;
|
|
315
|
-
if (length === 0) {
|
|
316
|
-
return direction === "asc" ? array.sort() : array.sort((first2, second2) => second2 - first2);
|
|
317
|
-
}
|
|
318
|
-
if (length === 1) {
|
|
319
|
-
return array.sort((first2, second2) => compare(keys[0].callback(first2), keys[0].callback(second2)) * (keys[0].direction === "asc" ? 1 : -1));
|
|
320
|
-
}
|
|
321
|
-
const sorted = array.sort((first2, second2) => {
|
|
322
|
-
for (let index = 0;index < length; index += 1) {
|
|
323
|
-
const { callback, direction: direction2 } = keys[index];
|
|
324
|
-
const descending = direction2 === "desc";
|
|
325
|
-
const compared = compare(callback(descending ? second2 : first2), callback(descending ? first2 : second2));
|
|
326
|
-
if (compared !== 0) {
|
|
327
|
-
return compared;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
return 0;
|
|
331
|
-
});
|
|
332
|
-
return sorted;
|
|
333
|
-
}
|
|
334
|
-
// src/js/array/splice.ts
|
|
335
|
-
function splice(array, start, amountOrValues, values) {
|
|
336
|
-
const amoutOrValuesIsArray = Array.isArray(amountOrValues);
|
|
337
|
-
return insertValues("splice", array, amoutOrValuesIsArray ? amountOrValues : values ?? [], start, amoutOrValuesIsArray ? array.length : typeof amountOrValues === "number" && amountOrValues > 0 ? amountOrValues : 0);
|
|
338
|
-
}
|
|
339
|
-
// src/js/array/to-map.ts
|
|
340
|
-
function toMap(array, first, second) {
|
|
341
|
-
const asArrays = first === true || second === true;
|
|
342
|
-
const callbacks = getCallbacks(undefined, first);
|
|
343
|
-
const hasCallback = typeof callbacks?.key === "function";
|
|
344
|
-
const map = new Map;
|
|
345
|
-
const { length } = array;
|
|
346
|
-
for (let index = 0;index < length; index += 1) {
|
|
347
|
-
const value = array[index];
|
|
348
|
-
const key = hasCallback ? callbacks?.key?.(value, index, array) ?? index : index;
|
|
349
|
-
if (asArrays) {
|
|
350
|
-
const existing = map.get(key);
|
|
351
|
-
if (Array.isArray(existing)) {
|
|
352
|
-
existing.push(value);
|
|
353
|
-
} else {
|
|
354
|
-
map.set(key, [value]);
|
|
355
|
-
}
|
|
356
|
-
} else {
|
|
357
|
-
map.set(key, value);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
return map;
|
|
361
|
-
}
|
|
362
|
-
// src/js/array/to-record.ts
|
|
363
|
-
function toRecord(array, first, second) {
|
|
364
|
-
return groupValues(array, first, first === true || second === true, true);
|
|
365
|
-
}
|
|
366
|
-
// src/js/array/unique.ts
|
|
367
|
-
function unique(array, key) {
|
|
368
|
-
return findValues("unique", array, undefined, key);
|
|
20
|
+
function push(array, pushed) {
|
|
21
|
+
return insertValues("push", array, pushed, array.length, 0);
|
|
369
22
|
}
|
|
370
23
|
export {
|
|
371
|
-
|
|
372
|
-
toRecord,
|
|
373
|
-
toMap,
|
|
374
|
-
splice,
|
|
375
|
-
sort,
|
|
376
|
-
shuffle,
|
|
377
|
-
push,
|
|
378
|
-
insert,
|
|
379
|
-
indexOf,
|
|
380
|
-
groupBy,
|
|
381
|
-
flatten,
|
|
382
|
-
find,
|
|
383
|
-
filter,
|
|
384
|
-
exists,
|
|
385
|
-
count,
|
|
24
|
+
chunk,
|
|
386
25
|
compact,
|
|
387
|
-
|
|
26
|
+
count,
|
|
27
|
+
exists,
|
|
28
|
+
filter,
|
|
29
|
+
find,
|
|
30
|
+
flatten,
|
|
31
|
+
groupBy,
|
|
32
|
+
indexOf,
|
|
33
|
+
insert,
|
|
34
|
+
push,
|
|
35
|
+
shuffle,
|
|
36
|
+
sort,
|
|
37
|
+
splice,
|
|
38
|
+
toMap,
|
|
39
|
+
toRecord,
|
|
40
|
+
unique
|
|
388
41
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const array_chunk = require("./chunk.cjs");
|
|
4
|
+
function insert(array, first, second) {
|
|
5
|
+
insertValues(
|
|
6
|
+
"splice",
|
|
7
|
+
array,
|
|
8
|
+
Array.isArray(first) ? first : second ?? [],
|
|
9
|
+
typeof first === "number" ? first : array.length,
|
|
10
|
+
0
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
function insertValues(type, array, items, start, deleteCount) {
|
|
14
|
+
const chunked = array_chunk.chunk(items);
|
|
15
|
+
const lastIndex = chunked.length - 1;
|
|
16
|
+
let index = Number(chunked.length);
|
|
17
|
+
let returned;
|
|
18
|
+
while (--index >= 0) {
|
|
19
|
+
const result = array.splice(
|
|
20
|
+
start,
|
|
21
|
+
index === lastIndex ? deleteCount : 0,
|
|
22
|
+
...chunked[index]
|
|
23
|
+
);
|
|
24
|
+
if (returned == null) {
|
|
25
|
+
returned = result;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return type === "splice" ? returned : array.length;
|
|
29
|
+
}
|
|
30
|
+
exports.insert = insert;
|
|
31
|
+
exports.insertValues = insertValues;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { chunk } from "./chunk.js";
|
|
2
|
+
function insert(array, first, second) {
|
|
3
|
+
insertValues(
|
|
4
|
+
"splice",
|
|
5
|
+
array,
|
|
6
|
+
Array.isArray(first) ? first : second ?? [],
|
|
7
|
+
typeof first === "number" ? first : array.length,
|
|
8
|
+
0
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
function insertValues(type, array, items, start, deleteCount) {
|
|
12
|
+
const chunked = chunk(items);
|
|
13
|
+
const lastIndex = chunked.length - 1;
|
|
14
|
+
let index = Number(chunked.length);
|
|
15
|
+
let returned;
|
|
16
|
+
while (--index >= 0) {
|
|
17
|
+
const result = array.splice(
|
|
18
|
+
start,
|
|
19
|
+
index === lastIndex ? deleteCount : 0,
|
|
20
|
+
...chunked[index]
|
|
21
|
+
);
|
|
22
|
+
if (returned == null) {
|
|
23
|
+
returned = result;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return type === "splice" ? returned : array.length;
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
insert,
|
|
30
|
+
insertValues
|
|
31
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const random = require("../random.cjs");
|
|
4
|
+
function shuffle(array) {
|
|
5
|
+
const shuffled = array.slice();
|
|
6
|
+
const { length } = shuffled;
|
|
7
|
+
for (let index = 0; index < length; index += 1) {
|
|
8
|
+
const random$1 = random.getRandomInteger(0, length);
|
|
9
|
+
[shuffled[index], shuffled[random$1]] = [shuffled[random$1], shuffled[index]];
|
|
10
|
+
}
|
|
11
|
+
return shuffled;
|
|
12
|
+
}
|
|
13
|
+
exports.shuffle = shuffle;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import { getRandomInteger } from "../random";
|
|
1
|
+
import { getRandomInteger } from "../random.js";
|
|
3
2
|
function shuffle(array) {
|
|
4
3
|
const shuffled = array.slice();
|
|
5
4
|
const { length } = shuffled;
|
|
6
|
-
for (let index = 0;index < length; index += 1) {
|
|
5
|
+
for (let index = 0; index < length; index += 1) {
|
|
7
6
|
const random = getRandomInteger(0, length);
|
|
8
7
|
[shuffled[index], shuffled[random]] = [shuffled[random], shuffled[index]];
|
|
9
8
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const is = require("../is.cjs");
|
|
4
|
+
const value_compare = require("../value/compare.cjs");
|
|
5
|
+
function sort(array, first, second) {
|
|
6
|
+
if (array.length < 2) {
|
|
7
|
+
return array;
|
|
8
|
+
}
|
|
9
|
+
if (first == null || typeof first === "boolean") {
|
|
10
|
+
return first === true ? array.sort((first2, second2) => second2 - first2) : array.sort();
|
|
11
|
+
}
|
|
12
|
+
const direction = second === true ? "desc" : "asc";
|
|
13
|
+
const keys = (Array.isArray(first) ? first : [first]).map((key) => {
|
|
14
|
+
const returned = {
|
|
15
|
+
direction,
|
|
16
|
+
callback: void 0
|
|
17
|
+
};
|
|
18
|
+
if (is.isKey(key)) {
|
|
19
|
+
returned.callback = (value) => value[key];
|
|
20
|
+
} else if (typeof key === "function") {
|
|
21
|
+
returned.callback = key;
|
|
22
|
+
} else if (typeof (key == null ? void 0 : key.value) === "function" || is.isKey(key == null ? void 0 : key.value)) {
|
|
23
|
+
returned.direction = (key == null ? void 0 : key.direction) ?? direction;
|
|
24
|
+
returned.callback = typeof key.value === "function" ? key.value : (value) => value[key.value];
|
|
25
|
+
}
|
|
26
|
+
return returned;
|
|
27
|
+
}).filter((key) => typeof key.callback === "function");
|
|
28
|
+
const { length } = keys;
|
|
29
|
+
if (length === 0) {
|
|
30
|
+
return direction === "asc" ? array.sort() : array.sort((first2, second2) => second2 - first2);
|
|
31
|
+
}
|
|
32
|
+
if (length === 1) {
|
|
33
|
+
return array.sort(
|
|
34
|
+
(first2, second2) => value_compare.compare(keys[0].callback(first2), keys[0].callback(second2)) * (keys[0].direction === "asc" ? 1 : -1)
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
const sorted = array.sort((first2, second2) => {
|
|
38
|
+
for (let index = 0; index < length; index += 1) {
|
|
39
|
+
const { callback, direction: direction2 } = keys[index];
|
|
40
|
+
const descending = direction2 === "desc";
|
|
41
|
+
const compared = value_compare.compare(
|
|
42
|
+
callback(descending ? second2 : first2),
|
|
43
|
+
callback(descending ? first2 : second2)
|
|
44
|
+
);
|
|
45
|
+
if (compared !== 0) {
|
|
46
|
+
return compared;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return 0;
|
|
50
|
+
});
|
|
51
|
+
return sorted;
|
|
52
|
+
}
|
|
53
|
+
exports.sort = sort;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { compare } from "../value/compare";
|
|
1
|
+
import { isKey } from "../is.js";
|
|
2
|
+
import { compare } from "../value/compare.js";
|
|
4
3
|
function sort(array, first, second) {
|
|
5
4
|
if (array.length < 2) {
|
|
6
5
|
return array;
|
|
@@ -12,14 +11,14 @@ function sort(array, first, second) {
|
|
|
12
11
|
const keys = (Array.isArray(first) ? first : [first]).map((key) => {
|
|
13
12
|
const returned = {
|
|
14
13
|
direction,
|
|
15
|
-
callback:
|
|
14
|
+
callback: void 0
|
|
16
15
|
};
|
|
17
16
|
if (isKey(key)) {
|
|
18
17
|
returned.callback = (value) => value[key];
|
|
19
18
|
} else if (typeof key === "function") {
|
|
20
19
|
returned.callback = key;
|
|
21
|
-
} else if (typeof key
|
|
22
|
-
returned.direction = key
|
|
20
|
+
} else if (typeof (key == null ? void 0 : key.value) === "function" || isKey(key == null ? void 0 : key.value)) {
|
|
21
|
+
returned.direction = (key == null ? void 0 : key.direction) ?? direction;
|
|
23
22
|
returned.callback = typeof key.value === "function" ? key.value : (value) => value[key.value];
|
|
24
23
|
}
|
|
25
24
|
return returned;
|
|
@@ -29,13 +28,18 @@ function sort(array, first, second) {
|
|
|
29
28
|
return direction === "asc" ? array.sort() : array.sort((first2, second2) => second2 - first2);
|
|
30
29
|
}
|
|
31
30
|
if (length === 1) {
|
|
32
|
-
return array.sort(
|
|
31
|
+
return array.sort(
|
|
32
|
+
(first2, second2) => compare(keys[0].callback(first2), keys[0].callback(second2)) * (keys[0].direction === "asc" ? 1 : -1)
|
|
33
|
+
);
|
|
33
34
|
}
|
|
34
35
|
const sorted = array.sort((first2, second2) => {
|
|
35
|
-
for (let index = 0;index < length; index += 1) {
|
|
36
|
+
for (let index = 0; index < length; index += 1) {
|
|
36
37
|
const { callback, direction: direction2 } = keys[index];
|
|
37
38
|
const descending = direction2 === "desc";
|
|
38
|
-
const compared = compare(
|
|
39
|
+
const compared = compare(
|
|
40
|
+
callback(descending ? second2 : first2),
|
|
41
|
+
callback(descending ? first2 : second2)
|
|
42
|
+
);
|
|
39
43
|
if (compared !== 0) {
|
|
40
44
|
return compared;
|
|
41
45
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const array_insert = require("./insert.cjs");
|
|
4
|
+
function splice(array, start, first, second) {
|
|
5
|
+
const isArray = Array.isArray(first);
|
|
6
|
+
return array_insert.insertValues(
|
|
7
|
+
"splice",
|
|
8
|
+
array,
|
|
9
|
+
isArray ? first : second ?? [],
|
|
10
|
+
start,
|
|
11
|
+
isArray ? array.length : typeof first === "number" && first > 0 ? first : 0
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
exports.splice = splice;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { insertValues } from "./insert.js";
|
|
2
|
+
function splice(array, start, first, second) {
|
|
3
|
+
const isArray = Array.isArray(first);
|
|
4
|
+
return insertValues(
|
|
5
|
+
"splice",
|
|
6
|
+
array,
|
|
7
|
+
isArray ? first : second ?? [],
|
|
8
|
+
start,
|
|
9
|
+
isArray ? array.length : typeof first === "number" && first > 0 ? first : 0
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
splice
|
|
14
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const internal_array_callbacks = require("../internal/array/callbacks.cjs");
|
|
4
|
+
function toMap(array, first, second, third) {
|
|
5
|
+
var _a, _b;
|
|
6
|
+
const asArrays = first === true || second === true || third === true;
|
|
7
|
+
const callbacks = internal_array_callbacks.getCallbacks(void 0, first, second);
|
|
8
|
+
const map = /* @__PURE__ */ new Map();
|
|
9
|
+
const { length } = array;
|
|
10
|
+
for (let index = 0; index < length; index += 1) {
|
|
11
|
+
const item = array[index];
|
|
12
|
+
const key = ((_a = callbacks == null ? void 0 : callbacks.key) == null ? void 0 : _a.call(callbacks, item, index, array)) ?? index;
|
|
13
|
+
const value = ((_b = callbacks == null ? void 0 : callbacks.value) == null ? void 0 : _b.call(callbacks, item, index, array)) ?? item;
|
|
14
|
+
if (asArrays) {
|
|
15
|
+
const existing = map.get(key);
|
|
16
|
+
if (existing == null) {
|
|
17
|
+
map.set(key, [value]);
|
|
18
|
+
} else {
|
|
19
|
+
existing.push(value);
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
map.set(key, value);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return map;
|
|
26
|
+
}
|
|
27
|
+
exports.toMap = toMap;
|