@vinicunca/perkakas 0.0.11 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +142 -52
- package/dist/index.d.cts +226 -90
- package/dist/index.d.ts +226 -90
- package/dist/index.js +141 -52
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +3 -3
- package/package.json +7 -8
package/dist/index.cjs
CHANGED
|
@@ -32,6 +32,7 @@ __export(src_exports, {
|
|
|
32
32
|
concat: () => concat,
|
|
33
33
|
countBy: () => countBy,
|
|
34
34
|
createPipe: () => createPipe,
|
|
35
|
+
debounce: () => debounce,
|
|
35
36
|
difference: () => difference,
|
|
36
37
|
differenceWith: () => differenceWith,
|
|
37
38
|
drop: () => drop,
|
|
@@ -141,26 +142,26 @@ module.exports = __toCommonJS(src_exports);
|
|
|
141
142
|
|
|
142
143
|
// src/aria/key-codes.ts
|
|
143
144
|
var KEY_CODES = {
|
|
144
|
-
|
|
145
|
+
ALT: "Alt",
|
|
145
146
|
ARROW_DOWN: "ArrowDown",
|
|
146
|
-
ARROW_UP: "ArrowUp",
|
|
147
147
|
ARROW_LEFT: "ArrowLeft",
|
|
148
148
|
ARROW_RIGHT: "ArrowRight",
|
|
149
|
+
ARROW_UP: "ArrowUp",
|
|
150
|
+
AT: "@",
|
|
151
|
+
BACKSPACE: "Backspace",
|
|
152
|
+
CTRL: "Control",
|
|
153
|
+
DELETE: "Delete",
|
|
154
|
+
END: "End",
|
|
149
155
|
ENTER: "Enter",
|
|
150
156
|
ESC: "Escape",
|
|
151
|
-
|
|
152
|
-
SHIFT: "Shift",
|
|
157
|
+
HOME: "Home",
|
|
153
158
|
KEY_F: "KEY_F",
|
|
154
|
-
CTRL: "Control",
|
|
155
|
-
ALT: "Alt",
|
|
156
159
|
META: "Meta",
|
|
157
|
-
|
|
158
|
-
DELETE: "Delete",
|
|
159
|
-
BACKSPACE: "Backspace",
|
|
160
|
-
HOME: "Home",
|
|
161
|
-
END: "End",
|
|
160
|
+
PAGE_DOWN: "PageDown",
|
|
162
161
|
PAGE_UP: "PageUp",
|
|
163
|
-
|
|
162
|
+
SHIFT: "Shift",
|
|
163
|
+
SPACE: "Space",
|
|
164
|
+
TAB: "Tab"
|
|
164
165
|
};
|
|
165
166
|
|
|
166
167
|
// src/function/pipe.ts
|
|
@@ -200,7 +201,7 @@ function pipe(value, ...operations) {
|
|
|
200
201
|
}
|
|
201
202
|
const acc = [];
|
|
202
203
|
for (const item of ret) {
|
|
203
|
-
if (_processItem({
|
|
204
|
+
if (_processItem({ acc, item, lazySeq })) {
|
|
204
205
|
break;
|
|
205
206
|
}
|
|
206
207
|
}
|
|
@@ -215,9 +216,9 @@ function pipe(value, ...operations) {
|
|
|
215
216
|
return ret;
|
|
216
217
|
}
|
|
217
218
|
function _processItem({
|
|
219
|
+
acc,
|
|
218
220
|
item,
|
|
219
|
-
lazySeq
|
|
220
|
-
acc
|
|
221
|
+
lazySeq
|
|
221
222
|
}) {
|
|
222
223
|
if (lazySeq.length === 0) {
|
|
223
224
|
acc.push(item);
|
|
@@ -238,8 +239,8 @@ function _processItem({
|
|
|
238
239
|
const nextValues = lazyResult.next;
|
|
239
240
|
for (const subItem of nextValues) {
|
|
240
241
|
const subResult = _processItem({
|
|
241
|
-
item: subItem,
|
|
242
242
|
acc,
|
|
243
|
+
item: subItem,
|
|
243
244
|
lazySeq: lazySeq.slice(i + 1)
|
|
244
245
|
});
|
|
245
246
|
if (subResult) {
|
|
@@ -261,10 +262,7 @@ function _processItem({
|
|
|
261
262
|
if (lazyResult.hasNext) {
|
|
262
263
|
acc.push(item);
|
|
263
264
|
}
|
|
264
|
-
|
|
265
|
-
return true;
|
|
266
|
-
}
|
|
267
|
-
return false;
|
|
265
|
+
return !!isDone;
|
|
268
266
|
}
|
|
269
267
|
|
|
270
268
|
// src/function/create-pipe.ts
|
|
@@ -295,6 +293,103 @@ function once(fn) {
|
|
|
295
293
|
};
|
|
296
294
|
}
|
|
297
295
|
|
|
296
|
+
// src/function/debounce.ts
|
|
297
|
+
function debounce(func, {
|
|
298
|
+
maxWaitMs,
|
|
299
|
+
timing = "trailing",
|
|
300
|
+
waitMs
|
|
301
|
+
}) {
|
|
302
|
+
if (maxWaitMs !== void 0 && waitMs !== void 0 && maxWaitMs < waitMs) {
|
|
303
|
+
throw new Error(
|
|
304
|
+
`debounce: maxWaitMs (${maxWaitMs}) cannot be less than waitMs (${waitMs})`
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
let coolDownTimeoutId;
|
|
308
|
+
let maxWaitTimeoutId;
|
|
309
|
+
let latestCallArgs;
|
|
310
|
+
let result;
|
|
311
|
+
function handleDebouncedCall(args) {
|
|
312
|
+
latestCallArgs = args;
|
|
313
|
+
if (maxWaitMs !== void 0 && maxWaitTimeoutId === void 0) {
|
|
314
|
+
maxWaitTimeoutId = setTimeout(handleInvoke, maxWaitMs);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
function handleInvoke() {
|
|
318
|
+
if (latestCallArgs === void 0) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if (maxWaitTimeoutId !== void 0) {
|
|
322
|
+
const timeoutId = maxWaitTimeoutId;
|
|
323
|
+
maxWaitTimeoutId = void 0;
|
|
324
|
+
clearTimeout(timeoutId);
|
|
325
|
+
}
|
|
326
|
+
const args = latestCallArgs;
|
|
327
|
+
latestCallArgs = void 0;
|
|
328
|
+
result = func(...args);
|
|
329
|
+
}
|
|
330
|
+
function handleCoolDownEnd() {
|
|
331
|
+
if (coolDownTimeoutId === void 0) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const timeoutId = coolDownTimeoutId;
|
|
335
|
+
coolDownTimeoutId = void 0;
|
|
336
|
+
clearTimeout(timeoutId);
|
|
337
|
+
if (latestCallArgs !== void 0) {
|
|
338
|
+
handleInvoke();
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
get cachedValue() {
|
|
343
|
+
return result;
|
|
344
|
+
},
|
|
345
|
+
call: (...args) => {
|
|
346
|
+
if (coolDownTimeoutId === void 0) {
|
|
347
|
+
if (timing === "trailing") {
|
|
348
|
+
handleDebouncedCall(args);
|
|
349
|
+
} else {
|
|
350
|
+
result = func(...args);
|
|
351
|
+
}
|
|
352
|
+
} else {
|
|
353
|
+
if (timing !== "leading") {
|
|
354
|
+
handleDebouncedCall(args);
|
|
355
|
+
}
|
|
356
|
+
const timeoutId = coolDownTimeoutId;
|
|
357
|
+
coolDownTimeoutId = void 0;
|
|
358
|
+
clearTimeout(timeoutId);
|
|
359
|
+
}
|
|
360
|
+
coolDownTimeoutId = setTimeout(
|
|
361
|
+
handleCoolDownEnd,
|
|
362
|
+
// If waitMs is not defined but maxWaitMs *is* it means the user is only
|
|
363
|
+
// interested in the leaky-bucket nature of the debouncer which is
|
|
364
|
+
// achieved by setting waitMs === maxWaitMs. If both are not defined we
|
|
365
|
+
// default to 0 which would wait until the end of the execution frame.
|
|
366
|
+
waitMs ?? maxWaitMs ?? 0
|
|
367
|
+
);
|
|
368
|
+
return result;
|
|
369
|
+
},
|
|
370
|
+
cancel: () => {
|
|
371
|
+
if (coolDownTimeoutId !== void 0) {
|
|
372
|
+
const timeoutId = coolDownTimeoutId;
|
|
373
|
+
coolDownTimeoutId = void 0;
|
|
374
|
+
clearTimeout(timeoutId);
|
|
375
|
+
}
|
|
376
|
+
if (maxWaitTimeoutId !== void 0) {
|
|
377
|
+
const timeoutId = maxWaitTimeoutId;
|
|
378
|
+
maxWaitTimeoutId = void 0;
|
|
379
|
+
clearTimeout(timeoutId);
|
|
380
|
+
}
|
|
381
|
+
latestCallArgs = void 0;
|
|
382
|
+
},
|
|
383
|
+
flush: () => {
|
|
384
|
+
handleCoolDownEnd();
|
|
385
|
+
return result;
|
|
386
|
+
},
|
|
387
|
+
get isPending() {
|
|
388
|
+
return coolDownTimeoutId !== void 0;
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
|
|
298
393
|
// src/function/purry.ts
|
|
299
394
|
function purry(fn, args, lazy) {
|
|
300
395
|
const diff = fn.length - args.length;
|
|
@@ -814,8 +909,8 @@ function _flatten(items) {
|
|
|
814
909
|
if (Array.isArray(next)) {
|
|
815
910
|
return {
|
|
816
911
|
done: false,
|
|
817
|
-
hasNext: true,
|
|
818
912
|
hasMany: true,
|
|
913
|
+
hasNext: true,
|
|
819
914
|
next
|
|
820
915
|
};
|
|
821
916
|
}
|
|
@@ -843,8 +938,8 @@ function _flatMap(array, fn) {
|
|
|
843
938
|
if (Array.isArray(next)) {
|
|
844
939
|
return {
|
|
845
940
|
done: false,
|
|
846
|
-
hasNext: true,
|
|
847
941
|
hasMany: true,
|
|
942
|
+
hasNext: true,
|
|
848
943
|
next
|
|
849
944
|
};
|
|
850
945
|
}
|
|
@@ -886,8 +981,8 @@ function _flattenDeepValue(value) {
|
|
|
886
981
|
if (Array.isArray(next)) {
|
|
887
982
|
return {
|
|
888
983
|
done: false,
|
|
889
|
-
hasNext: true,
|
|
890
984
|
hasMany: true,
|
|
985
|
+
hasNext: true,
|
|
891
986
|
next
|
|
892
987
|
};
|
|
893
988
|
}
|
|
@@ -1615,6 +1710,9 @@ function _zip(first2, second) {
|
|
|
1615
1710
|
}
|
|
1616
1711
|
return result;
|
|
1617
1712
|
}
|
|
1713
|
+
((zip2) => {
|
|
1714
|
+
zip2.strict = zip2;
|
|
1715
|
+
})(zip || (zip = {}));
|
|
1618
1716
|
|
|
1619
1717
|
// src/array/zip-obj.ts
|
|
1620
1718
|
function zipObj(...args) {
|
|
@@ -1894,39 +1992,30 @@ function _merge(a, b) {
|
|
|
1894
1992
|
}
|
|
1895
1993
|
|
|
1896
1994
|
// src/object/merge-deep.ts
|
|
1897
|
-
function mergeDeep({
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
const
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
if (mergeArray && Array.isArray(patch_)) {
|
|
1906
|
-
return [...original_, ...patch_];
|
|
1907
|
-
} else {
|
|
1908
|
-
return [...patch_];
|
|
1995
|
+
function mergeDeep(...args) {
|
|
1996
|
+
return purry(mergeDeepImplementation, args);
|
|
1997
|
+
}
|
|
1998
|
+
function mergeDeepImplementation(destination, source) {
|
|
1999
|
+
const output = { ...destination, ...source };
|
|
2000
|
+
for (const key in source) {
|
|
2001
|
+
if (!(key in destination)) {
|
|
2002
|
+
continue;
|
|
1909
2003
|
}
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
original: original_[key],
|
|
1920
|
-
patch: patch_[key]
|
|
1921
|
-
});
|
|
1922
|
-
} else {
|
|
1923
|
-
Object.assign(output, { [key]: patch_[key] });
|
|
1924
|
-
}
|
|
1925
|
-
;
|
|
1926
|
-
});
|
|
2004
|
+
const destinationValue = destination[key];
|
|
2005
|
+
if (!isRecord(destinationValue)) {
|
|
2006
|
+
continue;
|
|
2007
|
+
}
|
|
2008
|
+
const sourceValue = source[key];
|
|
2009
|
+
if (!isRecord(sourceValue)) {
|
|
2010
|
+
continue;
|
|
2011
|
+
}
|
|
2012
|
+
output[key] = mergeDeepImplementation(destinationValue, sourceValue);
|
|
1927
2013
|
}
|
|
1928
2014
|
return output;
|
|
1929
2015
|
}
|
|
2016
|
+
function isRecord(object) {
|
|
2017
|
+
return typeof object === "object" && object !== null && Object.getPrototypeOf(object) === Object.prototype;
|
|
2018
|
+
}
|
|
1930
2019
|
|
|
1931
2020
|
// src/object/omit.ts
|
|
1932
2021
|
function omit(...args) {
|
|
@@ -2206,6 +2295,7 @@ var isBrowser = typeof window !== "undefined";
|
|
|
2206
2295
|
concat,
|
|
2207
2296
|
countBy,
|
|
2208
2297
|
createPipe,
|
|
2298
|
+
debounce,
|
|
2209
2299
|
difference,
|
|
2210
2300
|
differenceWith,
|
|
2211
2301
|
drop,
|