@vinicunca/perkakas 0.0.10 → 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 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,
@@ -86,6 +87,7 @@ __export(src_exports, {
86
87
  meanBy: () => meanBy,
87
88
  merge: () => merge,
88
89
  mergeAll: () => mergeAll,
90
+ mergeDeep: () => mergeDeep,
89
91
  minBy: () => minBy,
90
92
  noop: () => noop,
91
93
  omit: () => omit,
@@ -140,26 +142,26 @@ module.exports = __toCommonJS(src_exports);
140
142
 
141
143
  // src/aria/key-codes.ts
142
144
  var KEY_CODES = {
143
- TAB: "Tab",
145
+ ALT: "Alt",
144
146
  ARROW_DOWN: "ArrowDown",
145
- ARROW_UP: "ArrowUp",
146
147
  ARROW_LEFT: "ArrowLeft",
147
148
  ARROW_RIGHT: "ArrowRight",
149
+ ARROW_UP: "ArrowUp",
150
+ AT: "@",
151
+ BACKSPACE: "Backspace",
152
+ CTRL: "Control",
153
+ DELETE: "Delete",
154
+ END: "End",
148
155
  ENTER: "Enter",
149
156
  ESC: "Escape",
150
- SPACE: "Space",
151
- SHIFT: "Shift",
157
+ HOME: "Home",
152
158
  KEY_F: "KEY_F",
153
- CTRL: "Control",
154
- ALT: "Alt",
155
159
  META: "Meta",
156
- AT: "@",
157
- DELETE: "Delete",
158
- BACKSPACE: "Backspace",
159
- HOME: "Home",
160
- END: "End",
160
+ PAGE_DOWN: "PageDown",
161
161
  PAGE_UP: "PageUp",
162
- PAGE_DOWN: "PageDown"
162
+ SHIFT: "Shift",
163
+ SPACE: "Space",
164
+ TAB: "Tab"
163
165
  };
164
166
 
165
167
  // src/function/pipe.ts
@@ -199,7 +201,7 @@ function pipe(value, ...operations) {
199
201
  }
200
202
  const acc = [];
201
203
  for (const item of ret) {
202
- if (_processItem({ item, acc, lazySeq })) {
204
+ if (_processItem({ acc, item, lazySeq })) {
203
205
  break;
204
206
  }
205
207
  }
@@ -214,9 +216,9 @@ function pipe(value, ...operations) {
214
216
  return ret;
215
217
  }
216
218
  function _processItem({
219
+ acc,
217
220
  item,
218
- lazySeq,
219
- acc
221
+ lazySeq
220
222
  }) {
221
223
  if (lazySeq.length === 0) {
222
224
  acc.push(item);
@@ -237,8 +239,8 @@ function _processItem({
237
239
  const nextValues = lazyResult.next;
238
240
  for (const subItem of nextValues) {
239
241
  const subResult = _processItem({
240
- item: subItem,
241
242
  acc,
243
+ item: subItem,
242
244
  lazySeq: lazySeq.slice(i + 1)
243
245
  });
244
246
  if (subResult) {
@@ -260,10 +262,7 @@ function _processItem({
260
262
  if (lazyResult.hasNext) {
261
263
  acc.push(item);
262
264
  }
263
- if (isDone) {
264
- return true;
265
- }
266
- return false;
265
+ return !!isDone;
267
266
  }
268
267
 
269
268
  // src/function/create-pipe.ts
@@ -294,6 +293,103 @@ function once(fn) {
294
293
  };
295
294
  }
296
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
+
297
393
  // src/function/purry.ts
298
394
  function purry(fn, args, lazy) {
299
395
  const diff = fn.length - args.length;
@@ -813,8 +909,8 @@ function _flatten(items) {
813
909
  if (Array.isArray(next)) {
814
910
  return {
815
911
  done: false,
816
- hasNext: true,
817
912
  hasMany: true,
913
+ hasNext: true,
818
914
  next
819
915
  };
820
916
  }
@@ -842,8 +938,8 @@ function _flatMap(array, fn) {
842
938
  if (Array.isArray(next)) {
843
939
  return {
844
940
  done: false,
845
- hasNext: true,
846
941
  hasMany: true,
942
+ hasNext: true,
847
943
  next
848
944
  };
849
945
  }
@@ -885,8 +981,8 @@ function _flattenDeepValue(value) {
885
981
  if (Array.isArray(next)) {
886
982
  return {
887
983
  done: false,
888
- hasNext: true,
889
984
  hasMany: true,
985
+ hasNext: true,
890
986
  next
891
987
  };
892
988
  }
@@ -1614,6 +1710,9 @@ function _zip(first2, second) {
1614
1710
  }
1615
1711
  return result;
1616
1712
  }
1713
+ ((zip2) => {
1714
+ zip2.strict = zip2;
1715
+ })(zip || (zip = {}));
1617
1716
 
1618
1717
  // src/array/zip-obj.ts
1619
1718
  function zipObj(...args) {
@@ -1892,6 +1991,32 @@ function _merge(a, b) {
1892
1991
  return Object.assign({}, a, b);
1893
1992
  }
1894
1993
 
1994
+ // src/object/merge-deep.ts
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;
2003
+ }
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);
2013
+ }
2014
+ return output;
2015
+ }
2016
+ function isRecord(object) {
2017
+ return typeof object === "object" && object !== null && Object.getPrototypeOf(object) === Object.prototype;
2018
+ }
2019
+
1895
2020
  // src/object/omit.ts
1896
2021
  function omit(...args) {
1897
2022
  return purry(_omit, args);
@@ -2170,6 +2295,7 @@ var isBrowser = typeof window !== "undefined";
2170
2295
  concat,
2171
2296
  countBy,
2172
2297
  createPipe,
2298
+ debounce,
2173
2299
  difference,
2174
2300
  differenceWith,
2175
2301
  drop,
@@ -2224,6 +2350,7 @@ var isBrowser = typeof window !== "undefined";
2224
2350
  meanBy,
2225
2351
  merge,
2226
2352
  mergeAll,
2353
+ mergeDeep,
2227
2354
  minBy,
2228
2355
  noop,
2229
2356
  omit,