radashi 12.6.0 → 13.0.0-beta.99854e3
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/radashi.cjs +70 -200
- package/dist/radashi.d.cts +79 -36
- package/dist/radashi.d.ts +79 -36
- package/dist/radashi.js +70 -201
- package/package.json +1 -1
package/dist/radashi.cjs
CHANGED
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
// src/array/alphabetical.ts
|
|
4
4
|
function alphabetical(array, getter, direction = "asc") {
|
|
5
|
-
if (!array) {
|
|
6
|
-
return [];
|
|
7
|
-
}
|
|
8
5
|
const asc = (a, b) => `${getter(a)}`.localeCompare(getter(b));
|
|
9
6
|
const dsc = (a, b) => `${getter(b)}`.localeCompare(getter(a));
|
|
10
7
|
return array.slice().sort(direction === "desc" ? dsc : asc);
|
|
@@ -12,10 +9,7 @@ function alphabetical(array, getter, direction = "asc") {
|
|
|
12
9
|
|
|
13
10
|
// src/array/boil.ts
|
|
14
11
|
function boil(array, compareFunc) {
|
|
15
|
-
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
return array.reduce(compareFunc);
|
|
12
|
+
return array.length ? array.reduce(compareFunc) : null;
|
|
19
13
|
}
|
|
20
14
|
|
|
21
15
|
// src/array/cartesianProduct.ts
|
|
@@ -46,7 +40,7 @@ function castArrayIfExists(value) {
|
|
|
46
40
|
}
|
|
47
41
|
|
|
48
42
|
// src/array/cluster.ts
|
|
49
|
-
function cluster(array, size
|
|
43
|
+
function cluster(array, size) {
|
|
50
44
|
const clusters = [];
|
|
51
45
|
if (size > 0) {
|
|
52
46
|
for (let i = 0; i < array.length; i += size) {
|
|
@@ -72,9 +66,6 @@ function concat(...values) {
|
|
|
72
66
|
|
|
73
67
|
// src/array/counting.ts
|
|
74
68
|
function counting(array, identity) {
|
|
75
|
-
if (!array) {
|
|
76
|
-
return {};
|
|
77
|
-
}
|
|
78
69
|
return array.reduce(
|
|
79
70
|
(acc, item) => {
|
|
80
71
|
const id = identity(item);
|
|
@@ -87,15 +78,6 @@ function counting(array, identity) {
|
|
|
87
78
|
|
|
88
79
|
// src/array/diff.ts
|
|
89
80
|
function diff(root, other, identity = (t) => t) {
|
|
90
|
-
if (!(root == null ? void 0 : root.length) && !(other == null ? void 0 : other.length)) {
|
|
91
|
-
return [];
|
|
92
|
-
}
|
|
93
|
-
if ((root == null ? void 0 : root.length) === void 0) {
|
|
94
|
-
return [...other];
|
|
95
|
-
}
|
|
96
|
-
if (!(other == null ? void 0 : other.length)) {
|
|
97
|
-
return [...root];
|
|
98
|
-
}
|
|
99
81
|
const bKeys = other.reduce(
|
|
100
82
|
(acc, item) => {
|
|
101
83
|
acc[identity(item)] = true;
|
|
@@ -108,7 +90,7 @@ function diff(root, other, identity = (t) => t) {
|
|
|
108
90
|
|
|
109
91
|
// src/array/first.ts
|
|
110
92
|
function first(array, defaultValue) {
|
|
111
|
-
return
|
|
93
|
+
return array.length > 0 ? array[0] : defaultValue;
|
|
112
94
|
}
|
|
113
95
|
|
|
114
96
|
// src/array/flat.ts
|
|
@@ -122,10 +104,8 @@ function flat(lists) {
|
|
|
122
104
|
// src/array/fork.ts
|
|
123
105
|
function fork(array, condition) {
|
|
124
106
|
const forked = [[], []];
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
forked[condition(item) ? 0 : 1].push(item);
|
|
128
|
-
}
|
|
107
|
+
for (const item of array) {
|
|
108
|
+
forked[condition(item) ? 0 : 1].push(item);
|
|
129
109
|
}
|
|
130
110
|
return forked;
|
|
131
111
|
}
|
|
@@ -147,9 +127,6 @@ function group(array, getGroupId) {
|
|
|
147
127
|
|
|
148
128
|
// src/array/intersects.ts
|
|
149
129
|
function intersects(listA, listB, identity) {
|
|
150
|
-
if (!listA || !listB) {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
130
|
if (identity) {
|
|
154
131
|
const known = new Set(listA.map(identity));
|
|
155
132
|
return listB.some((item) => known.has(identity(item)));
|
|
@@ -168,7 +145,7 @@ function iterate(count, func, initValue) {
|
|
|
168
145
|
|
|
169
146
|
// src/array/last.ts
|
|
170
147
|
function last(array, defaultValue) {
|
|
171
|
-
return
|
|
148
|
+
return array.length > 0 ? array[array.length - 1] : defaultValue;
|
|
172
149
|
}
|
|
173
150
|
|
|
174
151
|
// src/array/list.ts
|
|
@@ -187,18 +164,6 @@ function mapify(array, getKey, getValue = (item) => item) {
|
|
|
187
164
|
|
|
188
165
|
// src/array/merge.ts
|
|
189
166
|
function merge(prev, array, toKey) {
|
|
190
|
-
if (!array && !prev) {
|
|
191
|
-
return [];
|
|
192
|
-
}
|
|
193
|
-
if (!array) {
|
|
194
|
-
return [...prev];
|
|
195
|
-
}
|
|
196
|
-
if (!prev) {
|
|
197
|
-
return [];
|
|
198
|
-
}
|
|
199
|
-
if (!toKey) {
|
|
200
|
-
return [...prev];
|
|
201
|
-
}
|
|
202
167
|
const keys2 = /* @__PURE__ */ new Map();
|
|
203
168
|
for (const item of array) {
|
|
204
169
|
keys2.set(toKey(item), item);
|
|
@@ -211,13 +176,10 @@ function merge(prev, array, toKey) {
|
|
|
211
176
|
|
|
212
177
|
// src/array/objectify.ts
|
|
213
178
|
function objectify(array, getKey, getValue = (item) => item) {
|
|
214
|
-
return array.reduce(
|
|
215
|
-
(
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
},
|
|
219
|
-
{}
|
|
220
|
-
);
|
|
179
|
+
return array.reduce((acc, item) => {
|
|
180
|
+
acc[getKey(item)] = getValue(item);
|
|
181
|
+
return acc;
|
|
182
|
+
}, {});
|
|
221
183
|
}
|
|
222
184
|
|
|
223
185
|
// src/array/pluck.ts
|
|
@@ -236,9 +198,6 @@ function remove(array, predicate) {
|
|
|
236
198
|
|
|
237
199
|
// src/array/replace.ts
|
|
238
200
|
function replace(array, newItem, match) {
|
|
239
|
-
if (!array) {
|
|
240
|
-
return [];
|
|
241
|
-
}
|
|
242
201
|
if (newItem === void 0) {
|
|
243
202
|
return [...array];
|
|
244
203
|
}
|
|
@@ -254,15 +213,9 @@ function replace(array, newItem, match) {
|
|
|
254
213
|
|
|
255
214
|
// src/array/replaceOrAppend.ts
|
|
256
215
|
function replaceOrAppend(array, newItem, match) {
|
|
257
|
-
if (
|
|
258
|
-
return [];
|
|
259
|
-
}
|
|
260
|
-
if (!newItem) {
|
|
216
|
+
if (newItem === void 0) {
|
|
261
217
|
return [...array];
|
|
262
218
|
}
|
|
263
|
-
if (!array) {
|
|
264
|
-
return [newItem];
|
|
265
|
-
}
|
|
266
219
|
const out = array.slice();
|
|
267
220
|
for (let index = 0; index < array.length; index++) {
|
|
268
221
|
if (match(array[index], index)) {
|
|
@@ -276,9 +229,6 @@ function replaceOrAppend(array, newItem, match) {
|
|
|
276
229
|
|
|
277
230
|
// src/array/select.ts
|
|
278
231
|
function select(array, mapper, condition) {
|
|
279
|
-
if (!array) {
|
|
280
|
-
return [];
|
|
281
|
-
}
|
|
282
232
|
let mapped;
|
|
283
233
|
return array.reduce((acc, item, index) => {
|
|
284
234
|
if (condition) {
|
|
@@ -292,9 +242,6 @@ function select(array, mapper, condition) {
|
|
|
292
242
|
|
|
293
243
|
// src/array/selectFirst.ts
|
|
294
244
|
function selectFirst(array, mapper, condition) {
|
|
295
|
-
if (!array) {
|
|
296
|
-
return void 0;
|
|
297
|
-
}
|
|
298
245
|
let foundIndex = -1;
|
|
299
246
|
const found = array.find((item, index) => {
|
|
300
247
|
foundIndex = index;
|
|
@@ -322,9 +269,6 @@ function sift(array) {
|
|
|
322
269
|
|
|
323
270
|
// src/array/sort.ts
|
|
324
271
|
function sort(array, getter, desc = false) {
|
|
325
|
-
if (!array) {
|
|
326
|
-
return [];
|
|
327
|
-
}
|
|
328
272
|
const asc = (a, b) => getter(a) - getter(b);
|
|
329
273
|
const dsc = (a, b) => getter(b) - getter(a);
|
|
330
274
|
return array.slice().sort(desc === true ? dsc : asc);
|
|
@@ -332,9 +276,6 @@ function sort(array, getter, desc = false) {
|
|
|
332
276
|
|
|
333
277
|
// src/array/toggle.ts
|
|
334
278
|
function toggle(array, item, toKey, options) {
|
|
335
|
-
if (!array) {
|
|
336
|
-
return item !== void 0 ? [item] : [];
|
|
337
|
-
}
|
|
338
279
|
if (item === void 0) {
|
|
339
280
|
return [...array];
|
|
340
281
|
}
|
|
@@ -370,9 +311,6 @@ function unique(array, toKey) {
|
|
|
370
311
|
|
|
371
312
|
// src/array/unzip.ts
|
|
372
313
|
function unzip(arrays) {
|
|
373
|
-
if (!arrays || !arrays.length) {
|
|
374
|
-
return [];
|
|
375
|
-
}
|
|
376
314
|
const out = new Array(
|
|
377
315
|
arrays.reduce((max2, arr) => Math.max(max2, arr.length), 0)
|
|
378
316
|
);
|
|
@@ -391,9 +329,6 @@ function zip(...arrays) {
|
|
|
391
329
|
|
|
392
330
|
// src/array/zipToObject.ts
|
|
393
331
|
function zipToObject(keys2, values) {
|
|
394
|
-
if (!keys2 || !keys2.length) {
|
|
395
|
-
return {};
|
|
396
|
-
}
|
|
397
332
|
const getValue = isFunction(values) ? values : isArray(values) ? (_k, i) => values[i] : (_k, _i) => values;
|
|
398
333
|
return keys2.reduce(
|
|
399
334
|
(acc, key, idx) => {
|
|
@@ -466,9 +401,6 @@ function guard(func, shouldGuard) {
|
|
|
466
401
|
|
|
467
402
|
// src/async/map.ts
|
|
468
403
|
async function map(array, asyncMapFunc) {
|
|
469
|
-
if (!array) {
|
|
470
|
-
return [];
|
|
471
|
-
}
|
|
472
404
|
const result = [];
|
|
473
405
|
let index = 0;
|
|
474
406
|
for (const value of array) {
|
|
@@ -552,9 +484,6 @@ function queueByKey(asyncFn, keyFn) {
|
|
|
552
484
|
|
|
553
485
|
// src/async/reduce.ts
|
|
554
486
|
async function reduce(array, reducer, initialValue) {
|
|
555
|
-
if (!array) {
|
|
556
|
-
array = [];
|
|
557
|
-
}
|
|
558
487
|
let index = 0;
|
|
559
488
|
let acc = initialValue;
|
|
560
489
|
if (acc === void 0 && arguments.length < 3) {
|
|
@@ -653,6 +582,32 @@ function withResolvers() {
|
|
|
653
582
|
return { resolve, reject, promise };
|
|
654
583
|
}
|
|
655
584
|
|
|
585
|
+
// src/async/promiseMemo.ts
|
|
586
|
+
function promiseMemo(func, options = {}) {
|
|
587
|
+
const { key: keyFunc, ttl, cache = {} } = options;
|
|
588
|
+
return function callWithMemo(...args) {
|
|
589
|
+
const key = keyFunc ? keyFunc(...args) : JSON.stringify({ args });
|
|
590
|
+
const existing = cache[key];
|
|
591
|
+
if (existing !== void 0) {
|
|
592
|
+
if (!existing.exp) {
|
|
593
|
+
return existing.value;
|
|
594
|
+
}
|
|
595
|
+
if (existing.exp > (/* @__PURE__ */ new Date()).getTime()) {
|
|
596
|
+
return existing.value;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
const promise = func(...args);
|
|
600
|
+
cache[key] = {
|
|
601
|
+
exp: ttl ? (/* @__PURE__ */ new Date()).getTime() + ttl : null,
|
|
602
|
+
value: promise
|
|
603
|
+
};
|
|
604
|
+
promise.catch(() => {
|
|
605
|
+
delete cache[key];
|
|
606
|
+
});
|
|
607
|
+
return promise;
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
|
|
656
611
|
// src/curry/callable.ts
|
|
657
612
|
function callable(obj, fn) {
|
|
658
613
|
return new Proxy(Object.assign(fn.bind(null), obj), {
|
|
@@ -678,31 +633,30 @@ function compose(...funcs) {
|
|
|
678
633
|
}
|
|
679
634
|
|
|
680
635
|
// src/curry/debounce.ts
|
|
681
|
-
function debounce({ delay, leading },
|
|
682
|
-
let
|
|
683
|
-
let active = true;
|
|
636
|
+
function debounce({ delay, leading }, callee) {
|
|
637
|
+
let timeout2;
|
|
684
638
|
const debounced = (...args) => {
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
timer = void 0;
|
|
690
|
-
}, delay);
|
|
691
|
-
if (leading) {
|
|
692
|
-
func(...args);
|
|
693
|
-
leading = false;
|
|
694
|
-
}
|
|
639
|
+
clearTimeout(timeout2);
|
|
640
|
+
if (leading) {
|
|
641
|
+
leading = false;
|
|
642
|
+
callee(...args);
|
|
695
643
|
} else {
|
|
696
|
-
|
|
644
|
+
timeout2 = setTimeout(
|
|
645
|
+
debounced.flush = () => {
|
|
646
|
+
debounced.flush = noop;
|
|
647
|
+
clearTimeout(timeout2);
|
|
648
|
+
callee(...args);
|
|
649
|
+
},
|
|
650
|
+
delay
|
|
651
|
+
);
|
|
697
652
|
}
|
|
698
653
|
};
|
|
699
|
-
debounced.
|
|
700
|
-
|
|
701
|
-
};
|
|
654
|
+
debounced.callee = callee;
|
|
655
|
+
debounced.flush = noop;
|
|
702
656
|
debounced.cancel = () => {
|
|
703
|
-
|
|
657
|
+
debounced.flush = noop;
|
|
658
|
+
clearTimeout(timeout2);
|
|
704
659
|
};
|
|
705
|
-
debounced.flush = (...args) => func(...args);
|
|
706
660
|
return debounced;
|
|
707
661
|
}
|
|
708
662
|
|
|
@@ -712,7 +666,8 @@ function flip(fn) {
|
|
|
712
666
|
}
|
|
713
667
|
|
|
714
668
|
// src/curry/memo.ts
|
|
715
|
-
function
|
|
669
|
+
function memo(func, options = {}) {
|
|
670
|
+
const { key: keyFunc, ttl, cache = {} } = options;
|
|
716
671
|
return function callWithMemo(...args) {
|
|
717
672
|
const key = keyFunc ? keyFunc(...args) : JSON.stringify({ args });
|
|
718
673
|
const existing = cache[key];
|
|
@@ -732,9 +687,6 @@ function memoize(cache, func, keyFunc, ttl) {
|
|
|
732
687
|
return result;
|
|
733
688
|
};
|
|
734
689
|
}
|
|
735
|
-
function memo(func, options = {}) {
|
|
736
|
-
return memoize({}, func, options.key ?? null, options.ttl ?? null);
|
|
737
|
-
}
|
|
738
690
|
|
|
739
691
|
// src/curry/memoLastCall.ts
|
|
740
692
|
function memoLastCall(fn) {
|
|
@@ -867,15 +819,7 @@ function clamp(n, min2, max2) {
|
|
|
867
819
|
}
|
|
868
820
|
|
|
869
821
|
// src/number/inRange.ts
|
|
870
|
-
function inRange(number, start, end) {
|
|
871
|
-
const isTypeSafe = typeof number === "number" && typeof start === "number" && (typeof end === "undefined" || typeof end === "number");
|
|
872
|
-
if (!isTypeSafe) {
|
|
873
|
-
return false;
|
|
874
|
-
}
|
|
875
|
-
if (typeof end === "undefined") {
|
|
876
|
-
end = start;
|
|
877
|
-
start = 0;
|
|
878
|
-
}
|
|
822
|
+
function inRange(number, start, end = 0) {
|
|
879
823
|
return number >= Math.min(start, end) && number < Math.max(start, end);
|
|
880
824
|
}
|
|
881
825
|
|
|
@@ -886,7 +830,7 @@ function lerp(from, to, amount) {
|
|
|
886
830
|
|
|
887
831
|
// src/number/max.ts
|
|
888
832
|
function max(array, getter) {
|
|
889
|
-
if (!array
|
|
833
|
+
if (!array.length) {
|
|
890
834
|
return null;
|
|
891
835
|
}
|
|
892
836
|
const get2 = getter ?? ((v) => v);
|
|
@@ -895,7 +839,7 @@ function max(array, getter) {
|
|
|
895
839
|
|
|
896
840
|
// src/number/min.ts
|
|
897
841
|
function min(array, getter) {
|
|
898
|
-
if (!array
|
|
842
|
+
if (!array.length) {
|
|
899
843
|
return null;
|
|
900
844
|
}
|
|
901
845
|
const get2 = getter ?? ((v) => v);
|
|
@@ -952,9 +896,6 @@ function toInt(value, defaultValue) {
|
|
|
952
896
|
|
|
953
897
|
// src/object/assign.ts
|
|
954
898
|
function assign(initial, override) {
|
|
955
|
-
if (!initial || !override) {
|
|
956
|
-
return initial ?? override ?? {};
|
|
957
|
-
}
|
|
958
899
|
const proto = Object.getPrototypeOf(initial);
|
|
959
900
|
const merged = proto ? { ...initial } : Object.assign(Object.create(proto), initial);
|
|
960
901
|
for (const key of Object.keys(override)) {
|
|
@@ -965,12 +906,6 @@ function assign(initial, override) {
|
|
|
965
906
|
|
|
966
907
|
// src/object/clone.ts
|
|
967
908
|
function clone(obj) {
|
|
968
|
-
if (isPrimitive(obj)) {
|
|
969
|
-
return obj;
|
|
970
|
-
}
|
|
971
|
-
if (typeof obj === "function") {
|
|
972
|
-
return obj.bind({});
|
|
973
|
-
}
|
|
974
909
|
const proto = Object.getPrototypeOf(obj);
|
|
975
910
|
const newObj = typeof (proto == null ? void 0 : proto.constructor) === "function" ? new proto.constructor() : Object.create(proto);
|
|
976
911
|
for (const key of Object.getOwnPropertyNames(obj)) {
|
|
@@ -1048,9 +983,6 @@ function cloneDeep(root, customStrategy) {
|
|
|
1048
983
|
|
|
1049
984
|
// src/object/construct.ts
|
|
1050
985
|
function construct(obj) {
|
|
1051
|
-
if (!obj) {
|
|
1052
|
-
return {};
|
|
1053
|
-
}
|
|
1054
986
|
return Object.keys(obj).reduce((acc, path) => {
|
|
1055
987
|
return set(acc, path, obj[path]);
|
|
1056
988
|
}, {});
|
|
@@ -1058,9 +990,6 @@ function construct(obj) {
|
|
|
1058
990
|
|
|
1059
991
|
// src/object/crush.ts
|
|
1060
992
|
function crush(value) {
|
|
1061
|
-
if (!value) {
|
|
1062
|
-
return {};
|
|
1063
|
-
}
|
|
1064
993
|
return function crushReducer(crushed, value2, path) {
|
|
1065
994
|
if (isObject(value2) || isArray(value2)) {
|
|
1066
995
|
for (const [prop, propValue] of Object.entries(value2)) {
|
|
@@ -1103,9 +1032,6 @@ function get(value, path, defaultValue) {
|
|
|
1103
1032
|
|
|
1104
1033
|
// src/object/invert.ts
|
|
1105
1034
|
function invert(obj) {
|
|
1106
|
-
if (!obj) {
|
|
1107
|
-
return {};
|
|
1108
|
-
}
|
|
1109
1035
|
const keys2 = Object.keys(obj);
|
|
1110
1036
|
return keys2.reduce(
|
|
1111
1037
|
(acc, key) => {
|
|
@@ -1123,9 +1049,6 @@ function isDangerousKey(key, object) {
|
|
|
1123
1049
|
|
|
1124
1050
|
// src/object/keys.ts
|
|
1125
1051
|
function keys(value) {
|
|
1126
|
-
if (!value) {
|
|
1127
|
-
return [];
|
|
1128
|
-
}
|
|
1129
1052
|
const keys2 = [];
|
|
1130
1053
|
const keyPath = [];
|
|
1131
1054
|
const recurse = (value2) => {
|
|
@@ -1151,14 +1074,7 @@ function keys(value) {
|
|
|
1151
1074
|
|
|
1152
1075
|
// src/object/listify.ts
|
|
1153
1076
|
function listify(obj, toItem) {
|
|
1154
|
-
|
|
1155
|
-
return [];
|
|
1156
|
-
}
|
|
1157
|
-
const entries = Object.entries(obj);
|
|
1158
|
-
if (entries.length === 0) {
|
|
1159
|
-
return [];
|
|
1160
|
-
}
|
|
1161
|
-
return entries.reduce((acc, entry) => {
|
|
1077
|
+
return Object.entries(obj).reduce((acc, entry) => {
|
|
1162
1078
|
acc.push(toItem(entry[0], entry[1]));
|
|
1163
1079
|
return acc;
|
|
1164
1080
|
}, []);
|
|
@@ -1171,9 +1087,6 @@ function lowerize(obj) {
|
|
|
1171
1087
|
|
|
1172
1088
|
// src/object/mapEntries.ts
|
|
1173
1089
|
function mapEntries(obj, toEntry) {
|
|
1174
|
-
if (!obj) {
|
|
1175
|
-
return {};
|
|
1176
|
-
}
|
|
1177
1090
|
return Object.entries(obj).reduce(
|
|
1178
1091
|
(acc, [key, value]) => {
|
|
1179
1092
|
const [newKey, newValue] = toEntry(key, value);
|
|
@@ -1209,10 +1122,7 @@ function mapValues(obj, mapFunc) {
|
|
|
1209
1122
|
|
|
1210
1123
|
// src/object/omit.ts
|
|
1211
1124
|
function omit(obj, keys2) {
|
|
1212
|
-
if (
|
|
1213
|
-
return {};
|
|
1214
|
-
}
|
|
1215
|
-
if (!keys2 || keys2.length === 0) {
|
|
1125
|
+
if (keys2.length === 0) {
|
|
1216
1126
|
return obj;
|
|
1217
1127
|
}
|
|
1218
1128
|
return keys2.reduce(
|
|
@@ -1226,9 +1136,6 @@ function omit(obj, keys2) {
|
|
|
1226
1136
|
|
|
1227
1137
|
// src/object/pick.ts
|
|
1228
1138
|
function pick(obj, filter) {
|
|
1229
|
-
if (!obj) {
|
|
1230
|
-
return {};
|
|
1231
|
-
}
|
|
1232
1139
|
let keys2 = filter;
|
|
1233
1140
|
if (isArray(filter)) {
|
|
1234
1141
|
filter = null;
|
|
@@ -1245,10 +1152,7 @@ function pick(obj, filter) {
|
|
|
1245
1152
|
|
|
1246
1153
|
// src/object/set.ts
|
|
1247
1154
|
function set(initial, path, value) {
|
|
1248
|
-
if (
|
|
1249
|
-
return {};
|
|
1250
|
-
}
|
|
1251
|
-
if (!path || value === void 0) {
|
|
1155
|
+
if (value === void 0 || path.length === 0) {
|
|
1252
1156
|
return initial;
|
|
1253
1157
|
}
|
|
1254
1158
|
return function recurse(object, keys2, index) {
|
|
@@ -1270,9 +1174,6 @@ function set(initial, path, value) {
|
|
|
1270
1174
|
|
|
1271
1175
|
// src/object/shake.ts
|
|
1272
1176
|
function shake(obj, filter = (value) => value === void 0) {
|
|
1273
|
-
if (!obj) {
|
|
1274
|
-
return {};
|
|
1275
|
-
}
|
|
1276
1177
|
return Object.keys(obj).reduce((acc, key) => {
|
|
1277
1178
|
if (!filter(obj[key])) {
|
|
1278
1179
|
acc[key] = obj[key];
|
|
@@ -1665,14 +1566,7 @@ var series = (items, toKey = (item) => `${item}`) => {
|
|
|
1665
1566
|
|
|
1666
1567
|
// src/string/camel.ts
|
|
1667
1568
|
function camel(str) {
|
|
1668
|
-
|
|
1669
|
-
const parts = ((_a = str == null ? void 0 : str.replace(/([A-Z])+/g, capitalize)) == null ? void 0 : _a.split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase())) ?? [];
|
|
1670
|
-
if (parts.length === 0) {
|
|
1671
|
-
return "";
|
|
1672
|
-
}
|
|
1673
|
-
if (parts.length === 1) {
|
|
1674
|
-
return parts[0];
|
|
1675
|
-
}
|
|
1569
|
+
const parts = str.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase());
|
|
1676
1570
|
return parts.reduce((acc, part) => {
|
|
1677
1571
|
return `${acc}${part.charAt(0).toUpperCase()}${part.slice(1)}`;
|
|
1678
1572
|
});
|
|
@@ -1680,23 +1574,13 @@ function camel(str) {
|
|
|
1680
1574
|
|
|
1681
1575
|
// src/string/capitalize.ts
|
|
1682
1576
|
function capitalize(str) {
|
|
1683
|
-
if (!str || str.length === 0) {
|
|
1684
|
-
return "";
|
|
1685
|
-
}
|
|
1686
1577
|
const lower = str.toLowerCase();
|
|
1687
1578
|
return lower.substring(0, 1).toUpperCase() + lower.substring(1, lower.length);
|
|
1688
1579
|
}
|
|
1689
1580
|
|
|
1690
1581
|
// src/string/dash.ts
|
|
1691
1582
|
function dash(str) {
|
|
1692
|
-
|
|
1693
|
-
const parts = ((_a = str == null ? void 0 : str.replace(/([A-Z])+/g, capitalize)) == null ? void 0 : _a.split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase())) ?? [];
|
|
1694
|
-
if (parts.length === 0) {
|
|
1695
|
-
return "";
|
|
1696
|
-
}
|
|
1697
|
-
if (parts.length === 1) {
|
|
1698
|
-
return parts[0];
|
|
1699
|
-
}
|
|
1583
|
+
const parts = str.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase());
|
|
1700
1584
|
return parts.reduce((acc, part) => {
|
|
1701
1585
|
return `${acc}-${part.toLowerCase()}`;
|
|
1702
1586
|
});
|
|
@@ -1741,9 +1625,6 @@ function escapeHTML(input) {
|
|
|
1741
1625
|
|
|
1742
1626
|
// src/string/pascal.ts
|
|
1743
1627
|
function pascal(str) {
|
|
1744
|
-
if (!str) {
|
|
1745
|
-
return "";
|
|
1746
|
-
}
|
|
1747
1628
|
const result = str.replace(
|
|
1748
1629
|
/(?:[^\w\d]|_|\s)+(\w)([A-Z]+)?/g,
|
|
1749
1630
|
(_, firstCharacter, capitalizedLetters) => {
|
|
@@ -1806,13 +1687,7 @@ function similarity(str1, str2) {
|
|
|
1806
1687
|
|
|
1807
1688
|
// src/string/snake.ts
|
|
1808
1689
|
function snake(str, options) {
|
|
1809
|
-
const parts =
|
|
1810
|
-
if (parts.length === 0) {
|
|
1811
|
-
return "";
|
|
1812
|
-
}
|
|
1813
|
-
if (parts.length === 1) {
|
|
1814
|
-
return parts[0];
|
|
1815
|
-
}
|
|
1690
|
+
const parts = str.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase());
|
|
1816
1691
|
const result = parts.reduce((acc, part) => {
|
|
1817
1692
|
return `${acc}_${part.toLowerCase()}`;
|
|
1818
1693
|
});
|
|
@@ -1833,17 +1708,11 @@ function template(str, data, regex = /\{\{(.+?)\}\}/g) {
|
|
|
1833
1708
|
|
|
1834
1709
|
// src/string/title.ts
|
|
1835
1710
|
function title(str) {
|
|
1836
|
-
if (!str) {
|
|
1837
|
-
return "";
|
|
1838
|
-
}
|
|
1839
1711
|
return str.split(/(?=[A-Z])|[\.\-\s_]/).map((s) => s.trim()).filter((s) => !!s).map((s) => capitalize(s.toLowerCase())).join(" ");
|
|
1840
1712
|
}
|
|
1841
1713
|
|
|
1842
1714
|
// src/string/trim.ts
|
|
1843
|
-
function trim(str, charsToTrim
|
|
1844
|
-
if (!str) {
|
|
1845
|
-
return "";
|
|
1846
|
-
}
|
|
1715
|
+
function trim(str, charsToTrim) {
|
|
1847
1716
|
const toTrim = charsToTrim.replace(/[\W]{1}/g, "\\$&");
|
|
1848
1717
|
const regex = new RegExp(`^[${toTrim}]+|[${toTrim}]+$`, "g");
|
|
1849
1718
|
return str.replace(regex, "");
|
|
@@ -1945,7 +1814,7 @@ function isError(value) {
|
|
|
1945
1814
|
|
|
1946
1815
|
// src/typed/isFloat.ts
|
|
1947
1816
|
function isFloat(value) {
|
|
1948
|
-
return isNumber(value) && value % 1 !== 0;
|
|
1817
|
+
return isNumber(value) && !Number.isNaN(value) && value % 1 !== 0;
|
|
1949
1818
|
}
|
|
1950
1819
|
|
|
1951
1820
|
// src/typed/isFunction.ts
|
|
@@ -1982,7 +1851,7 @@ function isNullish(value) {
|
|
|
1982
1851
|
|
|
1983
1852
|
// src/typed/isNumber.ts
|
|
1984
1853
|
function isNumber(value) {
|
|
1985
|
-
return typeof value === "number"
|
|
1854
|
+
return typeof value === "number";
|
|
1986
1855
|
}
|
|
1987
1856
|
|
|
1988
1857
|
// src/typed/isObject.ts
|
|
@@ -2182,6 +2051,7 @@ exports.pascal = pascal;
|
|
|
2182
2051
|
exports.pick = pick;
|
|
2183
2052
|
exports.pluck = pluck;
|
|
2184
2053
|
exports.promiseChain = promiseChain;
|
|
2054
|
+
exports.promiseMemo = promiseMemo;
|
|
2185
2055
|
exports.proxied = proxied;
|
|
2186
2056
|
exports.queueByKey = queueByKey;
|
|
2187
2057
|
exports.random = random;
|