es-toolkit 1.23.0-dev.749 → 1.23.0-dev.751

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.
@@ -17,11 +17,10 @@ function every(source, doesMatch) {
17
17
  switch (typeof doesMatch) {
18
18
  case 'function': {
19
19
  if (!Array.isArray(source)) {
20
- const entries = Object.entries(source);
21
- for (let i = 0; i < entries.length; i++) {
22
- const entry = entries[i];
23
- const key = entry[0];
24
- const value = entry[1];
20
+ const keys = Object.keys(source);
21
+ for (let i = 0; i < keys.length; i++) {
22
+ const key = keys[i];
23
+ const value = source[key];
25
24
  if (!doesMatch(value, key, source)) {
26
25
  return false;
27
26
  }
@@ -13,11 +13,10 @@ function filter(source, predicate) {
13
13
  case 'function': {
14
14
  if (!Array.isArray(source)) {
15
15
  const result = [];
16
- const entries = Object.entries(source);
17
- for (let i = 0; i < entries.length; i++) {
18
- const entry = entries[i];
19
- const key = entry[0];
20
- const value = entry[1];
16
+ const keys = Object.keys(source);
17
+ for (let i = 0; i < keys.length; i++) {
18
+ const key = keys[i];
19
+ const value = source[key];
21
20
  if (predicate(value, key, source)) {
22
21
  result.push(value);
23
22
  }
@@ -10,11 +10,10 @@ function find(source, doesMatch) {
10
10
  switch (typeof doesMatch) {
11
11
  case 'function': {
12
12
  if (!Array.isArray(source)) {
13
- const entries = Object.entries(source);
14
- for (let i = 0; i < entries.length; i++) {
15
- const entry = entries[i];
16
- const key = entry[0];
17
- const value = entry[1];
13
+ const keys = Object.keys(source);
14
+ for (let i = 0; i < keys.length; i++) {
15
+ const key = keys[i];
16
+ const value = source[key];
18
17
  if (doesMatch(value, key, source)) {
19
18
  return value;
20
19
  }
@@ -46,13 +46,13 @@ export { zipWith } from '../array/zipWith.mjs';
46
46
  export { AbortError } from '../error/AbortError.mjs';
47
47
  export { TimeoutError } from '../error/TimeoutError.mjs';
48
48
  export { after } from '../function/after.mjs';
49
+ export { MemoizeCache, memoize } from '../function/memoize.mjs';
50
+ export { negate } from '../function/negate.mjs';
49
51
  export { noop } from '../function/noop.mjs';
50
52
  export { once } from '../function/once.mjs';
51
- export { negate } from '../function/negate.mjs';
52
- export { MemoizeCache, memoize } from '../function/memoize.mjs';
53
- export { unary } from '../function/unary.mjs';
54
53
  export { partial } from '../function/partial.mjs';
55
54
  export { partialRight } from '../function/partialRight.mjs';
55
+ export { unary } from '../function/unary.mjs';
56
56
  export { mean } from '../math/mean.mjs';
57
57
  export { meanBy } from '../math/meanBy.mjs';
58
58
  export { randomInt } from '../math/randomInt.mjs';
@@ -95,8 +95,8 @@ export { chunk } from './array/chunk.mjs';
95
95
  export { concat } from './array/concat.mjs';
96
96
  export { difference } from './array/difference.mjs';
97
97
  export { drop } from './array/drop.mjs';
98
- export { dropWhile } from './array/dropWhile.mjs';
99
98
  export { dropRightWhile } from './array/dropRightWhile.mjs';
99
+ export { dropWhile } from './array/dropWhile.mjs';
100
100
  export { every } from './array/every.mjs';
101
101
  export { fill } from './array/fill.mjs';
102
102
  export { filter } from './array/filter.mjs';
@@ -202,6 +202,7 @@ export { trim } from './string/trim.mjs';
202
202
  export { trimEnd } from './string/trimEnd.mjs';
203
203
  export { trimStart } from './string/trimStart.mjs';
204
204
  export { constant } from './util/constant.mjs';
205
+ export { defaultTo } from './util/defaultTo.mjs';
205
206
  export { eq } from './util/eq.mjs';
206
207
  export { times } from './util/times.mjs';
207
208
  export { toFinite } from './util/toFinite.mjs';
@@ -210,4 +211,3 @@ export { toLength } from './util/toLength.mjs';
210
211
  export { toNumber } from './util/toNumber.mjs';
211
212
  export { toPath } from './util/toPath.mjs';
212
213
  export { toString } from './util/toString.mjs';
213
- export { defaultTo } from './util/defaultTo.mjs';
@@ -46,13 +46,13 @@ export { zipWith } from '../array/zipWith.js';
46
46
  export { AbortError } from '../error/AbortError.js';
47
47
  export { TimeoutError } from '../error/TimeoutError.js';
48
48
  export { after } from '../function/after.js';
49
+ export { MemoizeCache, memoize } from '../function/memoize.js';
50
+ export { negate } from '../function/negate.js';
49
51
  export { noop } from '../function/noop.js';
50
52
  export { once } from '../function/once.js';
51
- export { negate } from '../function/negate.js';
52
- export { MemoizeCache, memoize } from '../function/memoize.js';
53
- export { unary } from '../function/unary.js';
54
53
  export { partial } from '../function/partial.js';
55
54
  export { partialRight } from '../function/partialRight.js';
55
+ export { unary } from '../function/unary.js';
56
56
  export { mean } from '../math/mean.js';
57
57
  export { meanBy } from '../math/meanBy.js';
58
58
  export { randomInt } from '../math/randomInt.js';
@@ -95,8 +95,8 @@ export { chunk } from './array/chunk.js';
95
95
  export { concat } from './array/concat.js';
96
96
  export { difference } from './array/difference.js';
97
97
  export { drop } from './array/drop.js';
98
- export { dropWhile } from './array/dropWhile.js';
99
98
  export { dropRightWhile } from './array/dropRightWhile.js';
99
+ export { dropWhile } from './array/dropWhile.js';
100
100
  export { every } from './array/every.js';
101
101
  export { fill } from './array/fill.js';
102
102
  export { filter } from './array/filter.js';
@@ -202,6 +202,7 @@ export { trim } from './string/trim.js';
202
202
  export { trimEnd } from './string/trimEnd.js';
203
203
  export { trimStart } from './string/trimStart.js';
204
204
  export { constant } from './util/constant.js';
205
+ export { defaultTo } from './util/defaultTo.js';
205
206
  export { eq } from './util/eq.js';
206
207
  export { times } from './util/times.js';
207
208
  export { toFinite } from './util/toFinite.js';
@@ -210,4 +211,3 @@ export { toLength } from './util/toLength.js';
210
211
  export { toNumber } from './util/toNumber.js';
211
212
  export { toPath } from './util/toPath.js';
212
213
  export { toString } from './util/toString.js';
213
- export { defaultTo } from './util/defaultTo.js';
@@ -4,11 +4,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
5
  const zipWith = require('../_chunk/zipWith-CV0XAX.js');
6
6
  const promise_index = require('../_chunk/index-BGZDR9.js');
7
- const flowRight$1 = require('../_chunk/flowRight-Cf9ldK.js');
7
+ const unary = require('../_chunk/unary-BZ5Ixo.js');
8
8
  const noop = require('../_chunk/noop-2IwLUk.js');
9
9
  const sumBy = require('../_chunk/sumBy-BkErWJ.js');
10
10
  const randomInt = require('../_chunk/randomInt-CF7bZK.js');
11
- const toMerged = require('../_chunk/toMerged-CkfNn9.js');
11
+ const toMerged = require('../_chunk/toMerged-DDLv0D.js');
12
12
  const isPlainObject$1 = require('../_chunk/isPlainObject-DgrsU7.js');
13
13
  const isWeakSet$1 = require('../_chunk/isWeakSet-Bd6nry.js');
14
14
  const upperFirst = require('../_chunk/upperFirst-BUECmK.js');
@@ -376,44 +376,44 @@ function matchesProperty(property, source) {
376
376
  };
377
377
  }
378
378
 
379
- function dropWhile(arr, predicate) {
379
+ function dropRightWhile(arr, predicate) {
380
380
  switch (typeof predicate) {
381
381
  case 'function': {
382
- return zipWith.dropWhile(arr, (item, index, arr) => Boolean(predicate(item, index, arr)));
382
+ return zipWith.dropRightWhile(arr, (item, index, arr) => Boolean(predicate(item, index, arr)));
383
383
  }
384
384
  case 'object': {
385
385
  if (Array.isArray(predicate) && predicate.length === 2) {
386
386
  const key = predicate[0];
387
387
  const value = predicate[1];
388
- return zipWith.dropWhile(arr, matchesProperty(key, value));
388
+ return zipWith.dropRightWhile(arr, matchesProperty(key, value));
389
389
  }
390
390
  else {
391
- return zipWith.dropWhile(arr, matches(predicate));
391
+ return zipWith.dropRightWhile(arr, matches(predicate));
392
392
  }
393
393
  }
394
394
  case 'string': {
395
- return zipWith.dropWhile(arr, property(predicate));
395
+ return zipWith.dropRightWhile(arr, property(predicate));
396
396
  }
397
397
  }
398
398
  }
399
399
 
400
- function dropRightWhile(arr, predicate) {
400
+ function dropWhile(arr, predicate) {
401
401
  switch (typeof predicate) {
402
402
  case 'function': {
403
- return zipWith.dropRightWhile(arr, (item, index, arr) => Boolean(predicate(item, index, arr)));
403
+ return zipWith.dropWhile(arr, (item, index, arr) => Boolean(predicate(item, index, arr)));
404
404
  }
405
405
  case 'object': {
406
406
  if (Array.isArray(predicate) && predicate.length === 2) {
407
407
  const key = predicate[0];
408
408
  const value = predicate[1];
409
- return zipWith.dropRightWhile(arr, matchesProperty(key, value));
409
+ return zipWith.dropWhile(arr, matchesProperty(key, value));
410
410
  }
411
411
  else {
412
- return zipWith.dropRightWhile(arr, matches(predicate));
412
+ return zipWith.dropWhile(arr, matches(predicate));
413
413
  }
414
414
  }
415
415
  case 'string': {
416
- return zipWith.dropRightWhile(arr, property(predicate));
416
+ return zipWith.dropWhile(arr, property(predicate));
417
417
  }
418
418
  }
419
419
  }
@@ -436,11 +436,10 @@ function every(source, doesMatch) {
436
436
  switch (typeof doesMatch) {
437
437
  case 'function': {
438
438
  if (!Array.isArray(source)) {
439
- const entries = Object.entries(source);
440
- for (let i = 0; i < entries.length; i++) {
441
- const entry = entries[i];
442
- const key = entry[0];
443
- const value = entry[1];
439
+ const keys = Object.keys(source);
440
+ for (let i = 0; i < keys.length; i++) {
441
+ const key = keys[i];
442
+ const value = source[key];
444
443
  if (!doesMatch(value, key, source)) {
445
444
  return false;
446
445
  }
@@ -490,11 +489,10 @@ function filter(source, predicate) {
490
489
  case 'function': {
491
490
  if (!Array.isArray(source)) {
492
491
  const result = [];
493
- const entries = Object.entries(source);
494
- for (let i = 0; i < entries.length; i++) {
495
- const entry = entries[i];
496
- const key = entry[0];
497
- const value = entry[1];
492
+ const keys = Object.keys(source);
493
+ for (let i = 0; i < keys.length; i++) {
494
+ const key = keys[i];
495
+ const value = source[key];
498
496
  if (predicate(value, key, source)) {
499
497
  result.push(value);
500
498
  }
@@ -522,11 +520,10 @@ function find(source, doesMatch) {
522
520
  switch (typeof doesMatch) {
523
521
  case 'function': {
524
522
  if (!Array.isArray(source)) {
525
- const entries = Object.entries(source);
526
- for (let i = 0; i < entries.length; i++) {
527
- const entry = entries[i];
528
- const key = entry[0];
529
- const value = entry[1];
523
+ const keys = Object.keys(source);
524
+ for (let i = 0; i < keys.length; i++) {
525
+ const key = keys[i];
526
+ const value = source[key];
530
527
  if (doesMatch(value, key, source)) {
531
528
  return value;
532
529
  }
@@ -931,7 +928,7 @@ function ary(func, n = func.length, guard) {
931
928
  if (Number.isNaN(n) || n < 0) {
932
929
  n = 0;
933
930
  }
934
- return flowRight$1.ary(func, n);
931
+ return unary.ary(func, n);
935
932
  }
936
933
 
937
934
  function attempt(func, ...args) {
@@ -1145,7 +1142,7 @@ function debounce(func, debounceMs = 0, options = {}) {
1145
1142
  }
1146
1143
  let result = undefined;
1147
1144
  let pendingAt = null;
1148
- const _debounced = flowRight$1.debounce(function (...args) {
1145
+ const _debounced = unary.debounce(function (...args) {
1149
1146
  result = func.apply(this, args);
1150
1147
  pendingAt = null;
1151
1148
  }, debounceMs, { signal, edges });
@@ -1194,7 +1191,7 @@ function flow(...funcs) {
1194
1191
  if (flattenFuncs.some(func => typeof func !== 'function')) {
1195
1192
  throw new TypeError('Expected a function');
1196
1193
  }
1197
- return flowRight$1.flow(...flattenFuncs);
1194
+ return unary.flow(...flattenFuncs);
1198
1195
  }
1199
1196
 
1200
1197
  function flowRight(...funcs) {
@@ -1202,7 +1199,7 @@ function flowRight(...funcs) {
1202
1199
  if (flattenFuncs.some(func => typeof func !== 'function')) {
1203
1200
  throw new TypeError('Expected a function');
1204
1201
  }
1205
- return flowRight$1.flowRight(...flattenFuncs);
1202
+ return unary.flowRight(...flattenFuncs);
1206
1203
  }
1207
1204
 
1208
1205
  function rearg(func, ...indices) {
@@ -1221,7 +1218,7 @@ function rest(func, start = func.length - 1) {
1221
1218
  if (Number.isNaN(start) || start < 0) {
1222
1219
  start = func.length - 1;
1223
1220
  }
1224
- return flowRight$1.rest(func, start);
1221
+ return unary.rest(func, start);
1225
1222
  }
1226
1223
 
1227
1224
  function spread(func, argsIndex = 0) {
@@ -1786,13 +1783,13 @@ function isEqualWith(a, b, areValuesEqual = noop.noop) {
1786
1783
  return isWeakSet$1.isEqualWith(a, b, (...args) => {
1787
1784
  const result = areValuesEqual(...args);
1788
1785
  if (result !== undefined) {
1789
- return !!result;
1786
+ return Boolean(result);
1790
1787
  }
1791
1788
  if (a instanceof Map && b instanceof Map) {
1792
- return isEqualWith(Array.from(a), Array.from(b), flowRight$1.after(2, areValuesEqual));
1789
+ return isEqualWith(Array.from(a), Array.from(b), unary.after(2, areValuesEqual));
1793
1790
  }
1794
1791
  if (a instanceof Set && b instanceof Set) {
1795
- return isEqualWith(Array.from(a), Array.from(b), flowRight$1.after(2, areValuesEqual));
1792
+ return isEqualWith(Array.from(a), Array.from(b), unary.after(2, areValuesEqual));
1796
1793
  }
1797
1794
  });
1798
1795
  }
@@ -1994,6 +1991,13 @@ function constant(value) {
1994
1991
  return () => value;
1995
1992
  }
1996
1993
 
1994
+ function defaultTo(value, defaultValue) {
1995
+ if (value == null || Number.isNaN(value)) {
1996
+ return defaultValue;
1997
+ }
1998
+ return value;
1999
+ }
2000
+
1997
2001
  function times(n, iteratee) {
1998
2002
  n = toInteger(n);
1999
2003
  if (n < 1 || !Number.isSafeInteger(n)) {
@@ -2016,13 +2020,6 @@ function toLength(value) {
2016
2020
  return clamp(length, 0, MAX_ARRAY_LENGTH);
2017
2021
  }
2018
2022
 
2019
- function defaultTo(value, defaultValue) {
2020
- if (value == null || Number.isNaN(value)) {
2021
- return defaultValue;
2022
- }
2023
- return value;
2024
- }
2025
-
2026
2023
  exports.at = zipWith.at;
2027
2024
  exports.compact = zipWith.compact;
2028
2025
  exports.countBy = zipWith.countBy;
@@ -2074,13 +2071,13 @@ exports.TimeoutError = promise_index.TimeoutError;
2074
2071
  exports.delay = promise_index.delay;
2075
2072
  exports.timeout = promise_index.timeout;
2076
2073
  exports.withTimeout = promise_index.withTimeout;
2077
- exports.after = flowRight$1.after;
2078
- exports.memoize = flowRight$1.memoize;
2079
- exports.negate = flowRight$1.negate;
2080
- exports.once = flowRight$1.once;
2081
- exports.partial = flowRight$1.partial;
2082
- exports.partialRight = flowRight$1.partialRight;
2083
- exports.unary = flowRight$1.unary;
2074
+ exports.after = unary.after;
2075
+ exports.memoize = unary.memoize;
2076
+ exports.negate = unary.negate;
2077
+ exports.once = unary.once;
2078
+ exports.partial = unary.partial;
2079
+ exports.partialRight = unary.partialRight;
2080
+ exports.unary = unary.unary;
2084
2081
  exports.noop = noop.noop;
2085
2082
  exports.mean = sumBy.mean;
2086
2083
  exports.meanBy = sumBy.meanBy;
@@ -46,13 +46,13 @@ export { zipWith } from '../array/zipWith.mjs';
46
46
  export { AbortError } from '../error/AbortError.mjs';
47
47
  export { TimeoutError } from '../error/TimeoutError.mjs';
48
48
  export { after } from '../function/after.mjs';
49
+ export { memoize } from '../function/memoize.mjs';
50
+ export { negate } from '../function/negate.mjs';
49
51
  export { noop } from '../function/noop.mjs';
50
52
  export { once } from '../function/once.mjs';
51
- export { negate } from '../function/negate.mjs';
52
- export { memoize } from '../function/memoize.mjs';
53
- export { unary } from '../function/unary.mjs';
54
53
  export { partial } from '../function/partial.mjs';
55
54
  export { partialRight } from '../function/partialRight.mjs';
55
+ export { unary } from '../function/unary.mjs';
56
56
  export { mean } from '../math/mean.mjs';
57
57
  export { meanBy } from '../math/meanBy.mjs';
58
58
  export { randomInt } from '../math/randomInt.mjs';
@@ -97,8 +97,8 @@ export { chunk } from './array/chunk.mjs';
97
97
  export { concat } from './array/concat.mjs';
98
98
  export { difference } from './array/difference.mjs';
99
99
  export { drop } from './array/drop.mjs';
100
- export { dropWhile } from './array/dropWhile.mjs';
101
100
  export { dropRightWhile } from './array/dropRightWhile.mjs';
101
+ export { dropWhile } from './array/dropWhile.mjs';
102
102
  export { every } from './array/every.mjs';
103
103
  export { fill } from './array/fill.mjs';
104
104
  export { filter } from './array/filter.mjs';
@@ -203,6 +203,7 @@ export { trim } from './string/trim.mjs';
203
203
  export { trimEnd } from './string/trimEnd.mjs';
204
204
  export { trimStart } from './string/trimStart.mjs';
205
205
  export { constant } from './util/constant.mjs';
206
+ export { defaultTo } from './util/defaultTo.mjs';
206
207
  export { times } from './util/times.mjs';
207
208
  export { toFinite } from './util/toFinite.mjs';
208
209
  export { toInteger } from './util/toInteger.mjs';
@@ -210,4 +211,3 @@ export { toLength } from './util/toLength.mjs';
210
211
  export { toNumber } from './util/toNumber.mjs';
211
212
  export { toPath } from './util/toPath.mjs';
212
213
  export { toString } from './util/toString.mjs';
213
- export { defaultTo } from './util/defaultTo.mjs';
@@ -9,7 +9,7 @@ function isEqualWith(a, b, areValuesEqual = noop) {
9
9
  return isEqualWith$1(a, b, (...args) => {
10
10
  const result = areValuesEqual(...args);
11
11
  if (result !== undefined) {
12
- return !!result;
12
+ return Boolean(result);
13
13
  }
14
14
  if (a instanceof Map && b instanceof Map) {
15
15
  return isEqualWith(Array.from(a), Array.from(b), after(2, areValuesEqual));
@@ -1,18 +1,18 @@
1
- export { before } from './before.mjs';
2
1
  export { after } from './after.mjs';
2
+ export { ary } from './ary.mjs';
3
+ export { before } from './before.mjs';
4
+ export { curry } from './curry.mjs';
5
+ export { curryRight } from './curryRight.mjs';
3
6
  export { debounce } from './debounce.mjs';
7
+ export { flow } from './flow.mjs';
8
+ export { flowRight } from './flowRight.mjs';
9
+ export { MemoizeCache, memoize } from './memoize.mjs';
10
+ export { negate } from './negate.mjs';
4
11
  export { noop } from './noop.mjs';
5
12
  export { once } from './once.mjs';
6
- export { throttle } from './throttle.mjs';
7
- export { negate } from './negate.mjs';
8
- export { MemoizeCache, memoize } from './memoize.mjs';
9
- export { ary } from './ary.mjs';
10
- export { unary } from './unary.mjs';
11
13
  export { partial } from './partial.mjs';
12
14
  export { partialRight } from './partialRight.mjs';
13
15
  export { rest } from './rest.mjs';
14
- export { curry } from './curry.mjs';
15
- export { curryRight } from './curryRight.mjs';
16
16
  export { spread } from './spread.mjs';
17
- export { flow } from './flow.mjs';
18
- export { flowRight } from './flowRight.mjs';
17
+ export { throttle } from './throttle.mjs';
18
+ export { unary } from './unary.mjs';
@@ -1,18 +1,18 @@
1
- export { before } from './before.js';
2
1
  export { after } from './after.js';
2
+ export { ary } from './ary.js';
3
+ export { before } from './before.js';
4
+ export { curry } from './curry.js';
5
+ export { curryRight } from './curryRight.js';
3
6
  export { debounce } from './debounce.js';
7
+ export { flow } from './flow.js';
8
+ export { flowRight } from './flowRight.js';
9
+ export { MemoizeCache, memoize } from './memoize.js';
10
+ export { negate } from './negate.js';
4
11
  export { noop } from './noop.js';
5
12
  export { once } from './once.js';
6
- export { throttle } from './throttle.js';
7
- export { negate } from './negate.js';
8
- export { MemoizeCache, memoize } from './memoize.js';
9
- export { ary } from './ary.js';
10
- export { unary } from './unary.js';
11
13
  export { partial } from './partial.js';
12
14
  export { partialRight } from './partialRight.js';
13
15
  export { rest } from './rest.js';
14
- export { curry } from './curry.js';
15
- export { curryRight } from './curryRight.js';
16
16
  export { spread } from './spread.js';
17
- export { flow } from './flow.js';
18
- export { flowRight } from './flowRight.js';
17
+ export { throttle } from './throttle.js';
18
+ export { unary } from './unary.js';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const flowRight = require('../_chunk/flowRight-Cf9ldK.js');
5
+ const unary = require('../_chunk/unary-BZ5Ixo.js');
6
6
  const noop = require('../_chunk/noop-2IwLUk.js');
7
7
 
8
8
  function before(n, func) {
@@ -18,27 +18,6 @@ function before(n, func) {
18
18
  };
19
19
  }
20
20
 
21
- function throttle(func, throttleMs, { signal, edges = ['leading', 'trailing'] } = {}) {
22
- let pendingAt = null;
23
- const debounced = flowRight.debounce(func, throttleMs, { signal, edges });
24
- const throttled = function (...args) {
25
- if (pendingAt == null) {
26
- pendingAt = Date.now();
27
- }
28
- else {
29
- if (Date.now() - pendingAt >= throttleMs) {
30
- pendingAt = Date.now();
31
- debounced.cancel();
32
- debounced(...args);
33
- }
34
- }
35
- debounced(...args);
36
- };
37
- throttled.cancel = debounced.cancel;
38
- throttled.flush = debounced.flush;
39
- return throttled;
40
- }
41
-
42
21
  function curry(func) {
43
22
  if (func.length === 0 || func.length === 1) {
44
23
  return func;
@@ -85,18 +64,39 @@ function spread(func) {
85
64
  };
86
65
  }
87
66
 
88
- exports.after = flowRight.after;
89
- exports.ary = flowRight.ary;
90
- exports.debounce = flowRight.debounce;
91
- exports.flow = flowRight.flow;
92
- exports.flowRight = flowRight.flowRight;
93
- exports.memoize = flowRight.memoize;
94
- exports.negate = flowRight.negate;
95
- exports.once = flowRight.once;
96
- exports.partial = flowRight.partial;
97
- exports.partialRight = flowRight.partialRight;
98
- exports.rest = flowRight.rest;
99
- exports.unary = flowRight.unary;
67
+ function throttle(func, throttleMs, { signal, edges = ['leading', 'trailing'] } = {}) {
68
+ let pendingAt = null;
69
+ const debounced = unary.debounce(func, throttleMs, { signal, edges });
70
+ const throttled = function (...args) {
71
+ if (pendingAt == null) {
72
+ pendingAt = Date.now();
73
+ }
74
+ else {
75
+ if (Date.now() - pendingAt >= throttleMs) {
76
+ pendingAt = Date.now();
77
+ debounced.cancel();
78
+ debounced(...args);
79
+ }
80
+ }
81
+ debounced(...args);
82
+ };
83
+ throttled.cancel = debounced.cancel;
84
+ throttled.flush = debounced.flush;
85
+ return throttled;
86
+ }
87
+
88
+ exports.after = unary.after;
89
+ exports.ary = unary.ary;
90
+ exports.debounce = unary.debounce;
91
+ exports.flow = unary.flow;
92
+ exports.flowRight = unary.flowRight;
93
+ exports.memoize = unary.memoize;
94
+ exports.negate = unary.negate;
95
+ exports.once = unary.once;
96
+ exports.partial = unary.partial;
97
+ exports.partialRight = unary.partialRight;
98
+ exports.rest = unary.rest;
99
+ exports.unary = unary.unary;
100
100
  exports.noop = noop.noop;
101
101
  exports.before = before;
102
102
  exports.curry = curry;
@@ -1,18 +1,18 @@
1
- export { before } from './before.mjs';
2
1
  export { after } from './after.mjs';
2
+ export { ary } from './ary.mjs';
3
+ export { before } from './before.mjs';
4
+ export { curry } from './curry.mjs';
5
+ export { curryRight } from './curryRight.mjs';
3
6
  export { debounce } from './debounce.mjs';
7
+ export { flow } from './flow.mjs';
8
+ export { flowRight } from './flowRight.mjs';
9
+ export { memoize } from './memoize.mjs';
10
+ export { negate } from './negate.mjs';
4
11
  export { noop } from './noop.mjs';
5
12
  export { once } from './once.mjs';
6
- export { throttle } from './throttle.mjs';
7
- export { negate } from './negate.mjs';
8
- export { memoize } from './memoize.mjs';
9
- export { ary } from './ary.mjs';
10
- export { unary } from './unary.mjs';
11
13
  export { partial } from './partial.mjs';
12
14
  export { partialRight } from './partialRight.mjs';
13
15
  export { rest } from './rest.mjs';
14
- export { curry } from './curry.mjs';
15
- export { curryRight } from './curryRight.mjs';
16
16
  export { spread } from './spread.mjs';
17
- export { flow } from './flow.mjs';
18
- export { flowRight } from './flowRight.mjs';
17
+ export { throttle } from './throttle.mjs';
18
+ export { unary } from './unary.mjs';
package/dist/index.d.mts CHANGED
@@ -56,24 +56,24 @@ export { zipObject } from './array/zipObject.mjs';
56
56
  export { zipWith } from './array/zipWith.mjs';
57
57
  export { AbortError } from './error/AbortError.mjs';
58
58
  export { TimeoutError } from './error/TimeoutError.mjs';
59
- export { before } from './function/before.mjs';
60
59
  export { after } from './function/after.mjs';
60
+ export { ary } from './function/ary.mjs';
61
+ export { before } from './function/before.mjs';
62
+ export { curry } from './function/curry.mjs';
63
+ export { curryRight } from './function/curryRight.mjs';
61
64
  export { debounce } from './function/debounce.mjs';
65
+ export { flow } from './function/flow.mjs';
66
+ export { flowRight } from './function/flowRight.mjs';
67
+ export { MemoizeCache, memoize } from './function/memoize.mjs';
68
+ export { negate } from './function/negate.mjs';
62
69
  export { noop } from './function/noop.mjs';
63
70
  export { once } from './function/once.mjs';
64
- export { throttle } from './function/throttle.mjs';
65
- export { negate } from './function/negate.mjs';
66
- export { MemoizeCache, memoize } from './function/memoize.mjs';
67
- export { ary } from './function/ary.mjs';
68
- export { unary } from './function/unary.mjs';
69
71
  export { partial } from './function/partial.mjs';
70
72
  export { partialRight } from './function/partialRight.mjs';
71
73
  export { rest } from './function/rest.mjs';
72
- export { curry } from './function/curry.mjs';
73
- export { curryRight } from './function/curryRight.mjs';
74
74
  export { spread } from './function/spread.mjs';
75
- export { flow } from './function/flow.mjs';
76
- export { flowRight } from './function/flowRight.mjs';
75
+ export { throttle } from './function/throttle.mjs';
76
+ export { unary } from './function/unary.mjs';
77
77
  export { clamp } from './math/clamp.mjs';
78
78
  export { inRange } from './math/inRange.mjs';
79
79
  export { mean } from './math/mean.mjs';
package/dist/index.d.ts CHANGED
@@ -56,24 +56,24 @@ export { zipObject } from './array/zipObject.js';
56
56
  export { zipWith } from './array/zipWith.js';
57
57
  export { AbortError } from './error/AbortError.js';
58
58
  export { TimeoutError } from './error/TimeoutError.js';
59
- export { before } from './function/before.js';
60
59
  export { after } from './function/after.js';
60
+ export { ary } from './function/ary.js';
61
+ export { before } from './function/before.js';
62
+ export { curry } from './function/curry.js';
63
+ export { curryRight } from './function/curryRight.js';
61
64
  export { debounce } from './function/debounce.js';
65
+ export { flow } from './function/flow.js';
66
+ export { flowRight } from './function/flowRight.js';
67
+ export { MemoizeCache, memoize } from './function/memoize.js';
68
+ export { negate } from './function/negate.js';
62
69
  export { noop } from './function/noop.js';
63
70
  export { once } from './function/once.js';
64
- export { throttle } from './function/throttle.js';
65
- export { negate } from './function/negate.js';
66
- export { MemoizeCache, memoize } from './function/memoize.js';
67
- export { ary } from './function/ary.js';
68
- export { unary } from './function/unary.js';
69
71
  export { partial } from './function/partial.js';
70
72
  export { partialRight } from './function/partialRight.js';
71
73
  export { rest } from './function/rest.js';
72
- export { curry } from './function/curry.js';
73
- export { curryRight } from './function/curryRight.js';
74
74
  export { spread } from './function/spread.js';
75
- export { flow } from './function/flow.js';
76
- export { flowRight } from './function/flowRight.js';
75
+ export { throttle } from './function/throttle.js';
76
+ export { unary } from './function/unary.js';
77
77
  export { clamp } from './math/clamp.js';
78
78
  export { inRange } from './math/inRange.js';
79
79
  export { mean } from './math/mean.js';