radashi 12.4.0 → 13.0.0-beta.f4c6a24
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 +41 -195
- package/dist/radashi.d.cts +27 -22
- package/dist/radashi.d.ts +27 -22
- package/dist/radashi.js +41 -195
- 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
|
for (let i = 0; i < array.length; i += size) {
|
|
52
46
|
clusters.push(array.slice(i, i + size));
|
|
@@ -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);
|
|
@@ -211,9 +176,6 @@ function remove(array, predicate) {
|
|
|
211
176
|
|
|
212
177
|
// src/array/replace.ts
|
|
213
178
|
function replace(array, newItem, match) {
|
|
214
|
-
if (!array) {
|
|
215
|
-
return [];
|
|
216
|
-
}
|
|
217
179
|
if (newItem === void 0) {
|
|
218
180
|
return [...array];
|
|
219
181
|
}
|
|
@@ -229,15 +191,9 @@ function replace(array, newItem, match) {
|
|
|
229
191
|
|
|
230
192
|
// src/array/replaceOrAppend.ts
|
|
231
193
|
function replaceOrAppend(array, newItem, match) {
|
|
232
|
-
if (
|
|
233
|
-
return [];
|
|
234
|
-
}
|
|
235
|
-
if (!newItem) {
|
|
194
|
+
if (newItem === void 0) {
|
|
236
195
|
return [...array];
|
|
237
196
|
}
|
|
238
|
-
if (!array) {
|
|
239
|
-
return [newItem];
|
|
240
|
-
}
|
|
241
197
|
const out = array.slice();
|
|
242
198
|
for (let index = 0; index < array.length; index++) {
|
|
243
199
|
if (match(array[index], index)) {
|
|
@@ -251,9 +207,6 @@ function replaceOrAppend(array, newItem, match) {
|
|
|
251
207
|
|
|
252
208
|
// src/array/select.ts
|
|
253
209
|
function select(array, mapper, condition) {
|
|
254
|
-
if (!array) {
|
|
255
|
-
return [];
|
|
256
|
-
}
|
|
257
210
|
let mapped;
|
|
258
211
|
return array.reduce((acc, item, index) => {
|
|
259
212
|
if (condition) {
|
|
@@ -267,9 +220,6 @@ function select(array, mapper, condition) {
|
|
|
267
220
|
|
|
268
221
|
// src/array/selectFirst.ts
|
|
269
222
|
function selectFirst(array, mapper, condition) {
|
|
270
|
-
if (!array) {
|
|
271
|
-
return void 0;
|
|
272
|
-
}
|
|
273
223
|
let foundIndex = -1;
|
|
274
224
|
const found = array.find((item, index) => {
|
|
275
225
|
foundIndex = index;
|
|
@@ -297,9 +247,6 @@ function sift(array) {
|
|
|
297
247
|
|
|
298
248
|
// src/array/sort.ts
|
|
299
249
|
function sort(array, getter, desc = false) {
|
|
300
|
-
if (!array) {
|
|
301
|
-
return [];
|
|
302
|
-
}
|
|
303
250
|
const asc = (a, b) => getter(a) - getter(b);
|
|
304
251
|
const dsc = (a, b) => getter(b) - getter(a);
|
|
305
252
|
return array.slice().sort(desc === true ? dsc : asc);
|
|
@@ -307,9 +254,6 @@ function sort(array, getter, desc = false) {
|
|
|
307
254
|
|
|
308
255
|
// src/array/toggle.ts
|
|
309
256
|
function toggle(array, item, toKey, options) {
|
|
310
|
-
if (!array) {
|
|
311
|
-
return item !== void 0 ? [item] : [];
|
|
312
|
-
}
|
|
313
257
|
if (item === void 0) {
|
|
314
258
|
return [...array];
|
|
315
259
|
}
|
|
@@ -345,9 +289,6 @@ function unique(array, toKey) {
|
|
|
345
289
|
|
|
346
290
|
// src/array/unzip.ts
|
|
347
291
|
function unzip(arrays) {
|
|
348
|
-
if (!arrays || !arrays.length) {
|
|
349
|
-
return [];
|
|
350
|
-
}
|
|
351
292
|
const out = new Array(
|
|
352
293
|
arrays.reduce((max2, arr) => Math.max(max2, arr.length), 0)
|
|
353
294
|
);
|
|
@@ -366,9 +307,6 @@ function zip(...arrays) {
|
|
|
366
307
|
|
|
367
308
|
// src/array/zipToObject.ts
|
|
368
309
|
function zipToObject(keys2, values) {
|
|
369
|
-
if (!keys2 || !keys2.length) {
|
|
370
|
-
return {};
|
|
371
|
-
}
|
|
372
310
|
const getValue = isFunction(values) ? values : isArray(values) ? (_k, i) => values[i] : (_k, _i) => values;
|
|
373
311
|
return keys2.reduce(
|
|
374
312
|
(acc, key, idx) => {
|
|
@@ -455,9 +393,6 @@ function guard(func, shouldGuard) {
|
|
|
455
393
|
|
|
456
394
|
// src/async/map.ts
|
|
457
395
|
async function map(array, asyncMapFunc) {
|
|
458
|
-
if (!array) {
|
|
459
|
-
return [];
|
|
460
|
-
}
|
|
461
396
|
const result = [];
|
|
462
397
|
let index = 0;
|
|
463
398
|
for (const value of array) {
|
|
@@ -527,9 +462,6 @@ async function parallel(options, array, func) {
|
|
|
527
462
|
|
|
528
463
|
// src/async/reduce.ts
|
|
529
464
|
async function reduce(array, reducer, initialValue) {
|
|
530
|
-
if (!array) {
|
|
531
|
-
array = [];
|
|
532
|
-
}
|
|
533
465
|
let index = 0;
|
|
534
466
|
let acc = initialValue;
|
|
535
467
|
if (acc === void 0 && arguments.length < 3) {
|
|
@@ -661,31 +593,30 @@ function compose(...funcs) {
|
|
|
661
593
|
}
|
|
662
594
|
|
|
663
595
|
// src/curry/debounce.ts
|
|
664
|
-
function debounce({ delay, leading },
|
|
665
|
-
let
|
|
666
|
-
let active = true;
|
|
596
|
+
function debounce({ delay, leading }, callee) {
|
|
597
|
+
let timeout2;
|
|
667
598
|
const debounced = (...args) => {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
timer = void 0;
|
|
673
|
-
}, delay);
|
|
674
|
-
if (leading) {
|
|
675
|
-
func(...args);
|
|
676
|
-
leading = false;
|
|
677
|
-
}
|
|
599
|
+
clearTimeout(timeout2);
|
|
600
|
+
if (leading) {
|
|
601
|
+
leading = false;
|
|
602
|
+
callee(...args);
|
|
678
603
|
} else {
|
|
679
|
-
|
|
604
|
+
timeout2 = setTimeout(
|
|
605
|
+
debounced.flush = () => {
|
|
606
|
+
debounced.flush = noop;
|
|
607
|
+
clearTimeout(timeout2);
|
|
608
|
+
callee(...args);
|
|
609
|
+
},
|
|
610
|
+
delay
|
|
611
|
+
);
|
|
680
612
|
}
|
|
681
613
|
};
|
|
682
|
-
debounced.
|
|
683
|
-
|
|
684
|
-
};
|
|
614
|
+
debounced.callee = callee;
|
|
615
|
+
debounced.flush = noop;
|
|
685
616
|
debounced.cancel = () => {
|
|
686
|
-
|
|
617
|
+
debounced.flush = noop;
|
|
618
|
+
clearTimeout(timeout2);
|
|
687
619
|
};
|
|
688
|
-
debounced.flush = (...args) => func(...args);
|
|
689
620
|
return debounced;
|
|
690
621
|
}
|
|
691
622
|
|
|
@@ -839,15 +770,7 @@ function clamp(n, min2, max2) {
|
|
|
839
770
|
}
|
|
840
771
|
|
|
841
772
|
// src/number/inRange.ts
|
|
842
|
-
function inRange(number, start, end) {
|
|
843
|
-
const isTypeSafe = typeof number === "number" && typeof start === "number" && (typeof end === "undefined" || typeof end === "number");
|
|
844
|
-
if (!isTypeSafe) {
|
|
845
|
-
return false;
|
|
846
|
-
}
|
|
847
|
-
if (typeof end === "undefined") {
|
|
848
|
-
end = start;
|
|
849
|
-
start = 0;
|
|
850
|
-
}
|
|
773
|
+
function inRange(number, start, end = 0) {
|
|
851
774
|
return number >= Math.min(start, end) && number < Math.max(start, end);
|
|
852
775
|
}
|
|
853
776
|
|
|
@@ -858,7 +781,7 @@ function lerp(from, to, amount) {
|
|
|
858
781
|
|
|
859
782
|
// src/number/max.ts
|
|
860
783
|
function max(array, getter) {
|
|
861
|
-
if (!array
|
|
784
|
+
if (!array.length) {
|
|
862
785
|
return null;
|
|
863
786
|
}
|
|
864
787
|
const get2 = getter ?? ((v) => v);
|
|
@@ -867,7 +790,7 @@ function max(array, getter) {
|
|
|
867
790
|
|
|
868
791
|
// src/number/min.ts
|
|
869
792
|
function min(array, getter) {
|
|
870
|
-
if (!array
|
|
793
|
+
if (!array.length) {
|
|
871
794
|
return null;
|
|
872
795
|
}
|
|
873
796
|
const get2 = getter ?? ((v) => v);
|
|
@@ -917,9 +840,6 @@ function toInt(value, defaultValue) {
|
|
|
917
840
|
|
|
918
841
|
// src/object/assign.ts
|
|
919
842
|
function assign(initial, override) {
|
|
920
|
-
if (!initial || !override) {
|
|
921
|
-
return initial ?? override ?? {};
|
|
922
|
-
}
|
|
923
843
|
const proto = Object.getPrototypeOf(initial);
|
|
924
844
|
const merged = proto ? { ...initial } : Object.assign(Object.create(proto), initial);
|
|
925
845
|
for (const key of Object.keys(override)) {
|
|
@@ -930,12 +850,6 @@ function assign(initial, override) {
|
|
|
930
850
|
|
|
931
851
|
// src/object/clone.ts
|
|
932
852
|
function clone(obj) {
|
|
933
|
-
if (isPrimitive(obj)) {
|
|
934
|
-
return obj;
|
|
935
|
-
}
|
|
936
|
-
if (typeof obj === "function") {
|
|
937
|
-
return obj.bind({});
|
|
938
|
-
}
|
|
939
853
|
const proto = Object.getPrototypeOf(obj);
|
|
940
854
|
const newObj = typeof (proto == null ? void 0 : proto.constructor) === "function" ? new proto.constructor() : Object.create(proto);
|
|
941
855
|
for (const key of Object.getOwnPropertyNames(obj)) {
|
|
@@ -1013,9 +927,6 @@ function cloneDeep(root, customStrategy) {
|
|
|
1013
927
|
|
|
1014
928
|
// src/object/construct.ts
|
|
1015
929
|
function construct(obj) {
|
|
1016
|
-
if (!obj) {
|
|
1017
|
-
return {};
|
|
1018
|
-
}
|
|
1019
930
|
return Object.keys(obj).reduce((acc, path) => {
|
|
1020
931
|
return set(acc, path, obj[path]);
|
|
1021
932
|
}, {});
|
|
@@ -1023,9 +934,6 @@ function construct(obj) {
|
|
|
1023
934
|
|
|
1024
935
|
// src/object/crush.ts
|
|
1025
936
|
function crush(value) {
|
|
1026
|
-
if (!value) {
|
|
1027
|
-
return {};
|
|
1028
|
-
}
|
|
1029
937
|
return function crushReducer(crushed, value2, path) {
|
|
1030
938
|
if (isObject(value2) || isArray(value2)) {
|
|
1031
939
|
for (const [prop, propValue] of Object.entries(value2)) {
|
|
@@ -1068,9 +976,6 @@ function get(value, path, defaultValue) {
|
|
|
1068
976
|
|
|
1069
977
|
// src/object/invert.ts
|
|
1070
978
|
function invert(obj) {
|
|
1071
|
-
if (!obj) {
|
|
1072
|
-
return {};
|
|
1073
|
-
}
|
|
1074
979
|
const keys2 = Object.keys(obj);
|
|
1075
980
|
return keys2.reduce(
|
|
1076
981
|
(acc, key) => {
|
|
@@ -1083,9 +988,6 @@ function invert(obj) {
|
|
|
1083
988
|
|
|
1084
989
|
// src/object/keys.ts
|
|
1085
990
|
function keys(value) {
|
|
1086
|
-
if (!value) {
|
|
1087
|
-
return [];
|
|
1088
|
-
}
|
|
1089
991
|
const keys2 = [];
|
|
1090
992
|
const keyPath = [];
|
|
1091
993
|
const recurse = (value2) => {
|
|
@@ -1111,14 +1013,7 @@ function keys(value) {
|
|
|
1111
1013
|
|
|
1112
1014
|
// src/object/listify.ts
|
|
1113
1015
|
function listify(obj, toItem) {
|
|
1114
|
-
|
|
1115
|
-
return [];
|
|
1116
|
-
}
|
|
1117
|
-
const entries = Object.entries(obj);
|
|
1118
|
-
if (entries.length === 0) {
|
|
1119
|
-
return [];
|
|
1120
|
-
}
|
|
1121
|
-
return entries.reduce((acc, entry) => {
|
|
1016
|
+
return Object.entries(obj).reduce((acc, entry) => {
|
|
1122
1017
|
acc.push(toItem(entry[0], entry[1]));
|
|
1123
1018
|
return acc;
|
|
1124
1019
|
}, []);
|
|
@@ -1131,9 +1026,6 @@ function lowerize(obj) {
|
|
|
1131
1026
|
|
|
1132
1027
|
// src/object/mapEntries.ts
|
|
1133
1028
|
function mapEntries(obj, toEntry) {
|
|
1134
|
-
if (!obj) {
|
|
1135
|
-
return {};
|
|
1136
|
-
}
|
|
1137
1029
|
return Object.entries(obj).reduce(
|
|
1138
1030
|
(acc, [key, value]) => {
|
|
1139
1031
|
const [newKey, newValue] = toEntry(key, value);
|
|
@@ -1169,10 +1061,7 @@ function mapValues(obj, mapFunc) {
|
|
|
1169
1061
|
|
|
1170
1062
|
// src/object/omit.ts
|
|
1171
1063
|
function omit(obj, keys2) {
|
|
1172
|
-
if (
|
|
1173
|
-
return {};
|
|
1174
|
-
}
|
|
1175
|
-
if (!keys2 || keys2.length === 0) {
|
|
1064
|
+
if (keys2.length === 0) {
|
|
1176
1065
|
return obj;
|
|
1177
1066
|
}
|
|
1178
1067
|
return keys2.reduce(
|
|
@@ -1186,9 +1075,6 @@ function omit(obj, keys2) {
|
|
|
1186
1075
|
|
|
1187
1076
|
// src/object/pick.ts
|
|
1188
1077
|
function pick(obj, filter) {
|
|
1189
|
-
if (!obj) {
|
|
1190
|
-
return {};
|
|
1191
|
-
}
|
|
1192
1078
|
let keys2 = filter;
|
|
1193
1079
|
if (isArray(filter)) {
|
|
1194
1080
|
filter = null;
|
|
@@ -1205,28 +1091,20 @@ function pick(obj, filter) {
|
|
|
1205
1091
|
|
|
1206
1092
|
// src/object/set.ts
|
|
1207
1093
|
function set(initial, path, value) {
|
|
1208
|
-
if (
|
|
1209
|
-
return {};
|
|
1210
|
-
}
|
|
1211
|
-
if (!path || value === void 0) {
|
|
1094
|
+
if (value === void 0) {
|
|
1212
1095
|
return initial;
|
|
1213
1096
|
}
|
|
1214
1097
|
const root = clone(initial);
|
|
1215
1098
|
const keys2 = path.match(/[^.[\]]+/g);
|
|
1216
|
-
|
|
1217
|
-
keys2.
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
);
|
|
1221
|
-
}
|
|
1099
|
+
keys2 == null ? void 0 : keys2.reduce(
|
|
1100
|
+
(object, key, i) => i < keys2.length - 1 ? object[key] ??= isIntString(keys2[i + 1]) ? [] : {} : object[key] = value,
|
|
1101
|
+
root
|
|
1102
|
+
);
|
|
1222
1103
|
return root;
|
|
1223
1104
|
}
|
|
1224
1105
|
|
|
1225
1106
|
// src/object/shake.ts
|
|
1226
1107
|
function shake(obj, filter = (value) => value === void 0) {
|
|
1227
|
-
if (!obj) {
|
|
1228
|
-
return {};
|
|
1229
|
-
}
|
|
1230
1108
|
return Object.keys(obj).reduce((acc, key) => {
|
|
1231
1109
|
if (!filter(obj[key])) {
|
|
1232
1110
|
acc[key] = obj[key];
|
|
@@ -1433,14 +1311,7 @@ var series = (items, toKey = (item) => `${item}`) => {
|
|
|
1433
1311
|
|
|
1434
1312
|
// src/string/camel.ts
|
|
1435
1313
|
function camel(str) {
|
|
1436
|
-
|
|
1437
|
-
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())) ?? [];
|
|
1438
|
-
if (parts.length === 0) {
|
|
1439
|
-
return "";
|
|
1440
|
-
}
|
|
1441
|
-
if (parts.length === 1) {
|
|
1442
|
-
return parts[0];
|
|
1443
|
-
}
|
|
1314
|
+
const parts = str.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase());
|
|
1444
1315
|
return parts.reduce((acc, part) => {
|
|
1445
1316
|
return `${acc}${part.charAt(0).toUpperCase()}${part.slice(1)}`;
|
|
1446
1317
|
});
|
|
@@ -1448,23 +1319,13 @@ function camel(str) {
|
|
|
1448
1319
|
|
|
1449
1320
|
// src/string/capitalize.ts
|
|
1450
1321
|
function capitalize(str) {
|
|
1451
|
-
if (!str || str.length === 0) {
|
|
1452
|
-
return "";
|
|
1453
|
-
}
|
|
1454
1322
|
const lower = str.toLowerCase();
|
|
1455
1323
|
return lower.substring(0, 1).toUpperCase() + lower.substring(1, lower.length);
|
|
1456
1324
|
}
|
|
1457
1325
|
|
|
1458
1326
|
// src/string/dash.ts
|
|
1459
1327
|
function dash(str) {
|
|
1460
|
-
|
|
1461
|
-
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())) ?? [];
|
|
1462
|
-
if (parts.length === 0) {
|
|
1463
|
-
return "";
|
|
1464
|
-
}
|
|
1465
|
-
if (parts.length === 1) {
|
|
1466
|
-
return parts[0];
|
|
1467
|
-
}
|
|
1328
|
+
const parts = str.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase());
|
|
1468
1329
|
return parts.reduce((acc, part) => {
|
|
1469
1330
|
return `${acc}-${part.toLowerCase()}`;
|
|
1470
1331
|
});
|
|
@@ -1496,9 +1357,6 @@ function dedent(text, ...values) {
|
|
|
1496
1357
|
|
|
1497
1358
|
// src/string/pascal.ts
|
|
1498
1359
|
function pascal(str) {
|
|
1499
|
-
if (!str) {
|
|
1500
|
-
return "";
|
|
1501
|
-
}
|
|
1502
1360
|
const result = str.replace(
|
|
1503
1361
|
/(?:[^\w\d]|_|\s)+(\w)([A-Z]+)?/g,
|
|
1504
1362
|
(_, firstCharacter, capitalizedLetters) => {
|
|
@@ -1561,13 +1419,7 @@ function similarity(str1, str2) {
|
|
|
1561
1419
|
|
|
1562
1420
|
// src/string/snake.ts
|
|
1563
1421
|
function snake(str, options) {
|
|
1564
|
-
const parts =
|
|
1565
|
-
if (parts.length === 0) {
|
|
1566
|
-
return "";
|
|
1567
|
-
}
|
|
1568
|
-
if (parts.length === 1) {
|
|
1569
|
-
return parts[0];
|
|
1570
|
-
}
|
|
1422
|
+
const parts = str.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase());
|
|
1571
1423
|
const result = parts.reduce((acc, part) => {
|
|
1572
1424
|
return `${acc}_${part.toLowerCase()}`;
|
|
1573
1425
|
});
|
|
@@ -1588,17 +1440,11 @@ function template(str, data, regex = /\{\{(.+?)\}\}/g) {
|
|
|
1588
1440
|
|
|
1589
1441
|
// src/string/title.ts
|
|
1590
1442
|
function title(str) {
|
|
1591
|
-
if (!str) {
|
|
1592
|
-
return "";
|
|
1593
|
-
}
|
|
1594
1443
|
return str.split(/(?=[A-Z])|[\.\-\s_]/).map((s) => s.trim()).filter((s) => !!s).map((s) => capitalize(s.toLowerCase())).join(" ");
|
|
1595
1444
|
}
|
|
1596
1445
|
|
|
1597
1446
|
// src/string/trim.ts
|
|
1598
|
-
function trim(str, charsToTrim
|
|
1599
|
-
if (!str) {
|
|
1600
|
-
return "";
|
|
1601
|
-
}
|
|
1447
|
+
function trim(str, charsToTrim) {
|
|
1602
1448
|
const toTrim = charsToTrim.replace(/[\W]{1}/g, "\\$&");
|
|
1603
1449
|
const regex = new RegExp(`^[${toTrim}]+|[${toTrim}]+$`, "g");
|
|
1604
1450
|
return str.replace(regex, "");
|
|
@@ -1693,7 +1539,7 @@ function isError(value) {
|
|
|
1693
1539
|
|
|
1694
1540
|
// src/typed/isFloat.ts
|
|
1695
1541
|
function isFloat(value) {
|
|
1696
|
-
return isNumber(value) && value % 1 !== 0;
|
|
1542
|
+
return isNumber(value) && !Number.isNaN(value) && value % 1 !== 0;
|
|
1697
1543
|
}
|
|
1698
1544
|
|
|
1699
1545
|
// src/typed/isFunction.ts
|
|
@@ -1730,7 +1576,7 @@ function isNullish(value) {
|
|
|
1730
1576
|
|
|
1731
1577
|
// src/typed/isNumber.ts
|
|
1732
1578
|
function isNumber(value) {
|
|
1733
|
-
return typeof value === "number"
|
|
1579
|
+
return typeof value === "number";
|
|
1734
1580
|
}
|
|
1735
1581
|
|
|
1736
1582
|
// src/typed/isObject.ts
|
package/dist/radashi.d.cts
CHANGED
|
@@ -108,11 +108,14 @@ type CastArrayIfExists<T> = [T] extends [never] ? never[] : [unknown] extends [T
|
|
|
108
108
|
* ```
|
|
109
109
|
* @version 12.1.0
|
|
110
110
|
*/
|
|
111
|
-
declare function cluster<T>(array: readonly T[], size
|
|
111
|
+
declare function cluster<T>(array: readonly T[], size: number): T[][];
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
|
-
* Counts the occurrences of each unique value returned by the
|
|
115
|
-
* function when applied to each item in the array.
|
|
114
|
+
* Counts the occurrences of each unique value returned by the
|
|
115
|
+
* `identity` function when applied to each item in the array.
|
|
116
|
+
*
|
|
117
|
+
* If no occurrences are found, the key will not be present in the
|
|
118
|
+
* returned object.
|
|
116
119
|
*
|
|
117
120
|
* @see https://radashi.js.org/reference/array/counting
|
|
118
121
|
* @example
|
|
@@ -122,7 +125,7 @@ declare function cluster<T>(array: readonly T[], size?: number): T[][];
|
|
|
122
125
|
* ```
|
|
123
126
|
* @version 12.1.0
|
|
124
127
|
*/
|
|
125
|
-
declare function counting<T, TId extends string | number | symbol>(array: readonly T[], identity: (item: T) => TId): Record<TId, number
|
|
128
|
+
declare function counting<T, TId extends string | number | symbol>(array: readonly T[], identity: (item: T) => TId): Partial<Record<TId, number>>;
|
|
126
129
|
|
|
127
130
|
/**
|
|
128
131
|
* Returns all items from the first list that do not exist in the
|
|
@@ -357,6 +360,7 @@ declare function objectify<T, Key extends string | number | symbol, Value = T>(a
|
|
|
357
360
|
*/
|
|
358
361
|
declare function remove<T>(array: readonly T[], predicate: (value: T) => boolean): T[];
|
|
359
362
|
|
|
363
|
+
type Defined$1<T> = T & ({} | null);
|
|
360
364
|
/**
|
|
361
365
|
* Replace an element in an array with a new item without modifying
|
|
362
366
|
* the array and return the new value.
|
|
@@ -369,8 +373,9 @@ declare function remove<T>(array: readonly T[], predicate: (value: T) => boolean
|
|
|
369
373
|
* ```
|
|
370
374
|
* @version 12.1.0
|
|
371
375
|
*/
|
|
372
|
-
declare function replace<T>(array: readonly T[], newItem:
|
|
376
|
+
declare function replace<T, U>(array: readonly T[], newItem: U, match: (item: T, idx: number) => boolean): (T | Defined$1<U>)[];
|
|
373
377
|
|
|
378
|
+
type Defined<T> = T & ({} | null);
|
|
374
379
|
/**
|
|
375
380
|
* Replace the first occurrence of an item in an array where the
|
|
376
381
|
* `match` function returns true. If no items match, append the new
|
|
@@ -387,7 +392,7 @@ declare function replace<T>(array: readonly T[], newItem: T, match: (item: T, id
|
|
|
387
392
|
* ```
|
|
388
393
|
* @version 12.1.0
|
|
389
394
|
*/
|
|
390
|
-
declare function replaceOrAppend<T>(array: readonly T[], newItem:
|
|
395
|
+
declare function replaceOrAppend<T, U>(array: readonly T[], newItem: U, match: (a: T, idx: number) => boolean): (T | Defined<U>)[];
|
|
391
396
|
|
|
392
397
|
/**
|
|
393
398
|
* Select performs a filter and a mapper inside of a reduce, only
|
|
@@ -1717,7 +1722,7 @@ declare function compose<F1Result, F1Args extends any[], F1NextArgs extends any[
|
|
|
1717
1722
|
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;
|
|
1718
1723
|
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;
|
|
1719
1724
|
|
|
1720
|
-
|
|
1725
|
+
interface DebounceFunction<TArgs extends any[] = any> {
|
|
1721
1726
|
(...args: TArgs): void;
|
|
1722
1727
|
/**
|
|
1723
1728
|
* When called, future invocations of the debounced function are
|
|
@@ -1725,15 +1730,15 @@ type DebounceFunction<TArgs extends any[]> = {
|
|
|
1725
1730
|
*/
|
|
1726
1731
|
cancel(): void;
|
|
1727
1732
|
/**
|
|
1728
|
-
*
|
|
1729
|
-
*
|
|
1733
|
+
* If a debounced call is scheduled, this invokes it immediately.
|
|
1734
|
+
* Otherwise, this equals Radashi's `noop` function.
|
|
1730
1735
|
*/
|
|
1731
|
-
|
|
1736
|
+
flush(): void;
|
|
1732
1737
|
/**
|
|
1733
|
-
*
|
|
1738
|
+
* The underlying function
|
|
1734
1739
|
*/
|
|
1735
|
-
|
|
1736
|
-
}
|
|
1740
|
+
readonly callee: (...args: TArgs) => unknown;
|
|
1741
|
+
}
|
|
1737
1742
|
interface DebounceOptions {
|
|
1738
1743
|
delay: number;
|
|
1739
1744
|
/**
|
|
@@ -1746,11 +1751,11 @@ interface DebounceOptions {
|
|
|
1746
1751
|
leading?: boolean;
|
|
1747
1752
|
}
|
|
1748
1753
|
/**
|
|
1749
|
-
* Returns a new function that will only call
|
|
1750
|
-
* `delay` milliseconds have passed without any invocations.
|
|
1754
|
+
* Returns a new function that will only call the source function
|
|
1755
|
+
* after `delay` milliseconds have passed without any invocations.
|
|
1751
1756
|
*
|
|
1752
|
-
*
|
|
1753
|
-
*
|
|
1757
|
+
* See the documentation (or the `DebounceFunction` type) for details
|
|
1758
|
+
* on the methods and properties available on the returned function.
|
|
1754
1759
|
*
|
|
1755
1760
|
* @see https://radashi.js.org/reference/curry/debounce
|
|
1756
1761
|
* @example
|
|
@@ -1765,7 +1770,7 @@ interface DebounceOptions {
|
|
|
1765
1770
|
* ```
|
|
1766
1771
|
* @version 12.1.0
|
|
1767
1772
|
*/
|
|
1768
|
-
declare function debounce<TArgs extends any[]>({ delay, leading }: DebounceOptions,
|
|
1773
|
+
declare function debounce<TArgs extends any[]>({ delay, leading }: DebounceOptions, callee: (...args: TArgs) => unknown): DebounceFunction<TArgs>;
|
|
1769
1774
|
|
|
1770
1775
|
/**
|
|
1771
1776
|
* Flip the first two arguments of a function.
|
|
@@ -2436,7 +2441,7 @@ TOverride | (IsOptional extends true ? TInitial : never) : Extract<TOverride, ob
|
|
|
2436
2441
|
* ```
|
|
2437
2442
|
* @version 12.1.0
|
|
2438
2443
|
*/
|
|
2439
|
-
declare function clone<T>(obj: T): T;
|
|
2444
|
+
declare function clone<T extends object>(obj: T): T;
|
|
2440
2445
|
|
|
2441
2446
|
/**
|
|
2442
2447
|
* A strategy for cloning objects with `cloneDeep`.
|
|
@@ -3158,7 +3163,7 @@ declare function template(str: string, data: Record<string, any>, regex?: RegExp
|
|
|
3158
3163
|
* ```
|
|
3159
3164
|
* @version 12.1.0
|
|
3160
3165
|
*/
|
|
3161
|
-
declare function title(str: string
|
|
3166
|
+
declare function title(str: string): string;
|
|
3162
3167
|
|
|
3163
3168
|
/**
|
|
3164
3169
|
* Trims all prefix and suffix characters from the given string. Like
|
|
@@ -3175,7 +3180,7 @@ declare function title(str: string | null | undefined): string;
|
|
|
3175
3180
|
* ```
|
|
3176
3181
|
* @version 12.1.0
|
|
3177
3182
|
*/
|
|
3178
|
-
declare function trim(str: string
|
|
3183
|
+
declare function trim(str: string, charsToTrim: string): string;
|
|
3179
3184
|
|
|
3180
3185
|
/**
|
|
3181
3186
|
* Literally just `Array.isArray` but with better type inference.
|
|
@@ -3455,7 +3460,7 @@ declare function isNullish(value: unknown): value is null | undefined;
|
|
|
3455
3460
|
* ```ts
|
|
3456
3461
|
* isNumber(0) // => true
|
|
3457
3462
|
* isNumber('0') // => false
|
|
3458
|
-
* isNumber(NaN) // =>
|
|
3463
|
+
* isNumber(NaN) // => true
|
|
3459
3464
|
* ```
|
|
3460
3465
|
* @version 12.1.0
|
|
3461
3466
|
*/
|
package/dist/radashi.d.ts
CHANGED
|
@@ -108,11 +108,14 @@ type CastArrayIfExists<T> = [T] extends [never] ? never[] : [unknown] extends [T
|
|
|
108
108
|
* ```
|
|
109
109
|
* @version 12.1.0
|
|
110
110
|
*/
|
|
111
|
-
declare function cluster<T>(array: readonly T[], size
|
|
111
|
+
declare function cluster<T>(array: readonly T[], size: number): T[][];
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
|
-
* Counts the occurrences of each unique value returned by the
|
|
115
|
-
* function when applied to each item in the array.
|
|
114
|
+
* Counts the occurrences of each unique value returned by the
|
|
115
|
+
* `identity` function when applied to each item in the array.
|
|
116
|
+
*
|
|
117
|
+
* If no occurrences are found, the key will not be present in the
|
|
118
|
+
* returned object.
|
|
116
119
|
*
|
|
117
120
|
* @see https://radashi.js.org/reference/array/counting
|
|
118
121
|
* @example
|
|
@@ -122,7 +125,7 @@ declare function cluster<T>(array: readonly T[], size?: number): T[][];
|
|
|
122
125
|
* ```
|
|
123
126
|
* @version 12.1.0
|
|
124
127
|
*/
|
|
125
|
-
declare function counting<T, TId extends string | number | symbol>(array: readonly T[], identity: (item: T) => TId): Record<TId, number
|
|
128
|
+
declare function counting<T, TId extends string | number | symbol>(array: readonly T[], identity: (item: T) => TId): Partial<Record<TId, number>>;
|
|
126
129
|
|
|
127
130
|
/**
|
|
128
131
|
* Returns all items from the first list that do not exist in the
|
|
@@ -357,6 +360,7 @@ declare function objectify<T, Key extends string | number | symbol, Value = T>(a
|
|
|
357
360
|
*/
|
|
358
361
|
declare function remove<T>(array: readonly T[], predicate: (value: T) => boolean): T[];
|
|
359
362
|
|
|
363
|
+
type Defined$1<T> = T & ({} | null);
|
|
360
364
|
/**
|
|
361
365
|
* Replace an element in an array with a new item without modifying
|
|
362
366
|
* the array and return the new value.
|
|
@@ -369,8 +373,9 @@ declare function remove<T>(array: readonly T[], predicate: (value: T) => boolean
|
|
|
369
373
|
* ```
|
|
370
374
|
* @version 12.1.0
|
|
371
375
|
*/
|
|
372
|
-
declare function replace<T>(array: readonly T[], newItem:
|
|
376
|
+
declare function replace<T, U>(array: readonly T[], newItem: U, match: (item: T, idx: number) => boolean): (T | Defined$1<U>)[];
|
|
373
377
|
|
|
378
|
+
type Defined<T> = T & ({} | null);
|
|
374
379
|
/**
|
|
375
380
|
* Replace the first occurrence of an item in an array where the
|
|
376
381
|
* `match` function returns true. If no items match, append the new
|
|
@@ -387,7 +392,7 @@ declare function replace<T>(array: readonly T[], newItem: T, match: (item: T, id
|
|
|
387
392
|
* ```
|
|
388
393
|
* @version 12.1.0
|
|
389
394
|
*/
|
|
390
|
-
declare function replaceOrAppend<T>(array: readonly T[], newItem:
|
|
395
|
+
declare function replaceOrAppend<T, U>(array: readonly T[], newItem: U, match: (a: T, idx: number) => boolean): (T | Defined<U>)[];
|
|
391
396
|
|
|
392
397
|
/**
|
|
393
398
|
* Select performs a filter and a mapper inside of a reduce, only
|
|
@@ -1717,7 +1722,7 @@ declare function compose<F1Result, F1Args extends any[], F1NextArgs extends any[
|
|
|
1717
1722
|
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;
|
|
1718
1723
|
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;
|
|
1719
1724
|
|
|
1720
|
-
|
|
1725
|
+
interface DebounceFunction<TArgs extends any[] = any> {
|
|
1721
1726
|
(...args: TArgs): void;
|
|
1722
1727
|
/**
|
|
1723
1728
|
* When called, future invocations of the debounced function are
|
|
@@ -1725,15 +1730,15 @@ type DebounceFunction<TArgs extends any[]> = {
|
|
|
1725
1730
|
*/
|
|
1726
1731
|
cancel(): void;
|
|
1727
1732
|
/**
|
|
1728
|
-
*
|
|
1729
|
-
*
|
|
1733
|
+
* If a debounced call is scheduled, this invokes it immediately.
|
|
1734
|
+
* Otherwise, this equals Radashi's `noop` function.
|
|
1730
1735
|
*/
|
|
1731
|
-
|
|
1736
|
+
flush(): void;
|
|
1732
1737
|
/**
|
|
1733
|
-
*
|
|
1738
|
+
* The underlying function
|
|
1734
1739
|
*/
|
|
1735
|
-
|
|
1736
|
-
}
|
|
1740
|
+
readonly callee: (...args: TArgs) => unknown;
|
|
1741
|
+
}
|
|
1737
1742
|
interface DebounceOptions {
|
|
1738
1743
|
delay: number;
|
|
1739
1744
|
/**
|
|
@@ -1746,11 +1751,11 @@ interface DebounceOptions {
|
|
|
1746
1751
|
leading?: boolean;
|
|
1747
1752
|
}
|
|
1748
1753
|
/**
|
|
1749
|
-
* Returns a new function that will only call
|
|
1750
|
-
* `delay` milliseconds have passed without any invocations.
|
|
1754
|
+
* Returns a new function that will only call the source function
|
|
1755
|
+
* after `delay` milliseconds have passed without any invocations.
|
|
1751
1756
|
*
|
|
1752
|
-
*
|
|
1753
|
-
*
|
|
1757
|
+
* See the documentation (or the `DebounceFunction` type) for details
|
|
1758
|
+
* on the methods and properties available on the returned function.
|
|
1754
1759
|
*
|
|
1755
1760
|
* @see https://radashi.js.org/reference/curry/debounce
|
|
1756
1761
|
* @example
|
|
@@ -1765,7 +1770,7 @@ interface DebounceOptions {
|
|
|
1765
1770
|
* ```
|
|
1766
1771
|
* @version 12.1.0
|
|
1767
1772
|
*/
|
|
1768
|
-
declare function debounce<TArgs extends any[]>({ delay, leading }: DebounceOptions,
|
|
1773
|
+
declare function debounce<TArgs extends any[]>({ delay, leading }: DebounceOptions, callee: (...args: TArgs) => unknown): DebounceFunction<TArgs>;
|
|
1769
1774
|
|
|
1770
1775
|
/**
|
|
1771
1776
|
* Flip the first two arguments of a function.
|
|
@@ -2436,7 +2441,7 @@ TOverride | (IsOptional extends true ? TInitial : never) : Extract<TOverride, ob
|
|
|
2436
2441
|
* ```
|
|
2437
2442
|
* @version 12.1.0
|
|
2438
2443
|
*/
|
|
2439
|
-
declare function clone<T>(obj: T): T;
|
|
2444
|
+
declare function clone<T extends object>(obj: T): T;
|
|
2440
2445
|
|
|
2441
2446
|
/**
|
|
2442
2447
|
* A strategy for cloning objects with `cloneDeep`.
|
|
@@ -3158,7 +3163,7 @@ declare function template(str: string, data: Record<string, any>, regex?: RegExp
|
|
|
3158
3163
|
* ```
|
|
3159
3164
|
* @version 12.1.0
|
|
3160
3165
|
*/
|
|
3161
|
-
declare function title(str: string
|
|
3166
|
+
declare function title(str: string): string;
|
|
3162
3167
|
|
|
3163
3168
|
/**
|
|
3164
3169
|
* Trims all prefix and suffix characters from the given string. Like
|
|
@@ -3175,7 +3180,7 @@ declare function title(str: string | null | undefined): string;
|
|
|
3175
3180
|
* ```
|
|
3176
3181
|
* @version 12.1.0
|
|
3177
3182
|
*/
|
|
3178
|
-
declare function trim(str: string
|
|
3183
|
+
declare function trim(str: string, charsToTrim: string): string;
|
|
3179
3184
|
|
|
3180
3185
|
/**
|
|
3181
3186
|
* Literally just `Array.isArray` but with better type inference.
|
|
@@ -3455,7 +3460,7 @@ declare function isNullish(value: unknown): value is null | undefined;
|
|
|
3455
3460
|
* ```ts
|
|
3456
3461
|
* isNumber(0) // => true
|
|
3457
3462
|
* isNumber('0') // => false
|
|
3458
|
-
* isNumber(NaN) // =>
|
|
3463
|
+
* isNumber(NaN) // => true
|
|
3459
3464
|
* ```
|
|
3460
3465
|
* @version 12.1.0
|
|
3461
3466
|
*/
|
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
|
|
@@ -44,7 +38,7 @@ function castArrayIfExists(value) {
|
|
|
44
38
|
}
|
|
45
39
|
|
|
46
40
|
// src/array/cluster.ts
|
|
47
|
-
function cluster(array, size
|
|
41
|
+
function cluster(array, size) {
|
|
48
42
|
const clusters = [];
|
|
49
43
|
for (let i = 0; i < array.length; i += size) {
|
|
50
44
|
clusters.push(array.slice(i, i + size));
|
|
@@ -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);
|
|
@@ -209,9 +174,6 @@ function remove(array, predicate) {
|
|
|
209
174
|
|
|
210
175
|
// src/array/replace.ts
|
|
211
176
|
function replace(array, newItem, match) {
|
|
212
|
-
if (!array) {
|
|
213
|
-
return [];
|
|
214
|
-
}
|
|
215
177
|
if (newItem === void 0) {
|
|
216
178
|
return [...array];
|
|
217
179
|
}
|
|
@@ -227,15 +189,9 @@ function replace(array, newItem, match) {
|
|
|
227
189
|
|
|
228
190
|
// src/array/replaceOrAppend.ts
|
|
229
191
|
function replaceOrAppend(array, newItem, match) {
|
|
230
|
-
if (
|
|
231
|
-
return [];
|
|
232
|
-
}
|
|
233
|
-
if (!newItem) {
|
|
192
|
+
if (newItem === void 0) {
|
|
234
193
|
return [...array];
|
|
235
194
|
}
|
|
236
|
-
if (!array) {
|
|
237
|
-
return [newItem];
|
|
238
|
-
}
|
|
239
195
|
const out = array.slice();
|
|
240
196
|
for (let index = 0; index < array.length; index++) {
|
|
241
197
|
if (match(array[index], index)) {
|
|
@@ -249,9 +205,6 @@ function replaceOrAppend(array, newItem, match) {
|
|
|
249
205
|
|
|
250
206
|
// src/array/select.ts
|
|
251
207
|
function select(array, mapper, condition) {
|
|
252
|
-
if (!array) {
|
|
253
|
-
return [];
|
|
254
|
-
}
|
|
255
208
|
let mapped;
|
|
256
209
|
return array.reduce((acc, item, index) => {
|
|
257
210
|
if (condition) {
|
|
@@ -265,9 +218,6 @@ function select(array, mapper, condition) {
|
|
|
265
218
|
|
|
266
219
|
// src/array/selectFirst.ts
|
|
267
220
|
function selectFirst(array, mapper, condition) {
|
|
268
|
-
if (!array) {
|
|
269
|
-
return void 0;
|
|
270
|
-
}
|
|
271
221
|
let foundIndex = -1;
|
|
272
222
|
const found = array.find((item, index) => {
|
|
273
223
|
foundIndex = index;
|
|
@@ -295,9 +245,6 @@ function sift(array) {
|
|
|
295
245
|
|
|
296
246
|
// src/array/sort.ts
|
|
297
247
|
function sort(array, getter, desc = false) {
|
|
298
|
-
if (!array) {
|
|
299
|
-
return [];
|
|
300
|
-
}
|
|
301
248
|
const asc = (a, b) => getter(a) - getter(b);
|
|
302
249
|
const dsc = (a, b) => getter(b) - getter(a);
|
|
303
250
|
return array.slice().sort(desc === true ? dsc : asc);
|
|
@@ -305,9 +252,6 @@ function sort(array, getter, desc = false) {
|
|
|
305
252
|
|
|
306
253
|
// src/array/toggle.ts
|
|
307
254
|
function toggle(array, item, toKey, options) {
|
|
308
|
-
if (!array) {
|
|
309
|
-
return item !== void 0 ? [item] : [];
|
|
310
|
-
}
|
|
311
255
|
if (item === void 0) {
|
|
312
256
|
return [...array];
|
|
313
257
|
}
|
|
@@ -343,9 +287,6 @@ function unique(array, toKey) {
|
|
|
343
287
|
|
|
344
288
|
// src/array/unzip.ts
|
|
345
289
|
function unzip(arrays) {
|
|
346
|
-
if (!arrays || !arrays.length) {
|
|
347
|
-
return [];
|
|
348
|
-
}
|
|
349
290
|
const out = new Array(
|
|
350
291
|
arrays.reduce((max2, arr) => Math.max(max2, arr.length), 0)
|
|
351
292
|
);
|
|
@@ -364,9 +305,6 @@ function zip(...arrays) {
|
|
|
364
305
|
|
|
365
306
|
// src/array/zipToObject.ts
|
|
366
307
|
function zipToObject(keys2, values) {
|
|
367
|
-
if (!keys2 || !keys2.length) {
|
|
368
|
-
return {};
|
|
369
|
-
}
|
|
370
308
|
const getValue = isFunction(values) ? values : isArray(values) ? (_k, i) => values[i] : (_k, _i) => values;
|
|
371
309
|
return keys2.reduce(
|
|
372
310
|
(acc, key, idx) => {
|
|
@@ -453,9 +391,6 @@ function guard(func, shouldGuard) {
|
|
|
453
391
|
|
|
454
392
|
// src/async/map.ts
|
|
455
393
|
async function map(array, asyncMapFunc) {
|
|
456
|
-
if (!array) {
|
|
457
|
-
return [];
|
|
458
|
-
}
|
|
459
394
|
const result = [];
|
|
460
395
|
let index = 0;
|
|
461
396
|
for (const value of array) {
|
|
@@ -525,9 +460,6 @@ async function parallel(options, array, func) {
|
|
|
525
460
|
|
|
526
461
|
// src/async/reduce.ts
|
|
527
462
|
async function reduce(array, reducer, initialValue) {
|
|
528
|
-
if (!array) {
|
|
529
|
-
array = [];
|
|
530
|
-
}
|
|
531
463
|
let index = 0;
|
|
532
464
|
let acc = initialValue;
|
|
533
465
|
if (acc === void 0 && arguments.length < 3) {
|
|
@@ -659,31 +591,30 @@ function compose(...funcs) {
|
|
|
659
591
|
}
|
|
660
592
|
|
|
661
593
|
// src/curry/debounce.ts
|
|
662
|
-
function debounce({ delay, leading },
|
|
663
|
-
let
|
|
664
|
-
let active = true;
|
|
594
|
+
function debounce({ delay, leading }, callee) {
|
|
595
|
+
let timeout2;
|
|
665
596
|
const debounced = (...args) => {
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
timer = void 0;
|
|
671
|
-
}, delay);
|
|
672
|
-
if (leading) {
|
|
673
|
-
func(...args);
|
|
674
|
-
leading = false;
|
|
675
|
-
}
|
|
597
|
+
clearTimeout(timeout2);
|
|
598
|
+
if (leading) {
|
|
599
|
+
leading = false;
|
|
600
|
+
callee(...args);
|
|
676
601
|
} else {
|
|
677
|
-
|
|
602
|
+
timeout2 = setTimeout(
|
|
603
|
+
debounced.flush = () => {
|
|
604
|
+
debounced.flush = noop;
|
|
605
|
+
clearTimeout(timeout2);
|
|
606
|
+
callee(...args);
|
|
607
|
+
},
|
|
608
|
+
delay
|
|
609
|
+
);
|
|
678
610
|
}
|
|
679
611
|
};
|
|
680
|
-
debounced.
|
|
681
|
-
|
|
682
|
-
};
|
|
612
|
+
debounced.callee = callee;
|
|
613
|
+
debounced.flush = noop;
|
|
683
614
|
debounced.cancel = () => {
|
|
684
|
-
|
|
615
|
+
debounced.flush = noop;
|
|
616
|
+
clearTimeout(timeout2);
|
|
685
617
|
};
|
|
686
|
-
debounced.flush = (...args) => func(...args);
|
|
687
618
|
return debounced;
|
|
688
619
|
}
|
|
689
620
|
|
|
@@ -837,15 +768,7 @@ function clamp(n, min2, max2) {
|
|
|
837
768
|
}
|
|
838
769
|
|
|
839
770
|
// src/number/inRange.ts
|
|
840
|
-
function inRange(number, start, end) {
|
|
841
|
-
const isTypeSafe = typeof number === "number" && typeof start === "number" && (typeof end === "undefined" || typeof end === "number");
|
|
842
|
-
if (!isTypeSafe) {
|
|
843
|
-
return false;
|
|
844
|
-
}
|
|
845
|
-
if (typeof end === "undefined") {
|
|
846
|
-
end = start;
|
|
847
|
-
start = 0;
|
|
848
|
-
}
|
|
771
|
+
function inRange(number, start, end = 0) {
|
|
849
772
|
return number >= Math.min(start, end) && number < Math.max(start, end);
|
|
850
773
|
}
|
|
851
774
|
|
|
@@ -856,7 +779,7 @@ function lerp(from, to, amount) {
|
|
|
856
779
|
|
|
857
780
|
// src/number/max.ts
|
|
858
781
|
function max(array, getter) {
|
|
859
|
-
if (!array
|
|
782
|
+
if (!array.length) {
|
|
860
783
|
return null;
|
|
861
784
|
}
|
|
862
785
|
const get2 = getter ?? ((v) => v);
|
|
@@ -865,7 +788,7 @@ function max(array, getter) {
|
|
|
865
788
|
|
|
866
789
|
// src/number/min.ts
|
|
867
790
|
function min(array, getter) {
|
|
868
|
-
if (!array
|
|
791
|
+
if (!array.length) {
|
|
869
792
|
return null;
|
|
870
793
|
}
|
|
871
794
|
const get2 = getter ?? ((v) => v);
|
|
@@ -915,9 +838,6 @@ function toInt(value, defaultValue) {
|
|
|
915
838
|
|
|
916
839
|
// src/object/assign.ts
|
|
917
840
|
function assign(initial, override) {
|
|
918
|
-
if (!initial || !override) {
|
|
919
|
-
return initial ?? override ?? {};
|
|
920
|
-
}
|
|
921
841
|
const proto = Object.getPrototypeOf(initial);
|
|
922
842
|
const merged = proto ? { ...initial } : Object.assign(Object.create(proto), initial);
|
|
923
843
|
for (const key of Object.keys(override)) {
|
|
@@ -928,12 +848,6 @@ function assign(initial, override) {
|
|
|
928
848
|
|
|
929
849
|
// src/object/clone.ts
|
|
930
850
|
function clone(obj) {
|
|
931
|
-
if (isPrimitive(obj)) {
|
|
932
|
-
return obj;
|
|
933
|
-
}
|
|
934
|
-
if (typeof obj === "function") {
|
|
935
|
-
return obj.bind({});
|
|
936
|
-
}
|
|
937
851
|
const proto = Object.getPrototypeOf(obj);
|
|
938
852
|
const newObj = typeof (proto == null ? void 0 : proto.constructor) === "function" ? new proto.constructor() : Object.create(proto);
|
|
939
853
|
for (const key of Object.getOwnPropertyNames(obj)) {
|
|
@@ -1011,9 +925,6 @@ function cloneDeep(root, customStrategy) {
|
|
|
1011
925
|
|
|
1012
926
|
// src/object/construct.ts
|
|
1013
927
|
function construct(obj) {
|
|
1014
|
-
if (!obj) {
|
|
1015
|
-
return {};
|
|
1016
|
-
}
|
|
1017
928
|
return Object.keys(obj).reduce((acc, path) => {
|
|
1018
929
|
return set(acc, path, obj[path]);
|
|
1019
930
|
}, {});
|
|
@@ -1021,9 +932,6 @@ function construct(obj) {
|
|
|
1021
932
|
|
|
1022
933
|
// src/object/crush.ts
|
|
1023
934
|
function crush(value) {
|
|
1024
|
-
if (!value) {
|
|
1025
|
-
return {};
|
|
1026
|
-
}
|
|
1027
935
|
return function crushReducer(crushed, value2, path) {
|
|
1028
936
|
if (isObject(value2) || isArray(value2)) {
|
|
1029
937
|
for (const [prop, propValue] of Object.entries(value2)) {
|
|
@@ -1066,9 +974,6 @@ function get(value, path, defaultValue) {
|
|
|
1066
974
|
|
|
1067
975
|
// src/object/invert.ts
|
|
1068
976
|
function invert(obj) {
|
|
1069
|
-
if (!obj) {
|
|
1070
|
-
return {};
|
|
1071
|
-
}
|
|
1072
977
|
const keys2 = Object.keys(obj);
|
|
1073
978
|
return keys2.reduce(
|
|
1074
979
|
(acc, key) => {
|
|
@@ -1081,9 +986,6 @@ function invert(obj) {
|
|
|
1081
986
|
|
|
1082
987
|
// src/object/keys.ts
|
|
1083
988
|
function keys(value) {
|
|
1084
|
-
if (!value) {
|
|
1085
|
-
return [];
|
|
1086
|
-
}
|
|
1087
989
|
const keys2 = [];
|
|
1088
990
|
const keyPath = [];
|
|
1089
991
|
const recurse = (value2) => {
|
|
@@ -1109,14 +1011,7 @@ function keys(value) {
|
|
|
1109
1011
|
|
|
1110
1012
|
// src/object/listify.ts
|
|
1111
1013
|
function listify(obj, toItem) {
|
|
1112
|
-
|
|
1113
|
-
return [];
|
|
1114
|
-
}
|
|
1115
|
-
const entries = Object.entries(obj);
|
|
1116
|
-
if (entries.length === 0) {
|
|
1117
|
-
return [];
|
|
1118
|
-
}
|
|
1119
|
-
return entries.reduce((acc, entry) => {
|
|
1014
|
+
return Object.entries(obj).reduce((acc, entry) => {
|
|
1120
1015
|
acc.push(toItem(entry[0], entry[1]));
|
|
1121
1016
|
return acc;
|
|
1122
1017
|
}, []);
|
|
@@ -1129,9 +1024,6 @@ function lowerize(obj) {
|
|
|
1129
1024
|
|
|
1130
1025
|
// src/object/mapEntries.ts
|
|
1131
1026
|
function mapEntries(obj, toEntry) {
|
|
1132
|
-
if (!obj) {
|
|
1133
|
-
return {};
|
|
1134
|
-
}
|
|
1135
1027
|
return Object.entries(obj).reduce(
|
|
1136
1028
|
(acc, [key, value]) => {
|
|
1137
1029
|
const [newKey, newValue] = toEntry(key, value);
|
|
@@ -1167,10 +1059,7 @@ function mapValues(obj, mapFunc) {
|
|
|
1167
1059
|
|
|
1168
1060
|
// src/object/omit.ts
|
|
1169
1061
|
function omit(obj, keys2) {
|
|
1170
|
-
if (
|
|
1171
|
-
return {};
|
|
1172
|
-
}
|
|
1173
|
-
if (!keys2 || keys2.length === 0) {
|
|
1062
|
+
if (keys2.length === 0) {
|
|
1174
1063
|
return obj;
|
|
1175
1064
|
}
|
|
1176
1065
|
return keys2.reduce(
|
|
@@ -1184,9 +1073,6 @@ function omit(obj, keys2) {
|
|
|
1184
1073
|
|
|
1185
1074
|
// src/object/pick.ts
|
|
1186
1075
|
function pick(obj, filter) {
|
|
1187
|
-
if (!obj) {
|
|
1188
|
-
return {};
|
|
1189
|
-
}
|
|
1190
1076
|
let keys2 = filter;
|
|
1191
1077
|
if (isArray(filter)) {
|
|
1192
1078
|
filter = null;
|
|
@@ -1203,28 +1089,20 @@ function pick(obj, filter) {
|
|
|
1203
1089
|
|
|
1204
1090
|
// src/object/set.ts
|
|
1205
1091
|
function set(initial, path, value) {
|
|
1206
|
-
if (
|
|
1207
|
-
return {};
|
|
1208
|
-
}
|
|
1209
|
-
if (!path || value === void 0) {
|
|
1092
|
+
if (value === void 0) {
|
|
1210
1093
|
return initial;
|
|
1211
1094
|
}
|
|
1212
1095
|
const root = clone(initial);
|
|
1213
1096
|
const keys2 = path.match(/[^.[\]]+/g);
|
|
1214
|
-
|
|
1215
|
-
keys2.
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
);
|
|
1219
|
-
}
|
|
1097
|
+
keys2 == null ? void 0 : keys2.reduce(
|
|
1098
|
+
(object, key, i) => i < keys2.length - 1 ? object[key] ??= isIntString(keys2[i + 1]) ? [] : {} : object[key] = value,
|
|
1099
|
+
root
|
|
1100
|
+
);
|
|
1220
1101
|
return root;
|
|
1221
1102
|
}
|
|
1222
1103
|
|
|
1223
1104
|
// src/object/shake.ts
|
|
1224
1105
|
function shake(obj, filter = (value) => value === void 0) {
|
|
1225
|
-
if (!obj) {
|
|
1226
|
-
return {};
|
|
1227
|
-
}
|
|
1228
1106
|
return Object.keys(obj).reduce((acc, key) => {
|
|
1229
1107
|
if (!filter(obj[key])) {
|
|
1230
1108
|
acc[key] = obj[key];
|
|
@@ -1431,14 +1309,7 @@ var series = (items, toKey = (item) => `${item}`) => {
|
|
|
1431
1309
|
|
|
1432
1310
|
// src/string/camel.ts
|
|
1433
1311
|
function camel(str) {
|
|
1434
|
-
|
|
1435
|
-
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())) ?? [];
|
|
1436
|
-
if (parts.length === 0) {
|
|
1437
|
-
return "";
|
|
1438
|
-
}
|
|
1439
|
-
if (parts.length === 1) {
|
|
1440
|
-
return parts[0];
|
|
1441
|
-
}
|
|
1312
|
+
const parts = str.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase());
|
|
1442
1313
|
return parts.reduce((acc, part) => {
|
|
1443
1314
|
return `${acc}${part.charAt(0).toUpperCase()}${part.slice(1)}`;
|
|
1444
1315
|
});
|
|
@@ -1446,23 +1317,13 @@ function camel(str) {
|
|
|
1446
1317
|
|
|
1447
1318
|
// src/string/capitalize.ts
|
|
1448
1319
|
function capitalize(str) {
|
|
1449
|
-
if (!str || str.length === 0) {
|
|
1450
|
-
return "";
|
|
1451
|
-
}
|
|
1452
1320
|
const lower = str.toLowerCase();
|
|
1453
1321
|
return lower.substring(0, 1).toUpperCase() + lower.substring(1, lower.length);
|
|
1454
1322
|
}
|
|
1455
1323
|
|
|
1456
1324
|
// src/string/dash.ts
|
|
1457
1325
|
function dash(str) {
|
|
1458
|
-
|
|
1459
|
-
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())) ?? [];
|
|
1460
|
-
if (parts.length === 0) {
|
|
1461
|
-
return "";
|
|
1462
|
-
}
|
|
1463
|
-
if (parts.length === 1) {
|
|
1464
|
-
return parts[0];
|
|
1465
|
-
}
|
|
1326
|
+
const parts = str.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase());
|
|
1466
1327
|
return parts.reduce((acc, part) => {
|
|
1467
1328
|
return `${acc}-${part.toLowerCase()}`;
|
|
1468
1329
|
});
|
|
@@ -1494,9 +1355,6 @@ function dedent(text, ...values) {
|
|
|
1494
1355
|
|
|
1495
1356
|
// src/string/pascal.ts
|
|
1496
1357
|
function pascal(str) {
|
|
1497
|
-
if (!str) {
|
|
1498
|
-
return "";
|
|
1499
|
-
}
|
|
1500
1358
|
const result = str.replace(
|
|
1501
1359
|
/(?:[^\w\d]|_|\s)+(\w)([A-Z]+)?/g,
|
|
1502
1360
|
(_, firstCharacter, capitalizedLetters) => {
|
|
@@ -1559,13 +1417,7 @@ function similarity(str1, str2) {
|
|
|
1559
1417
|
|
|
1560
1418
|
// src/string/snake.ts
|
|
1561
1419
|
function snake(str, options) {
|
|
1562
|
-
const parts =
|
|
1563
|
-
if (parts.length === 0) {
|
|
1564
|
-
return "";
|
|
1565
|
-
}
|
|
1566
|
-
if (parts.length === 1) {
|
|
1567
|
-
return parts[0];
|
|
1568
|
-
}
|
|
1420
|
+
const parts = str.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase());
|
|
1569
1421
|
const result = parts.reduce((acc, part) => {
|
|
1570
1422
|
return `${acc}_${part.toLowerCase()}`;
|
|
1571
1423
|
});
|
|
@@ -1586,17 +1438,11 @@ function template(str, data, regex = /\{\{(.+?)\}\}/g) {
|
|
|
1586
1438
|
|
|
1587
1439
|
// src/string/title.ts
|
|
1588
1440
|
function title(str) {
|
|
1589
|
-
if (!str) {
|
|
1590
|
-
return "";
|
|
1591
|
-
}
|
|
1592
1441
|
return str.split(/(?=[A-Z])|[\.\-\s_]/).map((s) => s.trim()).filter((s) => !!s).map((s) => capitalize(s.toLowerCase())).join(" ");
|
|
1593
1442
|
}
|
|
1594
1443
|
|
|
1595
1444
|
// src/string/trim.ts
|
|
1596
|
-
function trim(str, charsToTrim
|
|
1597
|
-
if (!str) {
|
|
1598
|
-
return "";
|
|
1599
|
-
}
|
|
1445
|
+
function trim(str, charsToTrim) {
|
|
1600
1446
|
const toTrim = charsToTrim.replace(/[\W]{1}/g, "\\$&");
|
|
1601
1447
|
const regex = new RegExp(`^[${toTrim}]+|[${toTrim}]+$`, "g");
|
|
1602
1448
|
return str.replace(regex, "");
|
|
@@ -1691,7 +1537,7 @@ function isError(value) {
|
|
|
1691
1537
|
|
|
1692
1538
|
// src/typed/isFloat.ts
|
|
1693
1539
|
function isFloat(value) {
|
|
1694
|
-
return isNumber(value) && value % 1 !== 0;
|
|
1540
|
+
return isNumber(value) && !Number.isNaN(value) && value % 1 !== 0;
|
|
1695
1541
|
}
|
|
1696
1542
|
|
|
1697
1543
|
// src/typed/isFunction.ts
|
|
@@ -1728,7 +1574,7 @@ function isNullish(value) {
|
|
|
1728
1574
|
|
|
1729
1575
|
// src/typed/isNumber.ts
|
|
1730
1576
|
function isNumber(value) {
|
|
1731
|
-
return typeof value === "number"
|
|
1577
|
+
return typeof value === "number";
|
|
1732
1578
|
}
|
|
1733
1579
|
|
|
1734
1580
|
// 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.f4c6a24",
|
|
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": {
|