radashi 12.3.4 → 13.0.0-beta.ffa4778
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 +39 -193
- package/dist/radashi.d.cts +21 -18
- package/dist/radashi.d.ts +21 -18
- package/dist/radashi.js +39 -193
- 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
|
|
@@ -56,9 +50,6 @@ function cluster(array, size = 2) {
|
|
|
56
50
|
|
|
57
51
|
// src/array/counting.ts
|
|
58
52
|
function counting(array, identity) {
|
|
59
|
-
if (!array) {
|
|
60
|
-
return {};
|
|
61
|
-
}
|
|
62
53
|
return array.reduce(
|
|
63
54
|
(acc, item) => {
|
|
64
55
|
const id = identity(item);
|
|
@@ -71,15 +62,6 @@ function counting(array, identity) {
|
|
|
71
62
|
|
|
72
63
|
// src/array/diff.ts
|
|
73
64
|
function diff(root, other, identity = (t) => t) {
|
|
74
|
-
if (!(root == null ? void 0 : root.length) && !(other == null ? void 0 : other.length)) {
|
|
75
|
-
return [];
|
|
76
|
-
}
|
|
77
|
-
if ((root == null ? void 0 : root.length) === void 0) {
|
|
78
|
-
return [...other];
|
|
79
|
-
}
|
|
80
|
-
if (!(other == null ? void 0 : other.length)) {
|
|
81
|
-
return [...root];
|
|
82
|
-
}
|
|
83
65
|
const bKeys = other.reduce(
|
|
84
66
|
(acc, item) => {
|
|
85
67
|
acc[identity(item)] = true;
|
|
@@ -92,7 +74,7 @@ function diff(root, other, identity = (t) => t) {
|
|
|
92
74
|
|
|
93
75
|
// src/array/first.ts
|
|
94
76
|
function first(array, defaultValue) {
|
|
95
|
-
return
|
|
77
|
+
return array.length > 0 ? array[0] : defaultValue;
|
|
96
78
|
}
|
|
97
79
|
|
|
98
80
|
// src/array/flat.ts
|
|
@@ -106,10 +88,8 @@ function flat(lists) {
|
|
|
106
88
|
// src/array/fork.ts
|
|
107
89
|
function fork(array, condition) {
|
|
108
90
|
const forked = [[], []];
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
forked[condition(item) ? 0 : 1].push(item);
|
|
112
|
-
}
|
|
91
|
+
for (const item of array) {
|
|
92
|
+
forked[condition(item) ? 0 : 1].push(item);
|
|
113
93
|
}
|
|
114
94
|
return forked;
|
|
115
95
|
}
|
|
@@ -131,9 +111,6 @@ function group(array, getGroupId) {
|
|
|
131
111
|
|
|
132
112
|
// src/array/intersects.ts
|
|
133
113
|
function intersects(listA, listB, identity) {
|
|
134
|
-
if (!listA || !listB) {
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
114
|
if (identity) {
|
|
138
115
|
const known = new Set(listA.map(identity));
|
|
139
116
|
return listB.some((item) => known.has(identity(item)));
|
|
@@ -152,7 +129,7 @@ function iterate(count, func, initValue) {
|
|
|
152
129
|
|
|
153
130
|
// src/array/last.ts
|
|
154
131
|
function last(array, defaultValue) {
|
|
155
|
-
return
|
|
132
|
+
return array.length > 0 ? array[array.length - 1] : defaultValue;
|
|
156
133
|
}
|
|
157
134
|
|
|
158
135
|
// src/array/list.ts
|
|
@@ -171,18 +148,6 @@ function mapify(array, getKey, getValue = (item) => item) {
|
|
|
171
148
|
|
|
172
149
|
// src/array/merge.ts
|
|
173
150
|
function merge(prev, array, toKey) {
|
|
174
|
-
if (!array && !prev) {
|
|
175
|
-
return [];
|
|
176
|
-
}
|
|
177
|
-
if (!array) {
|
|
178
|
-
return [...prev];
|
|
179
|
-
}
|
|
180
|
-
if (!prev) {
|
|
181
|
-
return [];
|
|
182
|
-
}
|
|
183
|
-
if (!toKey) {
|
|
184
|
-
return [...prev];
|
|
185
|
-
}
|
|
186
151
|
const keys2 = /* @__PURE__ */ new Map();
|
|
187
152
|
for (const item of array) {
|
|
188
153
|
keys2.set(toKey(item), item);
|
|
@@ -206,9 +171,6 @@ function objectify(array, getKey, getValue = (item) => item) {
|
|
|
206
171
|
|
|
207
172
|
// src/array/replace.ts
|
|
208
173
|
function replace(array, newItem, match) {
|
|
209
|
-
if (!array) {
|
|
210
|
-
return [];
|
|
211
|
-
}
|
|
212
174
|
if (newItem === void 0) {
|
|
213
175
|
return [...array];
|
|
214
176
|
}
|
|
@@ -224,15 +186,9 @@ function replace(array, newItem, match) {
|
|
|
224
186
|
|
|
225
187
|
// src/array/replaceOrAppend.ts
|
|
226
188
|
function replaceOrAppend(array, newItem, match) {
|
|
227
|
-
if (
|
|
228
|
-
return [];
|
|
229
|
-
}
|
|
230
|
-
if (!newItem) {
|
|
189
|
+
if (newItem === void 0) {
|
|
231
190
|
return [...array];
|
|
232
191
|
}
|
|
233
|
-
if (!array) {
|
|
234
|
-
return [newItem];
|
|
235
|
-
}
|
|
236
192
|
const out = array.slice();
|
|
237
193
|
for (let index = 0; index < array.length; index++) {
|
|
238
194
|
if (match(array[index], index)) {
|
|
@@ -246,9 +202,6 @@ function replaceOrAppend(array, newItem, match) {
|
|
|
246
202
|
|
|
247
203
|
// src/array/select.ts
|
|
248
204
|
function select(array, mapper, condition) {
|
|
249
|
-
if (!array) {
|
|
250
|
-
return [];
|
|
251
|
-
}
|
|
252
205
|
let mapped;
|
|
253
206
|
return array.reduce((acc, item, index) => {
|
|
254
207
|
if (condition) {
|
|
@@ -262,9 +215,6 @@ function select(array, mapper, condition) {
|
|
|
262
215
|
|
|
263
216
|
// src/array/selectFirst.ts
|
|
264
217
|
function selectFirst(array, mapper, condition) {
|
|
265
|
-
if (!array) {
|
|
266
|
-
return void 0;
|
|
267
|
-
}
|
|
268
218
|
let foundIndex = -1;
|
|
269
219
|
const found = array.find((item, index) => {
|
|
270
220
|
foundIndex = index;
|
|
@@ -292,9 +242,6 @@ function sift(array) {
|
|
|
292
242
|
|
|
293
243
|
// src/array/sort.ts
|
|
294
244
|
function sort(array, getter, desc = false) {
|
|
295
|
-
if (!array) {
|
|
296
|
-
return [];
|
|
297
|
-
}
|
|
298
245
|
const asc = (a, b) => getter(a) - getter(b);
|
|
299
246
|
const dsc = (a, b) => getter(b) - getter(a);
|
|
300
247
|
return array.slice().sort(desc === true ? dsc : asc);
|
|
@@ -302,9 +249,6 @@ function sort(array, getter, desc = false) {
|
|
|
302
249
|
|
|
303
250
|
// src/array/toggle.ts
|
|
304
251
|
function toggle(array, item, toKey, options) {
|
|
305
|
-
if (!array) {
|
|
306
|
-
return item !== void 0 ? [item] : [];
|
|
307
|
-
}
|
|
308
252
|
if (item === void 0) {
|
|
309
253
|
return [...array];
|
|
310
254
|
}
|
|
@@ -340,9 +284,6 @@ function unique(array, toKey) {
|
|
|
340
284
|
|
|
341
285
|
// src/array/unzip.ts
|
|
342
286
|
function unzip(arrays) {
|
|
343
|
-
if (!arrays || !arrays.length) {
|
|
344
|
-
return [];
|
|
345
|
-
}
|
|
346
287
|
const out = new Array(
|
|
347
288
|
arrays.reduce((max2, arr) => Math.max(max2, arr.length), 0)
|
|
348
289
|
);
|
|
@@ -361,9 +302,6 @@ function zip(...arrays) {
|
|
|
361
302
|
|
|
362
303
|
// src/array/zipToObject.ts
|
|
363
304
|
function zipToObject(keys2, values) {
|
|
364
|
-
if (!keys2 || !keys2.length) {
|
|
365
|
-
return {};
|
|
366
|
-
}
|
|
367
305
|
const getValue = isFunction(values) ? values : isArray(values) ? (_k, i) => values[i] : (_k, _i) => values;
|
|
368
306
|
return keys2.reduce(
|
|
369
307
|
(acc, key, idx) => {
|
|
@@ -450,9 +388,6 @@ function guard(func, shouldGuard) {
|
|
|
450
388
|
|
|
451
389
|
// src/async/map.ts
|
|
452
390
|
async function map(array, asyncMapFunc) {
|
|
453
|
-
if (!array) {
|
|
454
|
-
return [];
|
|
455
|
-
}
|
|
456
391
|
const result = [];
|
|
457
392
|
let index = 0;
|
|
458
393
|
for (const value of array) {
|
|
@@ -522,9 +457,6 @@ async function parallel(options, array, func) {
|
|
|
522
457
|
|
|
523
458
|
// src/async/reduce.ts
|
|
524
459
|
async function reduce(array, reducer, initialValue) {
|
|
525
|
-
if (!array) {
|
|
526
|
-
array = [];
|
|
527
|
-
}
|
|
528
460
|
const indices = array.keys();
|
|
529
461
|
let acc = initialValue;
|
|
530
462
|
if (acc === void 0 && arguments.length < 3) {
|
|
@@ -644,31 +576,30 @@ function compose(...funcs) {
|
|
|
644
576
|
}
|
|
645
577
|
|
|
646
578
|
// src/curry/debounce.ts
|
|
647
|
-
function debounce({ delay, leading },
|
|
648
|
-
let
|
|
649
|
-
let active = true;
|
|
579
|
+
function debounce({ delay, leading }, callee) {
|
|
580
|
+
let timeout2;
|
|
650
581
|
const debounced = (...args) => {
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
timer = void 0;
|
|
656
|
-
}, delay);
|
|
657
|
-
if (leading) {
|
|
658
|
-
func(...args);
|
|
659
|
-
leading = false;
|
|
660
|
-
}
|
|
582
|
+
clearTimeout(timeout2);
|
|
583
|
+
if (leading) {
|
|
584
|
+
leading = false;
|
|
585
|
+
callee(...args);
|
|
661
586
|
} else {
|
|
662
|
-
|
|
587
|
+
timeout2 = setTimeout(
|
|
588
|
+
debounced.flush = () => {
|
|
589
|
+
debounced.flush = noop;
|
|
590
|
+
clearTimeout(timeout2);
|
|
591
|
+
callee(...args);
|
|
592
|
+
},
|
|
593
|
+
delay
|
|
594
|
+
);
|
|
663
595
|
}
|
|
664
596
|
};
|
|
665
|
-
debounced.
|
|
666
|
-
|
|
667
|
-
};
|
|
597
|
+
debounced.callee = callee;
|
|
598
|
+
debounced.flush = noop;
|
|
668
599
|
debounced.cancel = () => {
|
|
669
|
-
|
|
600
|
+
debounced.flush = noop;
|
|
601
|
+
clearTimeout(timeout2);
|
|
670
602
|
};
|
|
671
|
-
debounced.flush = (...args) => func(...args);
|
|
672
603
|
return debounced;
|
|
673
604
|
}
|
|
674
605
|
|
|
@@ -807,15 +738,7 @@ function clamp(n, min2, max2) {
|
|
|
807
738
|
}
|
|
808
739
|
|
|
809
740
|
// src/number/inRange.ts
|
|
810
|
-
function inRange(number, start, end) {
|
|
811
|
-
const isTypeSafe = typeof number === "number" && typeof start === "number" && (typeof end === "undefined" || typeof end === "number");
|
|
812
|
-
if (!isTypeSafe) {
|
|
813
|
-
return false;
|
|
814
|
-
}
|
|
815
|
-
if (typeof end === "undefined") {
|
|
816
|
-
end = start;
|
|
817
|
-
start = 0;
|
|
818
|
-
}
|
|
741
|
+
function inRange(number, start, end = 0) {
|
|
819
742
|
return number >= Math.min(start, end) && number < Math.max(start, end);
|
|
820
743
|
}
|
|
821
744
|
|
|
@@ -826,7 +749,7 @@ function lerp(from, to, amount) {
|
|
|
826
749
|
|
|
827
750
|
// src/number/max.ts
|
|
828
751
|
function max(array, getter) {
|
|
829
|
-
if (!array
|
|
752
|
+
if (!array.length) {
|
|
830
753
|
return null;
|
|
831
754
|
}
|
|
832
755
|
const get2 = getter ?? ((v) => v);
|
|
@@ -835,7 +758,7 @@ function max(array, getter) {
|
|
|
835
758
|
|
|
836
759
|
// src/number/min.ts
|
|
837
760
|
function min(array, getter) {
|
|
838
|
-
if (!array
|
|
761
|
+
if (!array.length) {
|
|
839
762
|
return null;
|
|
840
763
|
}
|
|
841
764
|
const get2 = getter ?? ((v) => v);
|
|
@@ -885,9 +808,6 @@ function toInt(value, defaultValue) {
|
|
|
885
808
|
|
|
886
809
|
// src/object/assign.ts
|
|
887
810
|
function assign(initial, override) {
|
|
888
|
-
if (!initial || !override) {
|
|
889
|
-
return initial ?? override ?? {};
|
|
890
|
-
}
|
|
891
811
|
const proto = Object.getPrototypeOf(initial);
|
|
892
812
|
const merged = proto ? { ...initial } : Object.assign(Object.create(proto), initial);
|
|
893
813
|
for (const key of Object.keys(override)) {
|
|
@@ -898,12 +818,6 @@ function assign(initial, override) {
|
|
|
898
818
|
|
|
899
819
|
// src/object/clone.ts
|
|
900
820
|
function clone(obj) {
|
|
901
|
-
if (isPrimitive(obj)) {
|
|
902
|
-
return obj;
|
|
903
|
-
}
|
|
904
|
-
if (typeof obj === "function") {
|
|
905
|
-
return obj.bind({});
|
|
906
|
-
}
|
|
907
821
|
const proto = Object.getPrototypeOf(obj);
|
|
908
822
|
const newObj = typeof (proto == null ? void 0 : proto.constructor) === "function" ? new proto.constructor() : Object.create(proto);
|
|
909
823
|
for (const key of Object.getOwnPropertyNames(obj)) {
|
|
@@ -981,9 +895,6 @@ function cloneDeep(root, customStrategy) {
|
|
|
981
895
|
|
|
982
896
|
// src/object/construct.ts
|
|
983
897
|
function construct(obj) {
|
|
984
|
-
if (!obj) {
|
|
985
|
-
return {};
|
|
986
|
-
}
|
|
987
898
|
return Object.keys(obj).reduce((acc, path) => {
|
|
988
899
|
return set(acc, path, obj[path]);
|
|
989
900
|
}, {});
|
|
@@ -991,9 +902,6 @@ function construct(obj) {
|
|
|
991
902
|
|
|
992
903
|
// src/object/crush.ts
|
|
993
904
|
function crush(value) {
|
|
994
|
-
if (!value) {
|
|
995
|
-
return {};
|
|
996
|
-
}
|
|
997
905
|
return function crushReducer(crushed, value2, path) {
|
|
998
906
|
if (isObject(value2) || isArray(value2)) {
|
|
999
907
|
for (const [prop, propValue] of Object.entries(value2)) {
|
|
@@ -1036,9 +944,6 @@ function get(value, path, defaultValue) {
|
|
|
1036
944
|
|
|
1037
945
|
// src/object/invert.ts
|
|
1038
946
|
function invert(obj) {
|
|
1039
|
-
if (!obj) {
|
|
1040
|
-
return {};
|
|
1041
|
-
}
|
|
1042
947
|
const keys2 = Object.keys(obj);
|
|
1043
948
|
return keys2.reduce(
|
|
1044
949
|
(acc, key) => {
|
|
@@ -1051,9 +956,6 @@ function invert(obj) {
|
|
|
1051
956
|
|
|
1052
957
|
// src/object/keys.ts
|
|
1053
958
|
function keys(value) {
|
|
1054
|
-
if (!value) {
|
|
1055
|
-
return [];
|
|
1056
|
-
}
|
|
1057
959
|
const keys2 = [];
|
|
1058
960
|
const keyPath = [];
|
|
1059
961
|
const recurse = (value2) => {
|
|
@@ -1079,14 +981,7 @@ function keys(value) {
|
|
|
1079
981
|
|
|
1080
982
|
// src/object/listify.ts
|
|
1081
983
|
function listify(obj, toItem) {
|
|
1082
|
-
|
|
1083
|
-
return [];
|
|
1084
|
-
}
|
|
1085
|
-
const entries = Object.entries(obj);
|
|
1086
|
-
if (entries.length === 0) {
|
|
1087
|
-
return [];
|
|
1088
|
-
}
|
|
1089
|
-
return entries.reduce((acc, entry) => {
|
|
984
|
+
return Object.entries(obj).reduce((acc, entry) => {
|
|
1090
985
|
acc.push(toItem(entry[0], entry[1]));
|
|
1091
986
|
return acc;
|
|
1092
987
|
}, []);
|
|
@@ -1099,9 +994,6 @@ function lowerize(obj) {
|
|
|
1099
994
|
|
|
1100
995
|
// src/object/mapEntries.ts
|
|
1101
996
|
function mapEntries(obj, toEntry) {
|
|
1102
|
-
if (!obj) {
|
|
1103
|
-
return {};
|
|
1104
|
-
}
|
|
1105
997
|
return Object.entries(obj).reduce(
|
|
1106
998
|
(acc, [key, value]) => {
|
|
1107
999
|
const [newKey, newValue] = toEntry(key, value);
|
|
@@ -1137,10 +1029,7 @@ function mapValues(obj, mapFunc) {
|
|
|
1137
1029
|
|
|
1138
1030
|
// src/object/omit.ts
|
|
1139
1031
|
function omit(obj, keys2) {
|
|
1140
|
-
if (
|
|
1141
|
-
return {};
|
|
1142
|
-
}
|
|
1143
|
-
if (!keys2 || keys2.length === 0) {
|
|
1032
|
+
if (keys2.length === 0) {
|
|
1144
1033
|
return obj;
|
|
1145
1034
|
}
|
|
1146
1035
|
return keys2.reduce(
|
|
@@ -1154,9 +1043,6 @@ function omit(obj, keys2) {
|
|
|
1154
1043
|
|
|
1155
1044
|
// src/object/pick.ts
|
|
1156
1045
|
function pick(obj, filter) {
|
|
1157
|
-
if (!obj) {
|
|
1158
|
-
return {};
|
|
1159
|
-
}
|
|
1160
1046
|
let keys2 = filter;
|
|
1161
1047
|
if (isArray(filter)) {
|
|
1162
1048
|
filter = null;
|
|
@@ -1173,28 +1059,20 @@ function pick(obj, filter) {
|
|
|
1173
1059
|
|
|
1174
1060
|
// src/object/set.ts
|
|
1175
1061
|
function set(initial, path, value) {
|
|
1176
|
-
if (
|
|
1177
|
-
return {};
|
|
1178
|
-
}
|
|
1179
|
-
if (!path || value === void 0) {
|
|
1062
|
+
if (value === void 0) {
|
|
1180
1063
|
return initial;
|
|
1181
1064
|
}
|
|
1182
1065
|
const root = clone(initial);
|
|
1183
1066
|
const keys2 = path.match(/[^.[\]]+/g);
|
|
1184
|
-
|
|
1185
|
-
keys2.
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
);
|
|
1189
|
-
}
|
|
1067
|
+
keys2 == null ? void 0 : keys2.reduce(
|
|
1068
|
+
(object, key, i) => i < keys2.length - 1 ? object[key] ??= isIntString(keys2[i + 1]) ? [] : {} : object[key] = value,
|
|
1069
|
+
root
|
|
1070
|
+
);
|
|
1190
1071
|
return root;
|
|
1191
1072
|
}
|
|
1192
1073
|
|
|
1193
1074
|
// src/object/shake.ts
|
|
1194
1075
|
function shake(obj, filter = (value) => value === void 0) {
|
|
1195
|
-
if (!obj) {
|
|
1196
|
-
return {};
|
|
1197
|
-
}
|
|
1198
1076
|
return Object.keys(obj).reduce((acc, key) => {
|
|
1199
1077
|
if (!filter(obj[key])) {
|
|
1200
1078
|
acc[key] = obj[key];
|
|
@@ -1401,14 +1279,7 @@ var series = (items, toKey = (item) => `${item}`) => {
|
|
|
1401
1279
|
|
|
1402
1280
|
// src/string/camel.ts
|
|
1403
1281
|
function camel(str) {
|
|
1404
|
-
|
|
1405
|
-
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())) ?? [];
|
|
1406
|
-
if (parts.length === 0) {
|
|
1407
|
-
return "";
|
|
1408
|
-
}
|
|
1409
|
-
if (parts.length === 1) {
|
|
1410
|
-
return parts[0];
|
|
1411
|
-
}
|
|
1282
|
+
const parts = str.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase());
|
|
1412
1283
|
return parts.reduce((acc, part) => {
|
|
1413
1284
|
return `${acc}${part.charAt(0).toUpperCase()}${part.slice(1)}`;
|
|
1414
1285
|
});
|
|
@@ -1416,23 +1287,13 @@ function camel(str) {
|
|
|
1416
1287
|
|
|
1417
1288
|
// src/string/capitalize.ts
|
|
1418
1289
|
function capitalize(str) {
|
|
1419
|
-
if (!str || str.length === 0) {
|
|
1420
|
-
return "";
|
|
1421
|
-
}
|
|
1422
1290
|
const lower = str.toLowerCase();
|
|
1423
1291
|
return lower.substring(0, 1).toUpperCase() + lower.substring(1, lower.length);
|
|
1424
1292
|
}
|
|
1425
1293
|
|
|
1426
1294
|
// src/string/dash.ts
|
|
1427
1295
|
function dash(str) {
|
|
1428
|
-
|
|
1429
|
-
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())) ?? [];
|
|
1430
|
-
if (parts.length === 0) {
|
|
1431
|
-
return "";
|
|
1432
|
-
}
|
|
1433
|
-
if (parts.length === 1) {
|
|
1434
|
-
return parts[0];
|
|
1435
|
-
}
|
|
1296
|
+
const parts = str.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase());
|
|
1436
1297
|
return parts.reduce((acc, part) => {
|
|
1437
1298
|
return `${acc}-${part.toLowerCase()}`;
|
|
1438
1299
|
});
|
|
@@ -1464,9 +1325,6 @@ function dedent(text, ...values) {
|
|
|
1464
1325
|
|
|
1465
1326
|
// src/string/pascal.ts
|
|
1466
1327
|
function pascal(str) {
|
|
1467
|
-
if (!str) {
|
|
1468
|
-
return "";
|
|
1469
|
-
}
|
|
1470
1328
|
const result = str.replace(
|
|
1471
1329
|
/(?:[^\w\d]|_|\s)+(\w)([A-Z]+)?/g,
|
|
1472
1330
|
(_, firstCharacter, capitalizedLetters) => {
|
|
@@ -1529,13 +1387,7 @@ function similarity(str1, str2) {
|
|
|
1529
1387
|
|
|
1530
1388
|
// src/string/snake.ts
|
|
1531
1389
|
function snake(str, options) {
|
|
1532
|
-
const parts =
|
|
1533
|
-
if (parts.length === 0) {
|
|
1534
|
-
return "";
|
|
1535
|
-
}
|
|
1536
|
-
if (parts.length === 1) {
|
|
1537
|
-
return parts[0];
|
|
1538
|
-
}
|
|
1390
|
+
const parts = str.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase());
|
|
1539
1391
|
const result = parts.reduce((acc, part) => {
|
|
1540
1392
|
return `${acc}_${part.toLowerCase()}`;
|
|
1541
1393
|
});
|
|
@@ -1556,17 +1408,11 @@ function template(str, data, regex = /\{\{(.+?)\}\}/g) {
|
|
|
1556
1408
|
|
|
1557
1409
|
// src/string/title.ts
|
|
1558
1410
|
function title(str) {
|
|
1559
|
-
if (!str) {
|
|
1560
|
-
return "";
|
|
1561
|
-
}
|
|
1562
1411
|
return str.split(/(?=[A-Z])|[\.\-\s_]/).map((s) => s.trim()).filter((s) => !!s).map((s) => capitalize(s.toLowerCase())).join(" ");
|
|
1563
1412
|
}
|
|
1564
1413
|
|
|
1565
1414
|
// src/string/trim.ts
|
|
1566
1415
|
function trim(str, charsToTrim = " ") {
|
|
1567
|
-
if (!str) {
|
|
1568
|
-
return "";
|
|
1569
|
-
}
|
|
1570
1416
|
const toTrim = charsToTrim.replace(/[\W]{1}/g, "\\$&");
|
|
1571
1417
|
const regex = new RegExp(`^[${toTrim}]+|[${toTrim}]+$`, "g");
|
|
1572
1418
|
return str.replace(regex, "");
|
|
@@ -1659,7 +1505,7 @@ function isError(value) {
|
|
|
1659
1505
|
|
|
1660
1506
|
// src/typed/isFloat.ts
|
|
1661
1507
|
function isFloat(value) {
|
|
1662
|
-
return isNumber(value) && value % 1 !== 0;
|
|
1508
|
+
return isNumber(value) && !Number.isNaN(value) && value % 1 !== 0;
|
|
1663
1509
|
}
|
|
1664
1510
|
|
|
1665
1511
|
// src/typed/isFunction.ts
|
|
@@ -1696,7 +1542,7 @@ function isNullish(value) {
|
|
|
1696
1542
|
|
|
1697
1543
|
// src/typed/isNumber.ts
|
|
1698
1544
|
function isNumber(value) {
|
|
1699
|
-
return typeof value === "number"
|
|
1545
|
+
return typeof value === "number";
|
|
1700
1546
|
}
|
|
1701
1547
|
|
|
1702
1548
|
// src/typed/isObject.ts
|
package/dist/radashi.d.cts
CHANGED
|
@@ -332,6 +332,7 @@ declare function merge<T>(prev: readonly T[], array: readonly T[], toKey: (item:
|
|
|
332
332
|
*/
|
|
333
333
|
declare function objectify<T, Key extends string | number | symbol, Value = T>(array: readonly T[], getKey: (item: T) => Key, getValue?: (item: T) => Value): Record<Key, Value>;
|
|
334
334
|
|
|
335
|
+
type Defined$1<T> = T & ({} | null);
|
|
335
336
|
/**
|
|
336
337
|
* Replace an element in an array with a new item without modifying
|
|
337
338
|
* the array and return the new value.
|
|
@@ -344,8 +345,9 @@ declare function objectify<T, Key extends string | number | symbol, Value = T>(a
|
|
|
344
345
|
* ```
|
|
345
346
|
* @version 12.1.0
|
|
346
347
|
*/
|
|
347
|
-
declare function replace<T>(array: readonly T[], newItem:
|
|
348
|
+
declare function replace<T, U>(array: readonly T[], newItem: U, match: (item: T, idx: number) => boolean): (T | Defined$1<U>)[];
|
|
348
349
|
|
|
350
|
+
type Defined<T> = T & ({} | null);
|
|
349
351
|
/**
|
|
350
352
|
* Replace the first occurrence of an item in an array where the
|
|
351
353
|
* `match` function returns true. If no items match, append the new
|
|
@@ -362,7 +364,7 @@ declare function replace<T>(array: readonly T[], newItem: T, match: (item: T, id
|
|
|
362
364
|
* ```
|
|
363
365
|
* @version 12.1.0
|
|
364
366
|
*/
|
|
365
|
-
declare function replaceOrAppend<T>(array: readonly T[], newItem:
|
|
367
|
+
declare function replaceOrAppend<T, U>(array: readonly T[], newItem: U, match: (a: T, idx: number) => boolean): (T | Defined<U>)[];
|
|
366
368
|
|
|
367
369
|
/**
|
|
368
370
|
* Select performs a filter and a mapper inside of a reduce, only
|
|
@@ -945,7 +947,7 @@ declare function compose<F1Result, F1Args extends any[], F1NextArgs extends any[
|
|
|
945
947
|
declare function compose<F1Result, F1Args extends any[], F1NextArgs extends any[], F2NextArgs extends any[], F2Result, F3NextArgs extends any[], F3Result, F4NextArgs extends any[], F4Result, F5NextArgs extends any[], F5Result, F6NextArgs extends any[], F6Result, F7NextArgs extends any[], F7Result, F8NextArgs extends any[], F8Result, LastResult>(f1: (next: (...args: F1NextArgs) => F2Result) => (...args: F1Args) => F1Result, f2: (next: (...args: F2NextArgs) => F3Result) => (...args: F1NextArgs) => F2Result, f3: (next: (...args: F3NextArgs) => F4Result) => (...args: F2NextArgs) => F3Result, f4: (next: (...args: F4NextArgs) => F5Result) => (...args: F3NextArgs) => F4Result, f5: (next: (...args: F5NextArgs) => F6Result) => (...args: F4NextArgs) => F5Result, f6: (next: (...args: F6NextArgs) => F7Result) => (...args: F5NextArgs) => F6Result, f7: (next: (...args: F7NextArgs) => LastResult) => (...args: F6NextArgs) => F7Result, f8: (next: (...args: F8NextArgs) => LastResult) => (...args: F7NextArgs) => F8Result, last: (...args: F8NextArgs) => LastResult): (...args: F1Args) => F1Result;
|
|
946
948
|
declare function compose<F1Result, F1Args extends any[], F1NextArgs extends any[], F2NextArgs extends any[], F2Result, F3NextArgs extends any[], F3Result, F4NextArgs extends any[], F4Result, F5NextArgs extends any[], F5Result, F6NextArgs extends any[], F6Result, F7NextArgs extends any[], F7Result, F8NextArgs extends any[], F8Result, F9NextArgs extends any[], F9Result, LastResult>(f1: (next: (...args: F1NextArgs) => F2Result) => (...args: F1Args) => F1Result, f2: (next: (...args: F2NextArgs) => F3Result) => (...args: F1NextArgs) => F2Result, f3: (next: (...args: F3NextArgs) => F4Result) => (...args: F2NextArgs) => F3Result, f4: (next: (...args: F4NextArgs) => F5Result) => (...args: F3NextArgs) => F4Result, f5: (next: (...args: F5NextArgs) => F6Result) => (...args: F4NextArgs) => F5Result, f6: (next: (...args: F6NextArgs) => F7Result) => (...args: F5NextArgs) => F6Result, f7: (next: (...args: F7NextArgs) => LastResult) => (...args: F6NextArgs) => F7Result, f8: (next: (...args: F8NextArgs) => LastResult) => (...args: F7NextArgs) => F8Result, f9: (next: (...args: F9NextArgs) => LastResult) => (...args: F8NextArgs) => F9Result, last: (...args: F9NextArgs) => LastResult): (...args: F1Args) => F1Result;
|
|
947
949
|
|
|
948
|
-
|
|
950
|
+
interface DebounceFunction<TArgs extends any[] = any> {
|
|
949
951
|
(...args: TArgs): void;
|
|
950
952
|
/**
|
|
951
953
|
* When called, future invocations of the debounced function are
|
|
@@ -953,15 +955,16 @@ type DebounceFunction<TArgs extends any[]> = {
|
|
|
953
955
|
*/
|
|
954
956
|
cancel(): void;
|
|
955
957
|
/**
|
|
956
|
-
*
|
|
957
|
-
*
|
|
958
|
+
* If the debounced function is pending, it will be invoked
|
|
959
|
+
* immediately and the result will be returned. Otherwise,
|
|
960
|
+
* `undefined` will be returned.
|
|
958
961
|
*/
|
|
959
|
-
|
|
962
|
+
flush(...args: TArgs): void;
|
|
960
963
|
/**
|
|
961
|
-
*
|
|
964
|
+
* The underlying function
|
|
962
965
|
*/
|
|
963
|
-
|
|
964
|
-
}
|
|
966
|
+
readonly callee: (...args: TArgs) => unknown;
|
|
967
|
+
}
|
|
965
968
|
interface DebounceOptions {
|
|
966
969
|
delay: number;
|
|
967
970
|
/**
|
|
@@ -974,11 +977,11 @@ interface DebounceOptions {
|
|
|
974
977
|
leading?: boolean;
|
|
975
978
|
}
|
|
976
979
|
/**
|
|
977
|
-
* Returns a new function that will only call
|
|
978
|
-
* `delay` milliseconds have passed without any invocations.
|
|
980
|
+
* Returns a new function that will only call the source function
|
|
981
|
+
* after `delay` milliseconds have passed without any invocations.
|
|
979
982
|
*
|
|
980
|
-
*
|
|
981
|
-
*
|
|
983
|
+
* See the documentation (or the `DebounceFunction` type) for details
|
|
984
|
+
* on the methods and properties available on the returned function.
|
|
982
985
|
*
|
|
983
986
|
* @see https://radashi.js.org/reference/curry/debounce
|
|
984
987
|
* @example
|
|
@@ -993,7 +996,7 @@ interface DebounceOptions {
|
|
|
993
996
|
* ```
|
|
994
997
|
* @version 12.1.0
|
|
995
998
|
*/
|
|
996
|
-
declare function debounce<TArgs extends any[]>({ delay, leading }: DebounceOptions,
|
|
999
|
+
declare function debounce<TArgs extends any[]>({ delay, leading }: DebounceOptions, callee: (...args: TArgs) => unknown): DebounceFunction<TArgs>;
|
|
997
1000
|
|
|
998
1001
|
/**
|
|
999
1002
|
* Flip the first two arguments of a function.
|
|
@@ -1635,7 +1638,7 @@ TOverride | (IsOptional extends true ? TInitial : never) : Extract<TOverride, ob
|
|
|
1635
1638
|
* ```
|
|
1636
1639
|
* @version 12.1.0
|
|
1637
1640
|
*/
|
|
1638
|
-
declare function clone<T>(obj: T): T;
|
|
1641
|
+
declare function clone<T extends object>(obj: T): T;
|
|
1639
1642
|
|
|
1640
1643
|
/**
|
|
1641
1644
|
* A strategy for cloning objects with `cloneDeep`.
|
|
@@ -2357,7 +2360,7 @@ declare function template(str: string, data: Record<string, any>, regex?: RegExp
|
|
|
2357
2360
|
* ```
|
|
2358
2361
|
* @version 12.1.0
|
|
2359
2362
|
*/
|
|
2360
|
-
declare function title(str: string
|
|
2363
|
+
declare function title(str: string): string;
|
|
2361
2364
|
|
|
2362
2365
|
/**
|
|
2363
2366
|
* Trims all prefix and suffix characters from the given string. Like
|
|
@@ -2374,7 +2377,7 @@ declare function title(str: string | null | undefined): string;
|
|
|
2374
2377
|
* ```
|
|
2375
2378
|
* @version 12.1.0
|
|
2376
2379
|
*/
|
|
2377
|
-
declare function trim(str: string
|
|
2380
|
+
declare function trim(str: string, charsToTrim?: string): string;
|
|
2378
2381
|
|
|
2379
2382
|
/**
|
|
2380
2383
|
* Literally just `Array.isArray` but with better type inference.
|
|
@@ -2620,7 +2623,7 @@ declare function isNullish(value: unknown): value is null | undefined;
|
|
|
2620
2623
|
* ```ts
|
|
2621
2624
|
* isNumber(0) // => true
|
|
2622
2625
|
* isNumber('0') // => false
|
|
2623
|
-
* isNumber(NaN) // =>
|
|
2626
|
+
* isNumber(NaN) // => true
|
|
2624
2627
|
* ```
|
|
2625
2628
|
* @version 12.1.0
|
|
2626
2629
|
*/
|
package/dist/radashi.d.ts
CHANGED
|
@@ -332,6 +332,7 @@ declare function merge<T>(prev: readonly T[], array: readonly T[], toKey: (item:
|
|
|
332
332
|
*/
|
|
333
333
|
declare function objectify<T, Key extends string | number | symbol, Value = T>(array: readonly T[], getKey: (item: T) => Key, getValue?: (item: T) => Value): Record<Key, Value>;
|
|
334
334
|
|
|
335
|
+
type Defined$1<T> = T & ({} | null);
|
|
335
336
|
/**
|
|
336
337
|
* Replace an element in an array with a new item without modifying
|
|
337
338
|
* the array and return the new value.
|
|
@@ -344,8 +345,9 @@ declare function objectify<T, Key extends string | number | symbol, Value = T>(a
|
|
|
344
345
|
* ```
|
|
345
346
|
* @version 12.1.0
|
|
346
347
|
*/
|
|
347
|
-
declare function replace<T>(array: readonly T[], newItem:
|
|
348
|
+
declare function replace<T, U>(array: readonly T[], newItem: U, match: (item: T, idx: number) => boolean): (T | Defined$1<U>)[];
|
|
348
349
|
|
|
350
|
+
type Defined<T> = T & ({} | null);
|
|
349
351
|
/**
|
|
350
352
|
* Replace the first occurrence of an item in an array where the
|
|
351
353
|
* `match` function returns true. If no items match, append the new
|
|
@@ -362,7 +364,7 @@ declare function replace<T>(array: readonly T[], newItem: T, match: (item: T, id
|
|
|
362
364
|
* ```
|
|
363
365
|
* @version 12.1.0
|
|
364
366
|
*/
|
|
365
|
-
declare function replaceOrAppend<T>(array: readonly T[], newItem:
|
|
367
|
+
declare function replaceOrAppend<T, U>(array: readonly T[], newItem: U, match: (a: T, idx: number) => boolean): (T | Defined<U>)[];
|
|
366
368
|
|
|
367
369
|
/**
|
|
368
370
|
* Select performs a filter and a mapper inside of a reduce, only
|
|
@@ -945,7 +947,7 @@ declare function compose<F1Result, F1Args extends any[], F1NextArgs extends any[
|
|
|
945
947
|
declare function compose<F1Result, F1Args extends any[], F1NextArgs extends any[], F2NextArgs extends any[], F2Result, F3NextArgs extends any[], F3Result, F4NextArgs extends any[], F4Result, F5NextArgs extends any[], F5Result, F6NextArgs extends any[], F6Result, F7NextArgs extends any[], F7Result, F8NextArgs extends any[], F8Result, LastResult>(f1: (next: (...args: F1NextArgs) => F2Result) => (...args: F1Args) => F1Result, f2: (next: (...args: F2NextArgs) => F3Result) => (...args: F1NextArgs) => F2Result, f3: (next: (...args: F3NextArgs) => F4Result) => (...args: F2NextArgs) => F3Result, f4: (next: (...args: F4NextArgs) => F5Result) => (...args: F3NextArgs) => F4Result, f5: (next: (...args: F5NextArgs) => F6Result) => (...args: F4NextArgs) => F5Result, f6: (next: (...args: F6NextArgs) => F7Result) => (...args: F5NextArgs) => F6Result, f7: (next: (...args: F7NextArgs) => LastResult) => (...args: F6NextArgs) => F7Result, f8: (next: (...args: F8NextArgs) => LastResult) => (...args: F7NextArgs) => F8Result, last: (...args: F8NextArgs) => LastResult): (...args: F1Args) => F1Result;
|
|
946
948
|
declare function compose<F1Result, F1Args extends any[], F1NextArgs extends any[], F2NextArgs extends any[], F2Result, F3NextArgs extends any[], F3Result, F4NextArgs extends any[], F4Result, F5NextArgs extends any[], F5Result, F6NextArgs extends any[], F6Result, F7NextArgs extends any[], F7Result, F8NextArgs extends any[], F8Result, F9NextArgs extends any[], F9Result, LastResult>(f1: (next: (...args: F1NextArgs) => F2Result) => (...args: F1Args) => F1Result, f2: (next: (...args: F2NextArgs) => F3Result) => (...args: F1NextArgs) => F2Result, f3: (next: (...args: F3NextArgs) => F4Result) => (...args: F2NextArgs) => F3Result, f4: (next: (...args: F4NextArgs) => F5Result) => (...args: F3NextArgs) => F4Result, f5: (next: (...args: F5NextArgs) => F6Result) => (...args: F4NextArgs) => F5Result, f6: (next: (...args: F6NextArgs) => F7Result) => (...args: F5NextArgs) => F6Result, f7: (next: (...args: F7NextArgs) => LastResult) => (...args: F6NextArgs) => F7Result, f8: (next: (...args: F8NextArgs) => LastResult) => (...args: F7NextArgs) => F8Result, f9: (next: (...args: F9NextArgs) => LastResult) => (...args: F8NextArgs) => F9Result, last: (...args: F9NextArgs) => LastResult): (...args: F1Args) => F1Result;
|
|
947
949
|
|
|
948
|
-
|
|
950
|
+
interface DebounceFunction<TArgs extends any[] = any> {
|
|
949
951
|
(...args: TArgs): void;
|
|
950
952
|
/**
|
|
951
953
|
* When called, future invocations of the debounced function are
|
|
@@ -953,15 +955,16 @@ type DebounceFunction<TArgs extends any[]> = {
|
|
|
953
955
|
*/
|
|
954
956
|
cancel(): void;
|
|
955
957
|
/**
|
|
956
|
-
*
|
|
957
|
-
*
|
|
958
|
+
* If the debounced function is pending, it will be invoked
|
|
959
|
+
* immediately and the result will be returned. Otherwise,
|
|
960
|
+
* `undefined` will be returned.
|
|
958
961
|
*/
|
|
959
|
-
|
|
962
|
+
flush(...args: TArgs): void;
|
|
960
963
|
/**
|
|
961
|
-
*
|
|
964
|
+
* The underlying function
|
|
962
965
|
*/
|
|
963
|
-
|
|
964
|
-
}
|
|
966
|
+
readonly callee: (...args: TArgs) => unknown;
|
|
967
|
+
}
|
|
965
968
|
interface DebounceOptions {
|
|
966
969
|
delay: number;
|
|
967
970
|
/**
|
|
@@ -974,11 +977,11 @@ interface DebounceOptions {
|
|
|
974
977
|
leading?: boolean;
|
|
975
978
|
}
|
|
976
979
|
/**
|
|
977
|
-
* Returns a new function that will only call
|
|
978
|
-
* `delay` milliseconds have passed without any invocations.
|
|
980
|
+
* Returns a new function that will only call the source function
|
|
981
|
+
* after `delay` milliseconds have passed without any invocations.
|
|
979
982
|
*
|
|
980
|
-
*
|
|
981
|
-
*
|
|
983
|
+
* See the documentation (or the `DebounceFunction` type) for details
|
|
984
|
+
* on the methods and properties available on the returned function.
|
|
982
985
|
*
|
|
983
986
|
* @see https://radashi.js.org/reference/curry/debounce
|
|
984
987
|
* @example
|
|
@@ -993,7 +996,7 @@ interface DebounceOptions {
|
|
|
993
996
|
* ```
|
|
994
997
|
* @version 12.1.0
|
|
995
998
|
*/
|
|
996
|
-
declare function debounce<TArgs extends any[]>({ delay, leading }: DebounceOptions,
|
|
999
|
+
declare function debounce<TArgs extends any[]>({ delay, leading }: DebounceOptions, callee: (...args: TArgs) => unknown): DebounceFunction<TArgs>;
|
|
997
1000
|
|
|
998
1001
|
/**
|
|
999
1002
|
* Flip the first two arguments of a function.
|
|
@@ -1635,7 +1638,7 @@ TOverride | (IsOptional extends true ? TInitial : never) : Extract<TOverride, ob
|
|
|
1635
1638
|
* ```
|
|
1636
1639
|
* @version 12.1.0
|
|
1637
1640
|
*/
|
|
1638
|
-
declare function clone<T>(obj: T): T;
|
|
1641
|
+
declare function clone<T extends object>(obj: T): T;
|
|
1639
1642
|
|
|
1640
1643
|
/**
|
|
1641
1644
|
* A strategy for cloning objects with `cloneDeep`.
|
|
@@ -2357,7 +2360,7 @@ declare function template(str: string, data: Record<string, any>, regex?: RegExp
|
|
|
2357
2360
|
* ```
|
|
2358
2361
|
* @version 12.1.0
|
|
2359
2362
|
*/
|
|
2360
|
-
declare function title(str: string
|
|
2363
|
+
declare function title(str: string): string;
|
|
2361
2364
|
|
|
2362
2365
|
/**
|
|
2363
2366
|
* Trims all prefix and suffix characters from the given string. Like
|
|
@@ -2374,7 +2377,7 @@ declare function title(str: string | null | undefined): string;
|
|
|
2374
2377
|
* ```
|
|
2375
2378
|
* @version 12.1.0
|
|
2376
2379
|
*/
|
|
2377
|
-
declare function trim(str: string
|
|
2380
|
+
declare function trim(str: string, charsToTrim?: string): string;
|
|
2378
2381
|
|
|
2379
2382
|
/**
|
|
2380
2383
|
* Literally just `Array.isArray` but with better type inference.
|
|
@@ -2620,7 +2623,7 @@ declare function isNullish(value: unknown): value is null | undefined;
|
|
|
2620
2623
|
* ```ts
|
|
2621
2624
|
* isNumber(0) // => true
|
|
2622
2625
|
* isNumber('0') // => false
|
|
2623
|
-
* isNumber(NaN) // =>
|
|
2626
|
+
* isNumber(NaN) // => true
|
|
2624
2627
|
* ```
|
|
2625
2628
|
* @version 12.1.0
|
|
2626
2629
|
*/
|
package/dist/radashi.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
// src/array/alphabetical.ts
|
|
2
2
|
function alphabetical(array, getter, direction = "asc") {
|
|
3
|
-
if (!array) {
|
|
4
|
-
return [];
|
|
5
|
-
}
|
|
6
3
|
const asc = (a, b) => `${getter(a)}`.localeCompare(getter(b));
|
|
7
4
|
const dsc = (a, b) => `${getter(b)}`.localeCompare(getter(a));
|
|
8
5
|
return array.slice().sort(direction === "desc" ? dsc : asc);
|
|
@@ -10,10 +7,7 @@ function alphabetical(array, getter, direction = "asc") {
|
|
|
10
7
|
|
|
11
8
|
// src/array/boil.ts
|
|
12
9
|
function boil(array, compareFunc) {
|
|
13
|
-
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
return array.reduce(compareFunc);
|
|
10
|
+
return array.length ? array.reduce(compareFunc) : null;
|
|
17
11
|
}
|
|
18
12
|
|
|
19
13
|
// src/array/cartesianProduct.ts
|
|
@@ -54,9 +48,6 @@ function cluster(array, size = 2) {
|
|
|
54
48
|
|
|
55
49
|
// src/array/counting.ts
|
|
56
50
|
function counting(array, identity) {
|
|
57
|
-
if (!array) {
|
|
58
|
-
return {};
|
|
59
|
-
}
|
|
60
51
|
return array.reduce(
|
|
61
52
|
(acc, item) => {
|
|
62
53
|
const id = identity(item);
|
|
@@ -69,15 +60,6 @@ function counting(array, identity) {
|
|
|
69
60
|
|
|
70
61
|
// src/array/diff.ts
|
|
71
62
|
function diff(root, other, identity = (t) => t) {
|
|
72
|
-
if (!(root == null ? void 0 : root.length) && !(other == null ? void 0 : other.length)) {
|
|
73
|
-
return [];
|
|
74
|
-
}
|
|
75
|
-
if ((root == null ? void 0 : root.length) === void 0) {
|
|
76
|
-
return [...other];
|
|
77
|
-
}
|
|
78
|
-
if (!(other == null ? void 0 : other.length)) {
|
|
79
|
-
return [...root];
|
|
80
|
-
}
|
|
81
63
|
const bKeys = other.reduce(
|
|
82
64
|
(acc, item) => {
|
|
83
65
|
acc[identity(item)] = true;
|
|
@@ -90,7 +72,7 @@ function diff(root, other, identity = (t) => t) {
|
|
|
90
72
|
|
|
91
73
|
// src/array/first.ts
|
|
92
74
|
function first(array, defaultValue) {
|
|
93
|
-
return
|
|
75
|
+
return array.length > 0 ? array[0] : defaultValue;
|
|
94
76
|
}
|
|
95
77
|
|
|
96
78
|
// src/array/flat.ts
|
|
@@ -104,10 +86,8 @@ function flat(lists) {
|
|
|
104
86
|
// src/array/fork.ts
|
|
105
87
|
function fork(array, condition) {
|
|
106
88
|
const forked = [[], []];
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
forked[condition(item) ? 0 : 1].push(item);
|
|
110
|
-
}
|
|
89
|
+
for (const item of array) {
|
|
90
|
+
forked[condition(item) ? 0 : 1].push(item);
|
|
111
91
|
}
|
|
112
92
|
return forked;
|
|
113
93
|
}
|
|
@@ -129,9 +109,6 @@ function group(array, getGroupId) {
|
|
|
129
109
|
|
|
130
110
|
// src/array/intersects.ts
|
|
131
111
|
function intersects(listA, listB, identity) {
|
|
132
|
-
if (!listA || !listB) {
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
112
|
if (identity) {
|
|
136
113
|
const known = new Set(listA.map(identity));
|
|
137
114
|
return listB.some((item) => known.has(identity(item)));
|
|
@@ -150,7 +127,7 @@ function iterate(count, func, initValue) {
|
|
|
150
127
|
|
|
151
128
|
// src/array/last.ts
|
|
152
129
|
function last(array, defaultValue) {
|
|
153
|
-
return
|
|
130
|
+
return array.length > 0 ? array[array.length - 1] : defaultValue;
|
|
154
131
|
}
|
|
155
132
|
|
|
156
133
|
// src/array/list.ts
|
|
@@ -169,18 +146,6 @@ function mapify(array, getKey, getValue = (item) => item) {
|
|
|
169
146
|
|
|
170
147
|
// src/array/merge.ts
|
|
171
148
|
function merge(prev, array, toKey) {
|
|
172
|
-
if (!array && !prev) {
|
|
173
|
-
return [];
|
|
174
|
-
}
|
|
175
|
-
if (!array) {
|
|
176
|
-
return [...prev];
|
|
177
|
-
}
|
|
178
|
-
if (!prev) {
|
|
179
|
-
return [];
|
|
180
|
-
}
|
|
181
|
-
if (!toKey) {
|
|
182
|
-
return [...prev];
|
|
183
|
-
}
|
|
184
149
|
const keys2 = /* @__PURE__ */ new Map();
|
|
185
150
|
for (const item of array) {
|
|
186
151
|
keys2.set(toKey(item), item);
|
|
@@ -204,9 +169,6 @@ function objectify(array, getKey, getValue = (item) => item) {
|
|
|
204
169
|
|
|
205
170
|
// src/array/replace.ts
|
|
206
171
|
function replace(array, newItem, match) {
|
|
207
|
-
if (!array) {
|
|
208
|
-
return [];
|
|
209
|
-
}
|
|
210
172
|
if (newItem === void 0) {
|
|
211
173
|
return [...array];
|
|
212
174
|
}
|
|
@@ -222,15 +184,9 @@ function replace(array, newItem, match) {
|
|
|
222
184
|
|
|
223
185
|
// src/array/replaceOrAppend.ts
|
|
224
186
|
function replaceOrAppend(array, newItem, match) {
|
|
225
|
-
if (
|
|
226
|
-
return [];
|
|
227
|
-
}
|
|
228
|
-
if (!newItem) {
|
|
187
|
+
if (newItem === void 0) {
|
|
229
188
|
return [...array];
|
|
230
189
|
}
|
|
231
|
-
if (!array) {
|
|
232
|
-
return [newItem];
|
|
233
|
-
}
|
|
234
190
|
const out = array.slice();
|
|
235
191
|
for (let index = 0; index < array.length; index++) {
|
|
236
192
|
if (match(array[index], index)) {
|
|
@@ -244,9 +200,6 @@ function replaceOrAppend(array, newItem, match) {
|
|
|
244
200
|
|
|
245
201
|
// src/array/select.ts
|
|
246
202
|
function select(array, mapper, condition) {
|
|
247
|
-
if (!array) {
|
|
248
|
-
return [];
|
|
249
|
-
}
|
|
250
203
|
let mapped;
|
|
251
204
|
return array.reduce((acc, item, index) => {
|
|
252
205
|
if (condition) {
|
|
@@ -260,9 +213,6 @@ function select(array, mapper, condition) {
|
|
|
260
213
|
|
|
261
214
|
// src/array/selectFirst.ts
|
|
262
215
|
function selectFirst(array, mapper, condition) {
|
|
263
|
-
if (!array) {
|
|
264
|
-
return void 0;
|
|
265
|
-
}
|
|
266
216
|
let foundIndex = -1;
|
|
267
217
|
const found = array.find((item, index) => {
|
|
268
218
|
foundIndex = index;
|
|
@@ -290,9 +240,6 @@ function sift(array) {
|
|
|
290
240
|
|
|
291
241
|
// src/array/sort.ts
|
|
292
242
|
function sort(array, getter, desc = false) {
|
|
293
|
-
if (!array) {
|
|
294
|
-
return [];
|
|
295
|
-
}
|
|
296
243
|
const asc = (a, b) => getter(a) - getter(b);
|
|
297
244
|
const dsc = (a, b) => getter(b) - getter(a);
|
|
298
245
|
return array.slice().sort(desc === true ? dsc : asc);
|
|
@@ -300,9 +247,6 @@ function sort(array, getter, desc = false) {
|
|
|
300
247
|
|
|
301
248
|
// src/array/toggle.ts
|
|
302
249
|
function toggle(array, item, toKey, options) {
|
|
303
|
-
if (!array) {
|
|
304
|
-
return item !== void 0 ? [item] : [];
|
|
305
|
-
}
|
|
306
250
|
if (item === void 0) {
|
|
307
251
|
return [...array];
|
|
308
252
|
}
|
|
@@ -338,9 +282,6 @@ function unique(array, toKey) {
|
|
|
338
282
|
|
|
339
283
|
// src/array/unzip.ts
|
|
340
284
|
function unzip(arrays) {
|
|
341
|
-
if (!arrays || !arrays.length) {
|
|
342
|
-
return [];
|
|
343
|
-
}
|
|
344
285
|
const out = new Array(
|
|
345
286
|
arrays.reduce((max2, arr) => Math.max(max2, arr.length), 0)
|
|
346
287
|
);
|
|
@@ -359,9 +300,6 @@ function zip(...arrays) {
|
|
|
359
300
|
|
|
360
301
|
// src/array/zipToObject.ts
|
|
361
302
|
function zipToObject(keys2, values) {
|
|
362
|
-
if (!keys2 || !keys2.length) {
|
|
363
|
-
return {};
|
|
364
|
-
}
|
|
365
303
|
const getValue = isFunction(values) ? values : isArray(values) ? (_k, i) => values[i] : (_k, _i) => values;
|
|
366
304
|
return keys2.reduce(
|
|
367
305
|
(acc, key, idx) => {
|
|
@@ -448,9 +386,6 @@ function guard(func, shouldGuard) {
|
|
|
448
386
|
|
|
449
387
|
// src/async/map.ts
|
|
450
388
|
async function map(array, asyncMapFunc) {
|
|
451
|
-
if (!array) {
|
|
452
|
-
return [];
|
|
453
|
-
}
|
|
454
389
|
const result = [];
|
|
455
390
|
let index = 0;
|
|
456
391
|
for (const value of array) {
|
|
@@ -520,9 +455,6 @@ async function parallel(options, array, func) {
|
|
|
520
455
|
|
|
521
456
|
// src/async/reduce.ts
|
|
522
457
|
async function reduce(array, reducer, initialValue) {
|
|
523
|
-
if (!array) {
|
|
524
|
-
array = [];
|
|
525
|
-
}
|
|
526
458
|
const indices = array.keys();
|
|
527
459
|
let acc = initialValue;
|
|
528
460
|
if (acc === void 0 && arguments.length < 3) {
|
|
@@ -642,31 +574,30 @@ function compose(...funcs) {
|
|
|
642
574
|
}
|
|
643
575
|
|
|
644
576
|
// src/curry/debounce.ts
|
|
645
|
-
function debounce({ delay, leading },
|
|
646
|
-
let
|
|
647
|
-
let active = true;
|
|
577
|
+
function debounce({ delay, leading }, callee) {
|
|
578
|
+
let timeout2;
|
|
648
579
|
const debounced = (...args) => {
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
timer = void 0;
|
|
654
|
-
}, delay);
|
|
655
|
-
if (leading) {
|
|
656
|
-
func(...args);
|
|
657
|
-
leading = false;
|
|
658
|
-
}
|
|
580
|
+
clearTimeout(timeout2);
|
|
581
|
+
if (leading) {
|
|
582
|
+
leading = false;
|
|
583
|
+
callee(...args);
|
|
659
584
|
} else {
|
|
660
|
-
|
|
585
|
+
timeout2 = setTimeout(
|
|
586
|
+
debounced.flush = () => {
|
|
587
|
+
debounced.flush = noop;
|
|
588
|
+
clearTimeout(timeout2);
|
|
589
|
+
callee(...args);
|
|
590
|
+
},
|
|
591
|
+
delay
|
|
592
|
+
);
|
|
661
593
|
}
|
|
662
594
|
};
|
|
663
|
-
debounced.
|
|
664
|
-
|
|
665
|
-
};
|
|
595
|
+
debounced.callee = callee;
|
|
596
|
+
debounced.flush = noop;
|
|
666
597
|
debounced.cancel = () => {
|
|
667
|
-
|
|
598
|
+
debounced.flush = noop;
|
|
599
|
+
clearTimeout(timeout2);
|
|
668
600
|
};
|
|
669
|
-
debounced.flush = (...args) => func(...args);
|
|
670
601
|
return debounced;
|
|
671
602
|
}
|
|
672
603
|
|
|
@@ -805,15 +736,7 @@ function clamp(n, min2, max2) {
|
|
|
805
736
|
}
|
|
806
737
|
|
|
807
738
|
// src/number/inRange.ts
|
|
808
|
-
function inRange(number, start, end) {
|
|
809
|
-
const isTypeSafe = typeof number === "number" && typeof start === "number" && (typeof end === "undefined" || typeof end === "number");
|
|
810
|
-
if (!isTypeSafe) {
|
|
811
|
-
return false;
|
|
812
|
-
}
|
|
813
|
-
if (typeof end === "undefined") {
|
|
814
|
-
end = start;
|
|
815
|
-
start = 0;
|
|
816
|
-
}
|
|
739
|
+
function inRange(number, start, end = 0) {
|
|
817
740
|
return number >= Math.min(start, end) && number < Math.max(start, end);
|
|
818
741
|
}
|
|
819
742
|
|
|
@@ -824,7 +747,7 @@ function lerp(from, to, amount) {
|
|
|
824
747
|
|
|
825
748
|
// src/number/max.ts
|
|
826
749
|
function max(array, getter) {
|
|
827
|
-
if (!array
|
|
750
|
+
if (!array.length) {
|
|
828
751
|
return null;
|
|
829
752
|
}
|
|
830
753
|
const get2 = getter ?? ((v) => v);
|
|
@@ -833,7 +756,7 @@ function max(array, getter) {
|
|
|
833
756
|
|
|
834
757
|
// src/number/min.ts
|
|
835
758
|
function min(array, getter) {
|
|
836
|
-
if (!array
|
|
759
|
+
if (!array.length) {
|
|
837
760
|
return null;
|
|
838
761
|
}
|
|
839
762
|
const get2 = getter ?? ((v) => v);
|
|
@@ -883,9 +806,6 @@ function toInt(value, defaultValue) {
|
|
|
883
806
|
|
|
884
807
|
// src/object/assign.ts
|
|
885
808
|
function assign(initial, override) {
|
|
886
|
-
if (!initial || !override) {
|
|
887
|
-
return initial ?? override ?? {};
|
|
888
|
-
}
|
|
889
809
|
const proto = Object.getPrototypeOf(initial);
|
|
890
810
|
const merged = proto ? { ...initial } : Object.assign(Object.create(proto), initial);
|
|
891
811
|
for (const key of Object.keys(override)) {
|
|
@@ -896,12 +816,6 @@ function assign(initial, override) {
|
|
|
896
816
|
|
|
897
817
|
// src/object/clone.ts
|
|
898
818
|
function clone(obj) {
|
|
899
|
-
if (isPrimitive(obj)) {
|
|
900
|
-
return obj;
|
|
901
|
-
}
|
|
902
|
-
if (typeof obj === "function") {
|
|
903
|
-
return obj.bind({});
|
|
904
|
-
}
|
|
905
819
|
const proto = Object.getPrototypeOf(obj);
|
|
906
820
|
const newObj = typeof (proto == null ? void 0 : proto.constructor) === "function" ? new proto.constructor() : Object.create(proto);
|
|
907
821
|
for (const key of Object.getOwnPropertyNames(obj)) {
|
|
@@ -979,9 +893,6 @@ function cloneDeep(root, customStrategy) {
|
|
|
979
893
|
|
|
980
894
|
// src/object/construct.ts
|
|
981
895
|
function construct(obj) {
|
|
982
|
-
if (!obj) {
|
|
983
|
-
return {};
|
|
984
|
-
}
|
|
985
896
|
return Object.keys(obj).reduce((acc, path) => {
|
|
986
897
|
return set(acc, path, obj[path]);
|
|
987
898
|
}, {});
|
|
@@ -989,9 +900,6 @@ function construct(obj) {
|
|
|
989
900
|
|
|
990
901
|
// src/object/crush.ts
|
|
991
902
|
function crush(value) {
|
|
992
|
-
if (!value) {
|
|
993
|
-
return {};
|
|
994
|
-
}
|
|
995
903
|
return function crushReducer(crushed, value2, path) {
|
|
996
904
|
if (isObject(value2) || isArray(value2)) {
|
|
997
905
|
for (const [prop, propValue] of Object.entries(value2)) {
|
|
@@ -1034,9 +942,6 @@ function get(value, path, defaultValue) {
|
|
|
1034
942
|
|
|
1035
943
|
// src/object/invert.ts
|
|
1036
944
|
function invert(obj) {
|
|
1037
|
-
if (!obj) {
|
|
1038
|
-
return {};
|
|
1039
|
-
}
|
|
1040
945
|
const keys2 = Object.keys(obj);
|
|
1041
946
|
return keys2.reduce(
|
|
1042
947
|
(acc, key) => {
|
|
@@ -1049,9 +954,6 @@ function invert(obj) {
|
|
|
1049
954
|
|
|
1050
955
|
// src/object/keys.ts
|
|
1051
956
|
function keys(value) {
|
|
1052
|
-
if (!value) {
|
|
1053
|
-
return [];
|
|
1054
|
-
}
|
|
1055
957
|
const keys2 = [];
|
|
1056
958
|
const keyPath = [];
|
|
1057
959
|
const recurse = (value2) => {
|
|
@@ -1077,14 +979,7 @@ function keys(value) {
|
|
|
1077
979
|
|
|
1078
980
|
// src/object/listify.ts
|
|
1079
981
|
function listify(obj, toItem) {
|
|
1080
|
-
|
|
1081
|
-
return [];
|
|
1082
|
-
}
|
|
1083
|
-
const entries = Object.entries(obj);
|
|
1084
|
-
if (entries.length === 0) {
|
|
1085
|
-
return [];
|
|
1086
|
-
}
|
|
1087
|
-
return entries.reduce((acc, entry) => {
|
|
982
|
+
return Object.entries(obj).reduce((acc, entry) => {
|
|
1088
983
|
acc.push(toItem(entry[0], entry[1]));
|
|
1089
984
|
return acc;
|
|
1090
985
|
}, []);
|
|
@@ -1097,9 +992,6 @@ function lowerize(obj) {
|
|
|
1097
992
|
|
|
1098
993
|
// src/object/mapEntries.ts
|
|
1099
994
|
function mapEntries(obj, toEntry) {
|
|
1100
|
-
if (!obj) {
|
|
1101
|
-
return {};
|
|
1102
|
-
}
|
|
1103
995
|
return Object.entries(obj).reduce(
|
|
1104
996
|
(acc, [key, value]) => {
|
|
1105
997
|
const [newKey, newValue] = toEntry(key, value);
|
|
@@ -1135,10 +1027,7 @@ function mapValues(obj, mapFunc) {
|
|
|
1135
1027
|
|
|
1136
1028
|
// src/object/omit.ts
|
|
1137
1029
|
function omit(obj, keys2) {
|
|
1138
|
-
if (
|
|
1139
|
-
return {};
|
|
1140
|
-
}
|
|
1141
|
-
if (!keys2 || keys2.length === 0) {
|
|
1030
|
+
if (keys2.length === 0) {
|
|
1142
1031
|
return obj;
|
|
1143
1032
|
}
|
|
1144
1033
|
return keys2.reduce(
|
|
@@ -1152,9 +1041,6 @@ function omit(obj, keys2) {
|
|
|
1152
1041
|
|
|
1153
1042
|
// src/object/pick.ts
|
|
1154
1043
|
function pick(obj, filter) {
|
|
1155
|
-
if (!obj) {
|
|
1156
|
-
return {};
|
|
1157
|
-
}
|
|
1158
1044
|
let keys2 = filter;
|
|
1159
1045
|
if (isArray(filter)) {
|
|
1160
1046
|
filter = null;
|
|
@@ -1171,28 +1057,20 @@ function pick(obj, filter) {
|
|
|
1171
1057
|
|
|
1172
1058
|
// src/object/set.ts
|
|
1173
1059
|
function set(initial, path, value) {
|
|
1174
|
-
if (
|
|
1175
|
-
return {};
|
|
1176
|
-
}
|
|
1177
|
-
if (!path || value === void 0) {
|
|
1060
|
+
if (value === void 0) {
|
|
1178
1061
|
return initial;
|
|
1179
1062
|
}
|
|
1180
1063
|
const root = clone(initial);
|
|
1181
1064
|
const keys2 = path.match(/[^.[\]]+/g);
|
|
1182
|
-
|
|
1183
|
-
keys2.
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
);
|
|
1187
|
-
}
|
|
1065
|
+
keys2 == null ? void 0 : keys2.reduce(
|
|
1066
|
+
(object, key, i) => i < keys2.length - 1 ? object[key] ??= isIntString(keys2[i + 1]) ? [] : {} : object[key] = value,
|
|
1067
|
+
root
|
|
1068
|
+
);
|
|
1188
1069
|
return root;
|
|
1189
1070
|
}
|
|
1190
1071
|
|
|
1191
1072
|
// src/object/shake.ts
|
|
1192
1073
|
function shake(obj, filter = (value) => value === void 0) {
|
|
1193
|
-
if (!obj) {
|
|
1194
|
-
return {};
|
|
1195
|
-
}
|
|
1196
1074
|
return Object.keys(obj).reduce((acc, key) => {
|
|
1197
1075
|
if (!filter(obj[key])) {
|
|
1198
1076
|
acc[key] = obj[key];
|
|
@@ -1399,14 +1277,7 @@ var series = (items, toKey = (item) => `${item}`) => {
|
|
|
1399
1277
|
|
|
1400
1278
|
// src/string/camel.ts
|
|
1401
1279
|
function camel(str) {
|
|
1402
|
-
|
|
1403
|
-
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())) ?? [];
|
|
1404
|
-
if (parts.length === 0) {
|
|
1405
|
-
return "";
|
|
1406
|
-
}
|
|
1407
|
-
if (parts.length === 1) {
|
|
1408
|
-
return parts[0];
|
|
1409
|
-
}
|
|
1280
|
+
const parts = str.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase());
|
|
1410
1281
|
return parts.reduce((acc, part) => {
|
|
1411
1282
|
return `${acc}${part.charAt(0).toUpperCase()}${part.slice(1)}`;
|
|
1412
1283
|
});
|
|
@@ -1414,23 +1285,13 @@ function camel(str) {
|
|
|
1414
1285
|
|
|
1415
1286
|
// src/string/capitalize.ts
|
|
1416
1287
|
function capitalize(str) {
|
|
1417
|
-
if (!str || str.length === 0) {
|
|
1418
|
-
return "";
|
|
1419
|
-
}
|
|
1420
1288
|
const lower = str.toLowerCase();
|
|
1421
1289
|
return lower.substring(0, 1).toUpperCase() + lower.substring(1, lower.length);
|
|
1422
1290
|
}
|
|
1423
1291
|
|
|
1424
1292
|
// src/string/dash.ts
|
|
1425
1293
|
function dash(str) {
|
|
1426
|
-
|
|
1427
|
-
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())) ?? [];
|
|
1428
|
-
if (parts.length === 0) {
|
|
1429
|
-
return "";
|
|
1430
|
-
}
|
|
1431
|
-
if (parts.length === 1) {
|
|
1432
|
-
return parts[0];
|
|
1433
|
-
}
|
|
1294
|
+
const parts = str.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase());
|
|
1434
1295
|
return parts.reduce((acc, part) => {
|
|
1435
1296
|
return `${acc}-${part.toLowerCase()}`;
|
|
1436
1297
|
});
|
|
@@ -1462,9 +1323,6 @@ function dedent(text, ...values) {
|
|
|
1462
1323
|
|
|
1463
1324
|
// src/string/pascal.ts
|
|
1464
1325
|
function pascal(str) {
|
|
1465
|
-
if (!str) {
|
|
1466
|
-
return "";
|
|
1467
|
-
}
|
|
1468
1326
|
const result = str.replace(
|
|
1469
1327
|
/(?:[^\w\d]|_|\s)+(\w)([A-Z]+)?/g,
|
|
1470
1328
|
(_, firstCharacter, capitalizedLetters) => {
|
|
@@ -1527,13 +1385,7 @@ function similarity(str1, str2) {
|
|
|
1527
1385
|
|
|
1528
1386
|
// src/string/snake.ts
|
|
1529
1387
|
function snake(str, options) {
|
|
1530
|
-
const parts =
|
|
1531
|
-
if (parts.length === 0) {
|
|
1532
|
-
return "";
|
|
1533
|
-
}
|
|
1534
|
-
if (parts.length === 1) {
|
|
1535
|
-
return parts[0];
|
|
1536
|
-
}
|
|
1388
|
+
const parts = str.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase());
|
|
1537
1389
|
const result = parts.reduce((acc, part) => {
|
|
1538
1390
|
return `${acc}_${part.toLowerCase()}`;
|
|
1539
1391
|
});
|
|
@@ -1554,17 +1406,11 @@ function template(str, data, regex = /\{\{(.+?)\}\}/g) {
|
|
|
1554
1406
|
|
|
1555
1407
|
// src/string/title.ts
|
|
1556
1408
|
function title(str) {
|
|
1557
|
-
if (!str) {
|
|
1558
|
-
return "";
|
|
1559
|
-
}
|
|
1560
1409
|
return str.split(/(?=[A-Z])|[\.\-\s_]/).map((s) => s.trim()).filter((s) => !!s).map((s) => capitalize(s.toLowerCase())).join(" ");
|
|
1561
1410
|
}
|
|
1562
1411
|
|
|
1563
1412
|
// src/string/trim.ts
|
|
1564
1413
|
function trim(str, charsToTrim = " ") {
|
|
1565
|
-
if (!str) {
|
|
1566
|
-
return "";
|
|
1567
|
-
}
|
|
1568
1414
|
const toTrim = charsToTrim.replace(/[\W]{1}/g, "\\$&");
|
|
1569
1415
|
const regex = new RegExp(`^[${toTrim}]+|[${toTrim}]+$`, "g");
|
|
1570
1416
|
return str.replace(regex, "");
|
|
@@ -1657,7 +1503,7 @@ function isError(value) {
|
|
|
1657
1503
|
|
|
1658
1504
|
// src/typed/isFloat.ts
|
|
1659
1505
|
function isFloat(value) {
|
|
1660
|
-
return isNumber(value) && value % 1 !== 0;
|
|
1506
|
+
return isNumber(value) && !Number.isNaN(value) && value % 1 !== 0;
|
|
1661
1507
|
}
|
|
1662
1508
|
|
|
1663
1509
|
// src/typed/isFunction.ts
|
|
@@ -1694,7 +1540,7 @@ function isNullish(value) {
|
|
|
1694
1540
|
|
|
1695
1541
|
// src/typed/isNumber.ts
|
|
1696
1542
|
function isNumber(value) {
|
|
1697
|
-
return typeof value === "number"
|
|
1543
|
+
return typeof value === "number";
|
|
1698
1544
|
}
|
|
1699
1545
|
|
|
1700
1546
|
// src/typed/isObject.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "radashi",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.0.0-beta.ffa4778",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The modern, community-first TypeScript toolkit with all of the fast, readable, and minimal utility functions you need. Type-safe, dependency-free, tree-shakeable, fully tested.",
|
|
6
6
|
"repository": {
|