moderndash 0.0.9 → 0.0.11
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/index.cjs +711 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +161 -79
- package/dist/index.js +15 -35
- package/dist/index.js.map +1 -1
- package/package.json +8 -3
- package/src/array/difference.ts +2 -2
- package/src/array/differenceBy.ts +1 -1
- package/src/array/index.ts +0 -3
- package/src/array/intersectionBy.ts +1 -1
- package/src/collection/countBy.ts +4 -4
- package/src/collection/groupBy.ts +5 -6
- package/src/function/after.ts +10 -4
- package/src/function/before.ts +8 -4
- package/src/function/debounce.ts +12 -11
- package/src/function/index.ts +1 -0
- package/src/function/memoize.ts +7 -3
- package/src/function/once.ts +6 -3
- package/src/function/throttle.ts +5 -3
- package/src/function/times.ts +26 -0
- package/src/helpers/collections.ts +2 -2
- package/src/lang/isEmpty.ts +33 -5
- package/src/lang/isEqual.ts +26 -0
- package/src/lang/isEqualWith.ts +30 -1
- package/src/types.ts +8 -2
- package/src/array/union.ts +0 -16
- package/src/array/unionBy.ts +0 -26
- package/src/array/unionWith.ts +0 -31
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,711 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
after: () => after,
|
|
24
|
+
before: () => before,
|
|
25
|
+
camelCase: () => camelCase,
|
|
26
|
+
capitalize: () => capitalize,
|
|
27
|
+
chunk: () => chunk,
|
|
28
|
+
countBy: () => countBy,
|
|
29
|
+
debounce: () => debounce,
|
|
30
|
+
deburr: () => deburr,
|
|
31
|
+
difference: () => difference,
|
|
32
|
+
differenceBy: () => differenceBy,
|
|
33
|
+
differenceWith: () => differenceWith,
|
|
34
|
+
dropRightWhile: () => dropRightWhile,
|
|
35
|
+
dropWhile: () => dropWhile,
|
|
36
|
+
escape: () => escape,
|
|
37
|
+
escapeRegExp: () => escapeRegExp,
|
|
38
|
+
groupBy: () => groupBy,
|
|
39
|
+
intersection: () => intersection,
|
|
40
|
+
intersectionBy: () => intersectionBy,
|
|
41
|
+
intersectionWith: () => intersectionWith,
|
|
42
|
+
isEmpty: () => isEmpty,
|
|
43
|
+
isEqual: () => isEqual,
|
|
44
|
+
isEqualWith: () => isEqualWith,
|
|
45
|
+
isPlainObject: () => isPlainObject,
|
|
46
|
+
kebabCase: () => kebabCase,
|
|
47
|
+
memoize: () => memoize,
|
|
48
|
+
once: () => once,
|
|
49
|
+
pascalCase: () => pascalCase,
|
|
50
|
+
pick: () => pick,
|
|
51
|
+
sample: () => sample,
|
|
52
|
+
sampleSize: () => sampleSize,
|
|
53
|
+
shuffle: () => shuffle,
|
|
54
|
+
snakeCase: () => snakeCase,
|
|
55
|
+
sortBy: () => sortBy,
|
|
56
|
+
startCase: () => startCase,
|
|
57
|
+
stripSpecialChars: () => stripSpecialChars,
|
|
58
|
+
takeRightWhile: () => takeRightWhile,
|
|
59
|
+
takeWhile: () => takeWhile,
|
|
60
|
+
throttle: () => throttle,
|
|
61
|
+
times: () => times,
|
|
62
|
+
unescapeHTML: () => unescapeHTML,
|
|
63
|
+
uniq: () => uniq,
|
|
64
|
+
uniqBy: () => uniqBy,
|
|
65
|
+
uniqWith: () => uniqWith,
|
|
66
|
+
unzip: () => unzip,
|
|
67
|
+
unzipWith: () => unzipWith,
|
|
68
|
+
zip: () => zip,
|
|
69
|
+
zipWith: () => zipWith
|
|
70
|
+
});
|
|
71
|
+
module.exports = __toCommonJS(src_exports);
|
|
72
|
+
|
|
73
|
+
// src/array/chunk.ts
|
|
74
|
+
function chunk(chunkSize, array) {
|
|
75
|
+
const sizeInteger = Math.trunc(chunkSize);
|
|
76
|
+
if (array.length === 0 || sizeInteger < 1) {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
const chunkedArray = [];
|
|
80
|
+
let i = 0;
|
|
81
|
+
while (i < array.length) {
|
|
82
|
+
chunkedArray.push(array.slice(i, i + sizeInteger));
|
|
83
|
+
i += sizeInteger;
|
|
84
|
+
}
|
|
85
|
+
return chunkedArray;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// src/array/differenceWith.ts
|
|
89
|
+
function differenceWith(comparator, ...arrays) {
|
|
90
|
+
const difference2 = [];
|
|
91
|
+
const [firstArray, ...restArrays] = arrays;
|
|
92
|
+
firstArray.forEach((element) => {
|
|
93
|
+
if (!restArrays.some((array) => array.some((item) => comparator(item, element)))) {
|
|
94
|
+
difference2.push(element);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return difference2;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/lang/isEqual.ts
|
|
101
|
+
function isEqual(value1, value2) {
|
|
102
|
+
if (value1 === value2)
|
|
103
|
+
return true;
|
|
104
|
+
if (Array.isArray(value1) && Array.isArray(value2)) {
|
|
105
|
+
return isSameArray(value1, value2);
|
|
106
|
+
}
|
|
107
|
+
if (value1 instanceof RegExp && value2 instanceof RegExp) {
|
|
108
|
+
return value1.toString() === value2.toString();
|
|
109
|
+
}
|
|
110
|
+
if (isObject(value1) && isObject(value2)) {
|
|
111
|
+
return isSameObject(value1, value2);
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
function isObject(value) {
|
|
116
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && Object.prototype.toString.call(value) === "[object Object]";
|
|
117
|
+
}
|
|
118
|
+
function isSameObject(value1, value2) {
|
|
119
|
+
const keys1 = Object.keys(value1);
|
|
120
|
+
const keys2 = Object.keys(value2);
|
|
121
|
+
if (!isEqual(keys1, keys2))
|
|
122
|
+
return false;
|
|
123
|
+
for (const key of keys1) {
|
|
124
|
+
if (!isEqual(value1[key], value2[key]))
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
function isSameArray(value1, value2) {
|
|
130
|
+
if (value1.length !== value2.length)
|
|
131
|
+
return false;
|
|
132
|
+
for (const [i, element] of value1.entries()) {
|
|
133
|
+
if (!isEqual(element, value2[i]))
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// src/array/difference.ts
|
|
140
|
+
function difference(...arrays) {
|
|
141
|
+
return differenceWith(isEqual, ...arrays);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/helpers/typeofChecks.ts
|
|
145
|
+
function isObjectKey(key) {
|
|
146
|
+
return typeof key === "string" || typeof key === "number" || typeof key === "symbol";
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/helpers/shortHands.ts
|
|
150
|
+
function getPropertyShorthand(key) {
|
|
151
|
+
return (object) => object[key];
|
|
152
|
+
}
|
|
153
|
+
function getIterateFunction(iteratee) {
|
|
154
|
+
if (typeof iteratee === "function") {
|
|
155
|
+
return iteratee;
|
|
156
|
+
} else if (isObjectKey(iteratee)) {
|
|
157
|
+
return getPropertyShorthand(iteratee);
|
|
158
|
+
} else {
|
|
159
|
+
throw new TypeError("Expected iteratee to be a function or a property name");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// src/lang/isEqualWith.ts
|
|
164
|
+
function isEqualWith(a, b, customizer) {
|
|
165
|
+
return isEqual(customizer(a), customizer(b));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/array/differenceBy.ts
|
|
169
|
+
function differenceBy(iteratee, ...arrays) {
|
|
170
|
+
const iterateeFunction = getIterateFunction(iteratee);
|
|
171
|
+
return differenceWith((a, b) => isEqualWith(a, b, iterateeFunction), ...arrays);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/array/dropRightWhile.ts
|
|
175
|
+
function dropRightWhile(predicate, array) {
|
|
176
|
+
let i = array.length;
|
|
177
|
+
while (i > 0 && predicate(array[i - 1])) {
|
|
178
|
+
i--;
|
|
179
|
+
}
|
|
180
|
+
return array.slice(0, i);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// src/array/dropWhile.ts
|
|
184
|
+
function dropWhile(predicate, array) {
|
|
185
|
+
const index = array.findIndex((x) => !predicate(x));
|
|
186
|
+
return array.slice(index === -1 ? array.length : index);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// src/array/intersectionWith.ts
|
|
190
|
+
function intersectionWith(comparator, ...arrays) {
|
|
191
|
+
const intersection2 = [];
|
|
192
|
+
const [firstArray, ...restArrays] = arrays;
|
|
193
|
+
firstArray.forEach((element) => {
|
|
194
|
+
if (restArrays.every((array) => array.some((item) => comparator(item, element)))) {
|
|
195
|
+
intersection2.push(element);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
return intersection2;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// src/array/intersection.ts
|
|
202
|
+
function intersection(...arrays) {
|
|
203
|
+
return intersectionWith(isEqual, ...arrays);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// src/array/intersectionBy.ts
|
|
207
|
+
function intersectionBy(iteratee, ...arrays) {
|
|
208
|
+
const iterateeFunction = getIterateFunction(iteratee);
|
|
209
|
+
return intersectionWith((a, b) => isEqualWith(a, b, iterateeFunction), ...arrays);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// src/array/sample.ts
|
|
213
|
+
function sample(array) {
|
|
214
|
+
if (array.length === 0) {
|
|
215
|
+
return void 0;
|
|
216
|
+
}
|
|
217
|
+
const randomIndex = Math.floor(Math.random() * array.length);
|
|
218
|
+
return array[randomIndex];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// src/array/sampleSize.ts
|
|
222
|
+
function sampleSize(size, array) {
|
|
223
|
+
const sampleArray = [];
|
|
224
|
+
if (array.length === 0 || size <= 0) {
|
|
225
|
+
return sampleArray;
|
|
226
|
+
}
|
|
227
|
+
for (let i = 0; i < size; i++) {
|
|
228
|
+
sampleArray.push(sample(array));
|
|
229
|
+
}
|
|
230
|
+
return sampleArray;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// src/array/shuffle.ts
|
|
234
|
+
function shuffle(array) {
|
|
235
|
+
const shuffledArray = [...array];
|
|
236
|
+
let currentIndex = shuffledArray.length;
|
|
237
|
+
let temporaryValue;
|
|
238
|
+
let randomIndex;
|
|
239
|
+
while (0 !== currentIndex) {
|
|
240
|
+
randomIndex = Math.floor(Math.random() * currentIndex);
|
|
241
|
+
currentIndex -= 1;
|
|
242
|
+
temporaryValue = shuffledArray[currentIndex];
|
|
243
|
+
shuffledArray[currentIndex] = shuffledArray[randomIndex];
|
|
244
|
+
shuffledArray[randomIndex] = temporaryValue;
|
|
245
|
+
}
|
|
246
|
+
return shuffledArray;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// src/array/takeRightWhile.ts
|
|
250
|
+
function takeRightWhile(predicate, array) {
|
|
251
|
+
const result = [];
|
|
252
|
+
for (let i = array.length - 1; i >= 0; i--) {
|
|
253
|
+
if (predicate(array[i])) {
|
|
254
|
+
result.unshift(array[i]);
|
|
255
|
+
} else {
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return result;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// src/array/takeWhile.ts
|
|
263
|
+
function takeWhile(predicate, array) {
|
|
264
|
+
const result = [];
|
|
265
|
+
for (const element of array) {
|
|
266
|
+
if (predicate(element)) {
|
|
267
|
+
result.push(element);
|
|
268
|
+
} else {
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return result;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// src/array/uniqWith.ts
|
|
276
|
+
function uniqWith(comparator, array) {
|
|
277
|
+
return array.filter((value, index, self) => {
|
|
278
|
+
return self.findIndex((otherValue) => comparator(value, otherValue)) === index;
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// src/array/uniq.ts
|
|
283
|
+
function uniq(array) {
|
|
284
|
+
return uniqWith(isEqual, array);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// src/array/uniqBy.ts
|
|
288
|
+
function uniqBy(iteratee, array) {
|
|
289
|
+
const iterateeFunction = getIterateFunction(iteratee);
|
|
290
|
+
return uniqWith((a, b) => iterateeFunction(a) === iterateeFunction(b), array);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// src/array/unzipWith.ts
|
|
294
|
+
function unzipWith(iteratee, array) {
|
|
295
|
+
const result = [];
|
|
296
|
+
for (const elements of array) {
|
|
297
|
+
result.push(iteratee(...elements));
|
|
298
|
+
}
|
|
299
|
+
return result;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// src/array/unzip.ts
|
|
303
|
+
function unzip(array) {
|
|
304
|
+
return unzipWith((...t) => t, array);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// src/array/zipWith.ts
|
|
308
|
+
function zipWith(combineFunc, ...arrays) {
|
|
309
|
+
const len = Math.min(...arrays.map((a) => a.length));
|
|
310
|
+
const zipped = [];
|
|
311
|
+
for (let i = 0; i < len; i++) {
|
|
312
|
+
zipped[i] = combineFunc(...arrays.map((a) => a[i]));
|
|
313
|
+
}
|
|
314
|
+
return zipped;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// src/array/zip.ts
|
|
318
|
+
function zip(...arrays) {
|
|
319
|
+
return zipWith((...t) => t, ...arrays);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// src/helpers/collections.ts
|
|
323
|
+
function getValuesFromCollection(collection) {
|
|
324
|
+
return Array.isArray(collection) ? collection : Object.values(collection);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// src/collection/countBy.ts
|
|
328
|
+
function countBy(collection, iteratee) {
|
|
329
|
+
const result = {};
|
|
330
|
+
const values = getValuesFromCollection(collection);
|
|
331
|
+
for (const value of values) {
|
|
332
|
+
const key = iteratee(value);
|
|
333
|
+
if (result[key] === void 0) {
|
|
334
|
+
result[key] = 1;
|
|
335
|
+
} else {
|
|
336
|
+
result[key] += 1;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return result;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// src/collection/groupBy.ts
|
|
343
|
+
function groupBy(collection, iteratee) {
|
|
344
|
+
const result = {};
|
|
345
|
+
const values = getValuesFromCollection(collection);
|
|
346
|
+
for (const value of values) {
|
|
347
|
+
const key = iteratee(value);
|
|
348
|
+
result[key] = result[key] ?? [];
|
|
349
|
+
result[key].push(value);
|
|
350
|
+
}
|
|
351
|
+
return result;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// src/collection/sortBy.ts
|
|
355
|
+
function sortBy(iteratee, array) {
|
|
356
|
+
return array.sort((a, b) => {
|
|
357
|
+
const aValue = iteratee(a);
|
|
358
|
+
const bValue = iteratee(b);
|
|
359
|
+
if (aValue < bValue) {
|
|
360
|
+
return -1;
|
|
361
|
+
}
|
|
362
|
+
if (aValue > bValue) {
|
|
363
|
+
return 1;
|
|
364
|
+
}
|
|
365
|
+
return 0;
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// src/function/after.ts
|
|
370
|
+
function after(n, func) {
|
|
371
|
+
let count = 1;
|
|
372
|
+
return (...args) => {
|
|
373
|
+
if (count >= n) {
|
|
374
|
+
return func(...args);
|
|
375
|
+
}
|
|
376
|
+
count += 1;
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// src/function/before.ts
|
|
381
|
+
function before(n, func) {
|
|
382
|
+
let count = 0;
|
|
383
|
+
let result;
|
|
384
|
+
return (...args) => {
|
|
385
|
+
if (count < n) {
|
|
386
|
+
count += 1;
|
|
387
|
+
result = func(...args);
|
|
388
|
+
}
|
|
389
|
+
return result;
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// src/function/debounce.ts
|
|
394
|
+
function debounce(fn, wait = 0, options = {}) {
|
|
395
|
+
let lastArgs;
|
|
396
|
+
let lastThis;
|
|
397
|
+
let result;
|
|
398
|
+
let timerId;
|
|
399
|
+
let lastCallTime;
|
|
400
|
+
let lastInvokeTime = 0;
|
|
401
|
+
const maxing = options.maxWait ?? false;
|
|
402
|
+
const leading = options.leading ?? false;
|
|
403
|
+
const trailing = options.trailing ?? true;
|
|
404
|
+
const maxWait = options.maxWait ?? 0;
|
|
405
|
+
function invokeFunc(time) {
|
|
406
|
+
const args = lastArgs;
|
|
407
|
+
const thisArg = lastThis;
|
|
408
|
+
lastArgs = lastThis = void 0;
|
|
409
|
+
lastInvokeTime = time;
|
|
410
|
+
result = fn.apply(thisArg, args);
|
|
411
|
+
return result;
|
|
412
|
+
}
|
|
413
|
+
function leadingEdge(time) {
|
|
414
|
+
lastInvokeTime = time;
|
|
415
|
+
timerId = setTimeout(timerExpired, wait);
|
|
416
|
+
return leading ? invokeFunc(time) : result;
|
|
417
|
+
}
|
|
418
|
+
function remainingWait(time) {
|
|
419
|
+
const timeSinceLastCall = time - lastCallTime;
|
|
420
|
+
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
421
|
+
const timeWaiting = wait - timeSinceLastCall;
|
|
422
|
+
return maxing ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
|
|
423
|
+
}
|
|
424
|
+
function shouldInvoke(time) {
|
|
425
|
+
if (lastCallTime === void 0)
|
|
426
|
+
return true;
|
|
427
|
+
const timeSinceLastCall = time - lastCallTime;
|
|
428
|
+
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
429
|
+
return timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
|
|
430
|
+
}
|
|
431
|
+
function timerExpired() {
|
|
432
|
+
const time = Date.now();
|
|
433
|
+
if (shouldInvoke(time)) {
|
|
434
|
+
return trailingEdge(time);
|
|
435
|
+
}
|
|
436
|
+
timerId = setTimeout(timerExpired, remainingWait(time));
|
|
437
|
+
}
|
|
438
|
+
function trailingEdge(time) {
|
|
439
|
+
timerId = void 0;
|
|
440
|
+
if (trailing && lastArgs) {
|
|
441
|
+
return invokeFunc(time);
|
|
442
|
+
}
|
|
443
|
+
lastArgs = lastThis = void 0;
|
|
444
|
+
return result;
|
|
445
|
+
}
|
|
446
|
+
function cancel() {
|
|
447
|
+
if (timerId !== void 0) {
|
|
448
|
+
clearTimeout(timerId);
|
|
449
|
+
}
|
|
450
|
+
lastInvokeTime = 0;
|
|
451
|
+
lastArgs = lastCallTime = lastThis = timerId = void 0;
|
|
452
|
+
}
|
|
453
|
+
function flush() {
|
|
454
|
+
return timerId === void 0 ? result : trailingEdge(Date.now());
|
|
455
|
+
}
|
|
456
|
+
function debounced(...args) {
|
|
457
|
+
const time = Date.now();
|
|
458
|
+
const isInvoking = shouldInvoke(time);
|
|
459
|
+
lastArgs = args;
|
|
460
|
+
lastThis = this;
|
|
461
|
+
lastCallTime = time;
|
|
462
|
+
if (isInvoking) {
|
|
463
|
+
if (timerId === void 0) {
|
|
464
|
+
return leadingEdge(lastCallTime);
|
|
465
|
+
}
|
|
466
|
+
if (maxing) {
|
|
467
|
+
clearTimeout(timerId);
|
|
468
|
+
timerId = setTimeout(timerExpired, wait);
|
|
469
|
+
return invokeFunc(lastCallTime);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
if (timerId === void 0) {
|
|
473
|
+
timerId = setTimeout(timerExpired, wait);
|
|
474
|
+
}
|
|
475
|
+
return result;
|
|
476
|
+
}
|
|
477
|
+
debounced.cancel = cancel;
|
|
478
|
+
debounced.flush = flush;
|
|
479
|
+
return debounced;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// src/function/memoize.ts
|
|
483
|
+
var defaultResolver = (...args) => JSON.stringify(args);
|
|
484
|
+
function memoize(func, resolver = defaultResolver) {
|
|
485
|
+
const cache = /* @__PURE__ */ new Map();
|
|
486
|
+
const memoizedFunc = (...args) => {
|
|
487
|
+
const key = resolver(...args);
|
|
488
|
+
if (cache.has(key)) {
|
|
489
|
+
return cache.get(key);
|
|
490
|
+
}
|
|
491
|
+
const result = func(...args);
|
|
492
|
+
cache.set(key, result);
|
|
493
|
+
return result;
|
|
494
|
+
};
|
|
495
|
+
memoizedFunc.cache = cache;
|
|
496
|
+
return memoizedFunc;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// src/function/once.ts
|
|
500
|
+
function once(func) {
|
|
501
|
+
return before(1, func);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// src/function/throttle.ts
|
|
505
|
+
function throttle(func, wait = 0, options = {}) {
|
|
506
|
+
return debounce(func, wait, {
|
|
507
|
+
leading: options.leading ?? true,
|
|
508
|
+
maxWait: wait,
|
|
509
|
+
trailing: options.trailing ?? true
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// src/function/times.ts
|
|
514
|
+
function times(n, func) {
|
|
515
|
+
const result = [];
|
|
516
|
+
for (let i = 0; i < n; i++) {
|
|
517
|
+
result.push(func(i));
|
|
518
|
+
}
|
|
519
|
+
return result;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// src/lang/isEmpty.ts
|
|
523
|
+
function isEmpty(value) {
|
|
524
|
+
if (value === null || value === void 0) {
|
|
525
|
+
return true;
|
|
526
|
+
}
|
|
527
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
528
|
+
return value.length === 0;
|
|
529
|
+
}
|
|
530
|
+
if (value instanceof Map || value instanceof Set) {
|
|
531
|
+
return value.size === 0;
|
|
532
|
+
}
|
|
533
|
+
if (typeof value === "object") {
|
|
534
|
+
return Object.keys(value).length === 0;
|
|
535
|
+
}
|
|
536
|
+
return false;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// src/lang/isPlainObject.ts
|
|
540
|
+
function isPlainObject(value) {
|
|
541
|
+
return value !== null && typeof value === "object" && value.constructor === Object;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// src/object/pick.ts
|
|
545
|
+
function pick(object, keys) {
|
|
546
|
+
const result = {};
|
|
547
|
+
for (const key of keys) {
|
|
548
|
+
result[key] = object[key];
|
|
549
|
+
}
|
|
550
|
+
return result;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// src/string/deburr.ts
|
|
554
|
+
function deburr(str) {
|
|
555
|
+
return str.replace(/[^\u0000-\u007E]/g, (chr) => chr.normalize("NFD").replace(/[\u0300-\u036F]/g, ""));
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// src/helpers/stringModifiers.ts
|
|
559
|
+
function splitWords(str) {
|
|
560
|
+
str = deburr(str);
|
|
561
|
+
const regex = new RegExp(
|
|
562
|
+
"[^\\dA-Za-z]|(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])"
|
|
563
|
+
);
|
|
564
|
+
return str.split(regex).filter(Boolean);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// src/string/camelCase.ts
|
|
568
|
+
function camelCase(str) {
|
|
569
|
+
const words = splitWords(str);
|
|
570
|
+
const camelCase2 = words.map((word, index) => {
|
|
571
|
+
if (index === 0) {
|
|
572
|
+
return word.toLowerCase();
|
|
573
|
+
}
|
|
574
|
+
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
575
|
+
});
|
|
576
|
+
return camelCase2.join("");
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// src/string/capitalize.ts
|
|
580
|
+
function capitalize(str) {
|
|
581
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// src/string/escape.ts
|
|
585
|
+
function escape(str) {
|
|
586
|
+
const escapeChars = {
|
|
587
|
+
"&": "&",
|
|
588
|
+
"<": "<",
|
|
589
|
+
">": ">",
|
|
590
|
+
"'": "'",
|
|
591
|
+
'"': """
|
|
592
|
+
};
|
|
593
|
+
return str.replace(/["&'<>]/g, (char) => escapeChars[char] || char);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// src/string/escapeRegExp.ts
|
|
597
|
+
function escapeRegExp(str) {
|
|
598
|
+
return str.replace(/[$()*+.?[\\\]^{|}]/g, "\\$&");
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// src/string/kebabCase.ts
|
|
602
|
+
function kebabCase(str) {
|
|
603
|
+
const words = splitWords(str);
|
|
604
|
+
let kebabCase2 = "";
|
|
605
|
+
for (const word of words) {
|
|
606
|
+
kebabCase2 += word.toLowerCase() + "-";
|
|
607
|
+
}
|
|
608
|
+
return kebabCase2.slice(0, -1);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// src/string/pascalCase.ts
|
|
612
|
+
function pascalCase(str) {
|
|
613
|
+
const words = splitWords(str);
|
|
614
|
+
let pascalCase2 = "";
|
|
615
|
+
for (const word of words) {
|
|
616
|
+
pascalCase2 += word.charAt(0).toUpperCase() + word.slice(1);
|
|
617
|
+
}
|
|
618
|
+
return pascalCase2;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// src/string/snakeCase.ts
|
|
622
|
+
function snakeCase(str) {
|
|
623
|
+
const words = splitWords(str);
|
|
624
|
+
let snakeCase2 = "";
|
|
625
|
+
for (const word of words) {
|
|
626
|
+
if (snakeCase2.length > 0) {
|
|
627
|
+
snakeCase2 += "_";
|
|
628
|
+
}
|
|
629
|
+
snakeCase2 += word.toLowerCase();
|
|
630
|
+
}
|
|
631
|
+
return snakeCase2;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// src/string/startCase.ts
|
|
635
|
+
function startCase(str) {
|
|
636
|
+
const words = splitWords(str);
|
|
637
|
+
let startCase2 = "";
|
|
638
|
+
for (const word of words) {
|
|
639
|
+
startCase2 += word.charAt(0).toUpperCase() + word.slice(1).toLowerCase() + " ";
|
|
640
|
+
}
|
|
641
|
+
return startCase2.trimEnd();
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// src/string/stripSpecialChars.ts
|
|
645
|
+
function stripSpecialChars(str) {
|
|
646
|
+
str = deburr(str);
|
|
647
|
+
return str.replace(/[^\s\w]/gi, "");
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// src/string/unescape.ts
|
|
651
|
+
function unescapeHTML(html) {
|
|
652
|
+
const entityMap = {
|
|
653
|
+
"&": "&",
|
|
654
|
+
"<": "<",
|
|
655
|
+
">": ">",
|
|
656
|
+
""": '"',
|
|
657
|
+
"'": "'"
|
|
658
|
+
};
|
|
659
|
+
return html.replace(/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g, (entity) => entityMap[entity] || entity);
|
|
660
|
+
}
|
|
661
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
662
|
+
0 && (module.exports = {
|
|
663
|
+
after,
|
|
664
|
+
before,
|
|
665
|
+
camelCase,
|
|
666
|
+
capitalize,
|
|
667
|
+
chunk,
|
|
668
|
+
countBy,
|
|
669
|
+
debounce,
|
|
670
|
+
deburr,
|
|
671
|
+
difference,
|
|
672
|
+
differenceBy,
|
|
673
|
+
differenceWith,
|
|
674
|
+
dropRightWhile,
|
|
675
|
+
dropWhile,
|
|
676
|
+
escape,
|
|
677
|
+
escapeRegExp,
|
|
678
|
+
groupBy,
|
|
679
|
+
intersection,
|
|
680
|
+
intersectionBy,
|
|
681
|
+
intersectionWith,
|
|
682
|
+
isEmpty,
|
|
683
|
+
isEqual,
|
|
684
|
+
isEqualWith,
|
|
685
|
+
isPlainObject,
|
|
686
|
+
kebabCase,
|
|
687
|
+
memoize,
|
|
688
|
+
once,
|
|
689
|
+
pascalCase,
|
|
690
|
+
pick,
|
|
691
|
+
sample,
|
|
692
|
+
sampleSize,
|
|
693
|
+
shuffle,
|
|
694
|
+
snakeCase,
|
|
695
|
+
sortBy,
|
|
696
|
+
startCase,
|
|
697
|
+
stripSpecialChars,
|
|
698
|
+
takeRightWhile,
|
|
699
|
+
takeWhile,
|
|
700
|
+
throttle,
|
|
701
|
+
times,
|
|
702
|
+
unescapeHTML,
|
|
703
|
+
uniq,
|
|
704
|
+
uniqBy,
|
|
705
|
+
uniqWith,
|
|
706
|
+
unzip,
|
|
707
|
+
unzipWith,
|
|
708
|
+
zip,
|
|
709
|
+
zipWith
|
|
710
|
+
});
|
|
711
|
+
//# sourceMappingURL=index.cjs.map
|