@vinicunca/perkakas 1.1.0 → 1.2.2
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/add.d.cts +0 -1
- package/dist/add.d.ts +0 -1
- package/dist/chunk-6YAVWI3X.cjs +1 -0
- package/dist/chunk-AWXJSK4F.js +1 -0
- package/dist/chunk-C3NLWEGJ.js +1 -0
- package/dist/{chunk-TW3AOKT4.js → chunk-CUCNZMQN.js} +1 -1
- package/dist/{chunk-3TLR3L2W.cjs → chunk-EGUKWDAK.cjs} +1 -1
- package/dist/chunk-ETVIOWIV.js +1 -0
- package/dist/chunk-GOUUMCT7.cjs +1 -0
- package/dist/chunk-I2Z6A55T.js +1 -0
- package/dist/chunk-SJMGQLYS.cjs +1 -0
- package/dist/{chunk-WP5D3YAQ.cjs → chunk-YNCQNUT4.cjs} +1 -1
- package/dist/chunk.cjs +1 -1
- package/dist/chunk.d.cts +1 -4
- package/dist/chunk.d.ts +1 -4
- package/dist/chunk.js +1 -1
- package/dist/count-by.cjs +1 -0
- package/dist/count-by.d.cts +41 -0
- package/dist/count-by.d.ts +41 -0
- package/dist/count-by.js +1 -0
- package/dist/funnel.cjs +1 -0
- package/dist/funnel.d.cts +147 -0
- package/dist/funnel.d.ts +147 -0
- package/dist/funnel.js +1 -0
- package/dist/funnel.lodash-debounce-with-cached-value.test.cjs +1 -0
- package/dist/funnel.lodash-debounce-with-cached-value.test.d.cts +2 -0
- package/dist/funnel.lodash-debounce-with-cached-value.test.d.ts +2 -0
- package/dist/funnel.lodash-debounce-with-cached-value.test.js +1 -0
- package/dist/funnel.lodash-debounce.test.cjs +1 -0
- package/dist/funnel.lodash-debounce.test.d.cts +2 -0
- package/dist/funnel.lodash-debounce.test.d.ts +2 -0
- package/dist/funnel.lodash-debounce.test.js +1 -0
- package/dist/funnel.lodash-throttle-with-cached-value.test.cjs +1 -0
- package/dist/funnel.lodash-throttle-with-cached-value.test.d.cts +2 -0
- package/dist/funnel.lodash-throttle-with-cached-value.test.d.ts +2 -0
- package/dist/funnel.lodash-throttle-with-cached-value.test.js +1 -0
- package/dist/funnel.lodash-throttle.test.cjs +1 -0
- package/dist/funnel.lodash-throttle.test.d.cts +2 -0
- package/dist/funnel.lodash-throttle.test.d.ts +2 -0
- package/dist/funnel.lodash-throttle.test.js +1 -0
- package/dist/funnel.reference-batch.test.cjs +1 -0
- package/dist/funnel.reference-batch.test.d.cts +2 -0
- package/dist/funnel.reference-batch.test.d.ts +2 -0
- package/dist/funnel.reference-batch.test.js +1 -0
- package/dist/funnel.remeda-debounce.test.cjs +1 -0
- package/dist/funnel.remeda-debounce.test.d.cts +2 -0
- package/dist/funnel.remeda-debounce.test.d.ts +2 -0
- package/dist/funnel.remeda-debounce.test.js +1 -0
- package/dist/funnel.test-d.cjs +1 -0
- package/dist/funnel.test-d.d.cts +2 -0
- package/dist/funnel.test-d.d.ts +2 -0
- package/dist/funnel.test-d.js +1 -0
- package/dist/funnel.test.cjs +1 -0
- package/dist/funnel.test.d.cts +2 -0
- package/dist/funnel.test.d.ts +2 -0
- package/dist/funnel.test.js +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +1 -1
- package/dist/int-range-inclusive-Cn-qsrAN.d.cts +12 -0
- package/dist/int-range-inclusive-Cn-qsrAN.d.ts +12 -0
- package/dist/prop.cjs +1 -1
- package/dist/prop.d.cts +1 -0
- package/dist/prop.d.ts +1 -0
- package/dist/prop.js +1 -1
- package/dist/random-integer.cjs +1 -1
- package/dist/random-integer.d.cts +3 -2
- package/dist/random-integer.d.ts +3 -2
- package/dist/random-integer.js +1 -1
- package/dist/swap-indices.d.cts +1 -1
- package/dist/swap-indices.d.ts +1 -1
- package/package.json +9 -9
- package/dist/chunk-HE3Z4UIX.js +0 -1
- package/dist/chunk-IOSBDH5J.cjs +0 -1
- package/dist/chunk-QT66COHU.js +0 -1
package/dist/add.d.cts
CHANGED
package/dist/add.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk4MAOF3ZPcjs = require('./chunk-4MAOF3ZP.cjs');function c(...e){return _chunk4MAOF3ZPcjs.a.call(void 0, d,e)}function d(e,o){let n={};for(let[a,y]of e.entries()){let r=o(y,a,e);r!==void 0&&(n[r]??=0,n[r]+=1)}return n}exports.a = c;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function T(c,{triggerAt:l="end",minQuietPeriodMs:u,maxBurstDurationMs:t,minGapMs:o,reducer:p=g}){let e,n,d,r;function a(){let i=d;i!==void 0&&(d=void 0,c(i),o!==void 0&&(n=setTimeout(f,o)))}function f(){clearTimeout(n),n=void 0,e===void 0&&a()}function m(){clearTimeout(e),e=void 0,r=void 0,n===void 0&&a()}return{call:(...i)=>{let s=e===void 0&&n===void 0;if((l!=="start"||s)&&(d=p(d,...i)),!(e===void 0&&!s)){if(u!==void 0||t!==void 0||o===void 0){clearTimeout(e);let y=Date.now();r??=y;let R=t===void 0?u??0:Math.min(u??t,t-(y-r));e=setTimeout(m,R)}l!=="end"&&s&&a()}},cancel:()=>{clearTimeout(e),e=void 0,r=void 0,clearTimeout(n),n=void 0,d=void 0},flush:()=>{m(),f()},get isIdle(){return e===void 0&&n===void 0}}}var g=()=>"";export{T as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as t}from"./chunk-ENYMRDJU.js";function c(...e){return t(d,e)}function d(e,o){let n={};for(let[a,y]of e.entries()){let r=o(y,a,e);r!==void 0&&(n[r]??=0,n[r]+=1)}return n}export{c as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-ENYMRDJU.js";function
|
|
1
|
+
import{a}from"./chunk-ENYMRDJU.js";function l(...e){return a(s,e)}function s(e,n){if(n<1)throw new RangeError(`chunk: A chunk size of '${n}' would result in an infinite array`);if(e.length===0)return[];if(n>=e.length)return[[...e]];let i=Math.ceil(e.length/n),u=new Array(i);if(n===1)for(let[r,t]of e.entries())u[r]=[t];else for(let r=0;r<i;r+=1){let t=r*n;u[r]=e.slice(t,t+n)}return u}export{l as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk4MAOF3ZPcjs = require('./chunk-4MAOF3ZP.cjs');function
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk4MAOF3ZPcjs = require('./chunk-4MAOF3ZP.cjs');function l(...e){return _chunk4MAOF3ZPcjs.a.call(void 0, s,e)}function s(e,n){if(n<1)throw new RangeError(`chunk: A chunk size of '${n}' would result in an infinite array`);if(e.length===0)return[];if(n>=e.length)return[[...e]];let i=Math.ceil(e.length/n),u=new Array(i);if(n===1)for(let[r,t]of e.entries())u[r]=[t];else for(let r=0;r<i;r+=1){let t=r*n;u[r]=e.slice(t,t+n)}return u}exports.a = l;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as n}from"./chunk-ENYMRDJU.js";function p(...e){return n(t,e)}function t(e,o){return e[o]}export{p as a,t as b};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }function T(c,{triggerAt:l="end",minQuietPeriodMs:u,maxBurstDurationMs:t,minGapMs:o,reducer:p=g}){let e,n,d,r;function a(){let i=d;i!==void 0&&(d=void 0,c(i),o!==void 0&&(n=setTimeout(f,o)))}function f(){clearTimeout(n),n=void 0,e===void 0&&a()}function m(){clearTimeout(e),e=void 0,r=void 0,n===void 0&&a()}return{call:(...i)=>{let s=e===void 0&&n===void 0;if((l!=="start"||s)&&(d=p(d,...i)),!(e===void 0&&!s)){if(u!==void 0||t!==void 0||o===void 0){clearTimeout(e);let y=Date.now();r??=y;let R=t===void 0?_nullishCoalesce(u, () => (0)):Math.min(_nullishCoalesce(u, () => (t)),t-(y-r));e=setTimeout(m,R)}l!=="end"&&s&&a()}},cancel:()=>{clearTimeout(e),e=void 0,r=void 0,clearTimeout(n),n=void 0,d=void 0},flush:()=>{m(),f()},get isIdle(){return e===void 0&&n===void 0}}}var g=()=>"";exports.a = T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function o(r,n){let e=Math.ceil(r),t=Math.floor(n);if(t<e)throw new RangeError(`randomInt: The range [${r},${n}] contains no integer`);return Math.floor(Math.random()*(t-e+1)+e)}export{o as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});function o(r,n){let e=Math.ceil(r),t=Math.floor(n);if(t<e)throw new RangeError(`randomInt: The range [${r},${n}] contains no integer`);return Math.floor(Math.random()*(t-e+1)+e)}exports.a = o;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk4MAOF3ZPcjs = require('./chunk-4MAOF3ZP.cjs');function p(...
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk4MAOF3ZPcjs = require('./chunk-4MAOF3ZP.cjs');function p(...e){return _chunk4MAOF3ZPcjs.a.call(void 0, t,e)}function t(e,o){return e[o]}exports.a = p; exports.b = t;
|
package/dist/chunk.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkEGUKWDAKcjs = require('./chunk-EGUKWDAK.cjs');require('./chunk-4MAOF3ZP.cjs');require('./chunk-4YUDBZFA.cjs');exports.chunk = _chunkEGUKWDAKcjs.a;
|
package/dist/chunk.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IsNumericLiteral, LessThan, IfNever, Subtract, ValueOf, IntRange } from 'type-fest';
|
|
2
|
+
import { I as IntRangeInclusive } from './int-range-inclusive-Cn-qsrAN.cjs';
|
|
2
3
|
import { I as IterableContainer } from './iterable-container-BTpDVdNc.cjs';
|
|
3
4
|
import { T as TupleParts, N as NTuple } from './tuple-parts-DcH94smG.cjs';
|
|
4
5
|
import { N as NonEmptyArray } from './non-empty-array-C9Od1wmF.cjs';
|
|
@@ -86,10 +87,6 @@ type SuffixChunk<T extends Array<unknown>, Item, N extends number> = T extends r
|
|
|
86
87
|
* our output based on if we know for sure that the array is empty or not.
|
|
87
88
|
*/
|
|
88
89
|
type GenericChunk<T extends IterableContainer> = T extends readonly [...Array<unknown>, unknown] | readonly [unknown, ...Array<unknown>] ? NonEmptyArray<NonEmptyArray<T[number]>> : Array<NonEmptyArray<T[number]>>;
|
|
89
|
-
/**
|
|
90
|
-
* Type-fest's IntRange doesn't include the `To` value, but we need it!
|
|
91
|
-
*/
|
|
92
|
-
type IntRangeInclusive<From extends number, To extends number> = IntRange<From, To> | To;
|
|
93
90
|
/**
|
|
94
91
|
* Split an array into groups the length of `size`. If `array` can't be split evenly, the final chunk will be the remaining elements.
|
|
95
92
|
*
|
package/dist/chunk.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IsNumericLiteral, LessThan, IfNever, Subtract, ValueOf, IntRange } from 'type-fest';
|
|
2
|
+
import { I as IntRangeInclusive } from './int-range-inclusive-Cn-qsrAN.js';
|
|
2
3
|
import { I as IterableContainer } from './iterable-container-BTpDVdNc.js';
|
|
3
4
|
import { T as TupleParts, N as NTuple } from './tuple-parts-DcH94smG.js';
|
|
4
5
|
import { N as NonEmptyArray } from './non-empty-array-C9Od1wmF.js';
|
|
@@ -86,10 +87,6 @@ type SuffixChunk<T extends Array<unknown>, Item, N extends number> = T extends r
|
|
|
86
87
|
* our output based on if we know for sure that the array is empty or not.
|
|
87
88
|
*/
|
|
88
89
|
type GenericChunk<T extends IterableContainer> = T extends readonly [...Array<unknown>, unknown] | readonly [unknown, ...Array<unknown>] ? NonEmptyArray<NonEmptyArray<T[number]>> : Array<NonEmptyArray<T[number]>>;
|
|
89
|
-
/**
|
|
90
|
-
* Type-fest's IntRange doesn't include the `To` value, but we need it!
|
|
91
|
-
*/
|
|
92
|
-
type IntRangeInclusive<From extends number, To extends number> = IntRange<From, To> | To;
|
|
93
90
|
/**
|
|
94
91
|
* Split an array into groups the length of `size`. If `array` can't be split evenly, the final chunk will be the remaining elements.
|
|
95
92
|
*
|
package/dist/chunk.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-CUCNZMQN.js";import"./chunk-ENYMRDJU.js";import"./chunk-K2EX7PYH.js";export{a as chunk};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk6YAVWI3Xcjs = require('./chunk-6YAVWI3X.cjs');require('./chunk-4MAOF3ZP.cjs');require('./chunk-4YUDBZFA.cjs');exports.countBy = _chunk6YAVWI3Xcjs.a;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { E as ExactRecord } from './exact-record-h-jwajoM.cjs';
|
|
2
|
+
import './if-bounded-record-DVYSMNKL.cjs';
|
|
3
|
+
import 'type-fest';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Categorize and count elements in an array using a defined callback function.
|
|
7
|
+
* The callback function is applied to each element in the array to determine
|
|
8
|
+
* its category and then counts how many elements fall into each category.
|
|
9
|
+
*
|
|
10
|
+
* @param data - The array.
|
|
11
|
+
* @param categorizationFn - The categorization function.
|
|
12
|
+
* @signature
|
|
13
|
+
* P.countBy(data, categorizationFn)
|
|
14
|
+
* @example
|
|
15
|
+
* P.countBy(
|
|
16
|
+
* ["a", "b", "c", "B", "A", "a"],
|
|
17
|
+
* toLowerCase
|
|
18
|
+
* ); //=> { a: 3, b: 2, c: 1 }
|
|
19
|
+
* @dataFirst
|
|
20
|
+
* @category Array
|
|
21
|
+
*/
|
|
22
|
+
declare function countBy<T, K extends PropertyKey>(data: ReadonlyArray<T>, categorizationFn: (value: T, index: number, data: ReadonlyArray<T>) => K | undefined): ExactRecord<K, number>;
|
|
23
|
+
/**
|
|
24
|
+
* Categorize and count elements in an array using a defined callback function.
|
|
25
|
+
* The callback function is applied to each element in the array to determine
|
|
26
|
+
* its category and then counts how many elements fall into each category.
|
|
27
|
+
*
|
|
28
|
+
* @param categorizationFn - The categorization function.
|
|
29
|
+
* @signature
|
|
30
|
+
* P.countBy(categorizationFn)(data)
|
|
31
|
+
* @example
|
|
32
|
+
* P.pipe(
|
|
33
|
+
* ["a", "b", "c", "B", "A", "a"],
|
|
34
|
+
* P.countBy(toLowerCase),
|
|
35
|
+
* ); //=> { a: 3, b: 2, c: 1 }
|
|
36
|
+
* @dataLast
|
|
37
|
+
* @category Array
|
|
38
|
+
*/
|
|
39
|
+
declare function countBy<T, K extends PropertyKey>(categorizationFn: (value: T, index: number, data: ReadonlyArray<T>) => K | undefined): (data: ReadonlyArray<T>) => ExactRecord<K, number>;
|
|
40
|
+
|
|
41
|
+
export { countBy };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { E as ExactRecord } from './exact-record-Bf4LoPyZ.js';
|
|
2
|
+
import './if-bounded-record-DVYSMNKL.js';
|
|
3
|
+
import 'type-fest';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Categorize and count elements in an array using a defined callback function.
|
|
7
|
+
* The callback function is applied to each element in the array to determine
|
|
8
|
+
* its category and then counts how many elements fall into each category.
|
|
9
|
+
*
|
|
10
|
+
* @param data - The array.
|
|
11
|
+
* @param categorizationFn - The categorization function.
|
|
12
|
+
* @signature
|
|
13
|
+
* P.countBy(data, categorizationFn)
|
|
14
|
+
* @example
|
|
15
|
+
* P.countBy(
|
|
16
|
+
* ["a", "b", "c", "B", "A", "a"],
|
|
17
|
+
* toLowerCase
|
|
18
|
+
* ); //=> { a: 3, b: 2, c: 1 }
|
|
19
|
+
* @dataFirst
|
|
20
|
+
* @category Array
|
|
21
|
+
*/
|
|
22
|
+
declare function countBy<T, K extends PropertyKey>(data: ReadonlyArray<T>, categorizationFn: (value: T, index: number, data: ReadonlyArray<T>) => K | undefined): ExactRecord<K, number>;
|
|
23
|
+
/**
|
|
24
|
+
* Categorize and count elements in an array using a defined callback function.
|
|
25
|
+
* The callback function is applied to each element in the array to determine
|
|
26
|
+
* its category and then counts how many elements fall into each category.
|
|
27
|
+
*
|
|
28
|
+
* @param categorizationFn - The categorization function.
|
|
29
|
+
* @signature
|
|
30
|
+
* P.countBy(categorizationFn)(data)
|
|
31
|
+
* @example
|
|
32
|
+
* P.pipe(
|
|
33
|
+
* ["a", "b", "c", "B", "A", "a"],
|
|
34
|
+
* P.countBy(toLowerCase),
|
|
35
|
+
* ); //=> { a: 3, b: 2, c: 1 }
|
|
36
|
+
* @dataLast
|
|
37
|
+
* @category Array
|
|
38
|
+
*/
|
|
39
|
+
declare function countBy<T, K extends PropertyKey>(categorizationFn: (value: T, index: number, data: ReadonlyArray<T>) => K | undefined): (data: ReadonlyArray<T>) => ExactRecord<K, number>;
|
|
40
|
+
|
|
41
|
+
export { countBy };
|
package/dist/count-by.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"./chunk-C3NLWEGJ.js";import"./chunk-ENYMRDJU.js";import"./chunk-K2EX7PYH.js";export{a as countBy};
|
package/dist/funnel.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkGOUUMCT7cjs = require('./chunk-GOUUMCT7.cjs');exports.funnel = _chunkGOUUMCT7cjs.a;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { RequireAtLeastOne } from 'type-fest';
|
|
2
|
+
|
|
3
|
+
type FunnelOptions<Args extends RestArguments, R> = {
|
|
4
|
+
readonly reducer?: (accumulator: R | undefined, ...params: Args) => R;
|
|
5
|
+
} & FunnelTimingOptions;
|
|
6
|
+
/**
|
|
7
|
+
* Not all combinations of timing options are valid, there are dependencies
|
|
8
|
+
* between them to ensure users can't configure the funnel in a way which would
|
|
9
|
+
* cause it to never trigger.
|
|
10
|
+
*/
|
|
11
|
+
type FunnelTimingOptions = {
|
|
12
|
+
readonly triggerAt: 'both' | 'start';
|
|
13
|
+
readonly minQuietPeriodMs?: number;
|
|
14
|
+
readonly maxBurstDurationMs?: number;
|
|
15
|
+
readonly minGapMs?: number;
|
|
16
|
+
} | ({
|
|
17
|
+
readonly triggerAt?: 'end';
|
|
18
|
+
} & (({
|
|
19
|
+
readonly minGapMs: number;
|
|
20
|
+
} & RequireAtLeastOne<{
|
|
21
|
+
readonly minQuietPeriodMs: number;
|
|
22
|
+
readonly maxBurstDurationMs: number;
|
|
23
|
+
}>) | {
|
|
24
|
+
readonly minQuietPeriodMs?: number;
|
|
25
|
+
readonly maxBurstDurationMs?: number;
|
|
26
|
+
readonly minGapMs?: never;
|
|
27
|
+
}));
|
|
28
|
+
type RestArguments = Array<any>;
|
|
29
|
+
interface Funnel<Args extends RestArguments = []> {
|
|
30
|
+
/**
|
|
31
|
+
* Call the function. This might result in the `execute` function being called
|
|
32
|
+
* now or later, depending on it's configuration and it's current state.
|
|
33
|
+
*
|
|
34
|
+
* @param args - The args are defined by the `reducer` function.
|
|
35
|
+
*/
|
|
36
|
+
readonly call: (...args: Args) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Resets the funnel to it's initial state. Any calls made since the last
|
|
39
|
+
* invocation will be discarded.
|
|
40
|
+
*/
|
|
41
|
+
readonly cancel: () => void;
|
|
42
|
+
/**
|
|
43
|
+
* Triggers an invocation regardless of the current state of the funnel.
|
|
44
|
+
* Like any other invocation, The funnel will also be reset to it's initial
|
|
45
|
+
* state afterwards.
|
|
46
|
+
*/
|
|
47
|
+
readonly flush: () => void;
|
|
48
|
+
/**
|
|
49
|
+
* The funnel is in it's initial state (there are no active timeouts).
|
|
50
|
+
*/
|
|
51
|
+
readonly isIdle: boolean;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Creates a funnel that controls the timing and execution of `callback`. Its
|
|
55
|
+
* main purpose is to manage multiple consecutive (usually fast-paced) calls,
|
|
56
|
+
* reshaping them according to a defined batching strategy and timing policy.
|
|
57
|
+
* This is useful when handling uncontrolled call rates, such as DOM events or
|
|
58
|
+
* network traffic. It can implement strategies like debouncing, throttling,
|
|
59
|
+
* batching, and more.
|
|
60
|
+
*
|
|
61
|
+
* An optional `reducer` function can be provided to allow passing data to the
|
|
62
|
+
* callback via calls to `call` (otherwise the signature of `call` takes no
|
|
63
|
+
* arguments).
|
|
64
|
+
*
|
|
65
|
+
* Typing is inferred from `callback`s param, and from the rest params that
|
|
66
|
+
* the optional `reducer` function accepts. Use **explicit** types for these
|
|
67
|
+
* to ensure that everything _else_ is well-typed.
|
|
68
|
+
*
|
|
69
|
+
* Notice that this function constructs a funnel **object**, and does **not**
|
|
70
|
+
* execute anything when called. The returned object should be used to execute
|
|
71
|
+
* the funnel via the its `call` method.
|
|
72
|
+
*
|
|
73
|
+
* - Debouncing: use `minQuietPeriodMs` and any `triggerAt`.
|
|
74
|
+
* - Throttling: use `minGapMs` and `triggerAt: "start"` or `"both"`.
|
|
75
|
+
* - Batching: See the reference implementation in [`funnel.reference-batch.test.ts`](https://github.com/vinicunca/perkakas/blob/main/src/funnel.reference-batch.test.ts).
|
|
76
|
+
*
|
|
77
|
+
* @param callback - The main function that would be invoked periodically based
|
|
78
|
+
* on `options`. The function would take the latest result of the `reducer`; if
|
|
79
|
+
* no calls where made since the last time it was invoked it will not be
|
|
80
|
+
* invoked. (If a return value is needed, it should be passed via a reference or
|
|
81
|
+
* via closure to the outer scope of the funnel).
|
|
82
|
+
* @param options - An object that defines when `execute` should be invoked,
|
|
83
|
+
* relative to the calls of `call`. An empty/missing options object is
|
|
84
|
+
* equivalent to setting `minQuietPeriodMs` to `0`.
|
|
85
|
+
* @param options.reducer - Combines the arguments passed to `call` with the
|
|
86
|
+
* value computed on the previous call (or `undefined` on the first time). The
|
|
87
|
+
* goal of the function is to extract and summarize the data needed for
|
|
88
|
+
* `callback`. It should be fast and simple as it is called often and should
|
|
89
|
+
* defer heavy operations to the `execute` function. If the final value
|
|
90
|
+
* is `undefined`, `callback` will not be called.
|
|
91
|
+
* @param options.triggerAt - At what "edges" of the funnel's burst window
|
|
92
|
+
* would `execute` invoke:
|
|
93
|
+
* - `start` - the function will be invoked immediately (within the **same**
|
|
94
|
+
* execution frame!), and any subsequent calls would be ignored until the funnel
|
|
95
|
+
* is idle again. During this period `reducer` will also not be called.
|
|
96
|
+
* - `end` - the function will **not** be invoked initially but the timer will
|
|
97
|
+
* be started. Any calls during this time would be passed to the reducer, and
|
|
98
|
+
* when the timers are done, the reduced result would trigger an invocation.
|
|
99
|
+
* - `both` - the function will be invoked immediately, and then the funnel
|
|
100
|
+
* would behave as if it was in the 'end' state. @default 'end'.
|
|
101
|
+
* @param options.minQuietPeriodMs - The burst timer prevents subsequent calls
|
|
102
|
+
* in short succession to cause excessive invocations (aka "debounce"). This
|
|
103
|
+
* duration represents the **minimum** amount of time that needs to pass
|
|
104
|
+
* between calls (the "quiet" part) in order for the subsequent call to **not**
|
|
105
|
+
* be considered part of the burst. In other words, as long as calls are faster
|
|
106
|
+
* than this, they are considered part of the burst and the burst is extended.
|
|
107
|
+
* @param options.maxBurstDurationMs - Bursts are extended every time a call is
|
|
108
|
+
* made within the burst period. This means that the burst period could be
|
|
109
|
+
* extended indefinitely. To prevent such cases, a maximum burst duration could
|
|
110
|
+
* be defined. When `minQuietPeriodMs` is not defined and this option is, they
|
|
111
|
+
* will both share the same value.
|
|
112
|
+
* @param options.minGapMs - A minimum duration between calls of `execute`.
|
|
113
|
+
* This is maintained regardless of the shape of the burst and is ensured even
|
|
114
|
+
* if the `maxBurstDurationMs` is reached before it. (aka "throttle").
|
|
115
|
+
* @returns A funnel with a `call` function that is used to trigger invocations.
|
|
116
|
+
* In addition to it the funnel also comes with the following functions and
|
|
117
|
+
* properties:
|
|
118
|
+
* - `cancel` - Resets the funnel to it's initial state, discarding the current
|
|
119
|
+
* `reducer` result without calling `execute` on it.
|
|
120
|
+
* - `flush` - Triggers an invocation even if there are active timeouts, and
|
|
121
|
+
* then resets the funnel to it's initial state.
|
|
122
|
+
* - `isIdle` - Checks if there are any active timeouts.
|
|
123
|
+
* @signature
|
|
124
|
+
* P.funnel(callback, options);
|
|
125
|
+
* @example
|
|
126
|
+
* const debouncer = P.funnel(
|
|
127
|
+
* () => {
|
|
128
|
+
* console.log("Callback executed!");
|
|
129
|
+
* },
|
|
130
|
+
* { minQuietPeriodMs: 100 },
|
|
131
|
+
* );
|
|
132
|
+
* debouncer.call();
|
|
133
|
+
* debouncer.call();
|
|
134
|
+
*
|
|
135
|
+
* const throttle = P.funnel(
|
|
136
|
+
* () => {
|
|
137
|
+
* console.log("Callback executed!");
|
|
138
|
+
* },
|
|
139
|
+
* { minGapMs: 100, triggerAt: "start" },
|
|
140
|
+
* );
|
|
141
|
+
* throttle.call();
|
|
142
|
+
* throttle.call();
|
|
143
|
+
* @category Function
|
|
144
|
+
*/
|
|
145
|
+
declare function funnel<Args extends RestArguments = [], R = never>(callback: (data: R) => void, { triggerAt, minQuietPeriodMs, maxBurstDurationMs, minGapMs, reducer, }: FunnelOptions<Args, R>): Funnel<Args>;
|
|
146
|
+
|
|
147
|
+
export { funnel };
|
package/dist/funnel.d.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { RequireAtLeastOne } from 'type-fest';
|
|
2
|
+
|
|
3
|
+
type FunnelOptions<Args extends RestArguments, R> = {
|
|
4
|
+
readonly reducer?: (accumulator: R | undefined, ...params: Args) => R;
|
|
5
|
+
} & FunnelTimingOptions;
|
|
6
|
+
/**
|
|
7
|
+
* Not all combinations of timing options are valid, there are dependencies
|
|
8
|
+
* between them to ensure users can't configure the funnel in a way which would
|
|
9
|
+
* cause it to never trigger.
|
|
10
|
+
*/
|
|
11
|
+
type FunnelTimingOptions = {
|
|
12
|
+
readonly triggerAt: 'both' | 'start';
|
|
13
|
+
readonly minQuietPeriodMs?: number;
|
|
14
|
+
readonly maxBurstDurationMs?: number;
|
|
15
|
+
readonly minGapMs?: number;
|
|
16
|
+
} | ({
|
|
17
|
+
readonly triggerAt?: 'end';
|
|
18
|
+
} & (({
|
|
19
|
+
readonly minGapMs: number;
|
|
20
|
+
} & RequireAtLeastOne<{
|
|
21
|
+
readonly minQuietPeriodMs: number;
|
|
22
|
+
readonly maxBurstDurationMs: number;
|
|
23
|
+
}>) | {
|
|
24
|
+
readonly minQuietPeriodMs?: number;
|
|
25
|
+
readonly maxBurstDurationMs?: number;
|
|
26
|
+
readonly minGapMs?: never;
|
|
27
|
+
}));
|
|
28
|
+
type RestArguments = Array<any>;
|
|
29
|
+
interface Funnel<Args extends RestArguments = []> {
|
|
30
|
+
/**
|
|
31
|
+
* Call the function. This might result in the `execute` function being called
|
|
32
|
+
* now or later, depending on it's configuration and it's current state.
|
|
33
|
+
*
|
|
34
|
+
* @param args - The args are defined by the `reducer` function.
|
|
35
|
+
*/
|
|
36
|
+
readonly call: (...args: Args) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Resets the funnel to it's initial state. Any calls made since the last
|
|
39
|
+
* invocation will be discarded.
|
|
40
|
+
*/
|
|
41
|
+
readonly cancel: () => void;
|
|
42
|
+
/**
|
|
43
|
+
* Triggers an invocation regardless of the current state of the funnel.
|
|
44
|
+
* Like any other invocation, The funnel will also be reset to it's initial
|
|
45
|
+
* state afterwards.
|
|
46
|
+
*/
|
|
47
|
+
readonly flush: () => void;
|
|
48
|
+
/**
|
|
49
|
+
* The funnel is in it's initial state (there are no active timeouts).
|
|
50
|
+
*/
|
|
51
|
+
readonly isIdle: boolean;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Creates a funnel that controls the timing and execution of `callback`. Its
|
|
55
|
+
* main purpose is to manage multiple consecutive (usually fast-paced) calls,
|
|
56
|
+
* reshaping them according to a defined batching strategy and timing policy.
|
|
57
|
+
* This is useful when handling uncontrolled call rates, such as DOM events or
|
|
58
|
+
* network traffic. It can implement strategies like debouncing, throttling,
|
|
59
|
+
* batching, and more.
|
|
60
|
+
*
|
|
61
|
+
* An optional `reducer` function can be provided to allow passing data to the
|
|
62
|
+
* callback via calls to `call` (otherwise the signature of `call` takes no
|
|
63
|
+
* arguments).
|
|
64
|
+
*
|
|
65
|
+
* Typing is inferred from `callback`s param, and from the rest params that
|
|
66
|
+
* the optional `reducer` function accepts. Use **explicit** types for these
|
|
67
|
+
* to ensure that everything _else_ is well-typed.
|
|
68
|
+
*
|
|
69
|
+
* Notice that this function constructs a funnel **object**, and does **not**
|
|
70
|
+
* execute anything when called. The returned object should be used to execute
|
|
71
|
+
* the funnel via the its `call` method.
|
|
72
|
+
*
|
|
73
|
+
* - Debouncing: use `minQuietPeriodMs` and any `triggerAt`.
|
|
74
|
+
* - Throttling: use `minGapMs` and `triggerAt: "start"` or `"both"`.
|
|
75
|
+
* - Batching: See the reference implementation in [`funnel.reference-batch.test.ts`](https://github.com/vinicunca/perkakas/blob/main/src/funnel.reference-batch.test.ts).
|
|
76
|
+
*
|
|
77
|
+
* @param callback - The main function that would be invoked periodically based
|
|
78
|
+
* on `options`. The function would take the latest result of the `reducer`; if
|
|
79
|
+
* no calls where made since the last time it was invoked it will not be
|
|
80
|
+
* invoked. (If a return value is needed, it should be passed via a reference or
|
|
81
|
+
* via closure to the outer scope of the funnel).
|
|
82
|
+
* @param options - An object that defines when `execute` should be invoked,
|
|
83
|
+
* relative to the calls of `call`. An empty/missing options object is
|
|
84
|
+
* equivalent to setting `minQuietPeriodMs` to `0`.
|
|
85
|
+
* @param options.reducer - Combines the arguments passed to `call` with the
|
|
86
|
+
* value computed on the previous call (or `undefined` on the first time). The
|
|
87
|
+
* goal of the function is to extract and summarize the data needed for
|
|
88
|
+
* `callback`. It should be fast and simple as it is called often and should
|
|
89
|
+
* defer heavy operations to the `execute` function. If the final value
|
|
90
|
+
* is `undefined`, `callback` will not be called.
|
|
91
|
+
* @param options.triggerAt - At what "edges" of the funnel's burst window
|
|
92
|
+
* would `execute` invoke:
|
|
93
|
+
* - `start` - the function will be invoked immediately (within the **same**
|
|
94
|
+
* execution frame!), and any subsequent calls would be ignored until the funnel
|
|
95
|
+
* is idle again. During this period `reducer` will also not be called.
|
|
96
|
+
* - `end` - the function will **not** be invoked initially but the timer will
|
|
97
|
+
* be started. Any calls during this time would be passed to the reducer, and
|
|
98
|
+
* when the timers are done, the reduced result would trigger an invocation.
|
|
99
|
+
* - `both` - the function will be invoked immediately, and then the funnel
|
|
100
|
+
* would behave as if it was in the 'end' state. @default 'end'.
|
|
101
|
+
* @param options.minQuietPeriodMs - The burst timer prevents subsequent calls
|
|
102
|
+
* in short succession to cause excessive invocations (aka "debounce"). This
|
|
103
|
+
* duration represents the **minimum** amount of time that needs to pass
|
|
104
|
+
* between calls (the "quiet" part) in order for the subsequent call to **not**
|
|
105
|
+
* be considered part of the burst. In other words, as long as calls are faster
|
|
106
|
+
* than this, they are considered part of the burst and the burst is extended.
|
|
107
|
+
* @param options.maxBurstDurationMs - Bursts are extended every time a call is
|
|
108
|
+
* made within the burst period. This means that the burst period could be
|
|
109
|
+
* extended indefinitely. To prevent such cases, a maximum burst duration could
|
|
110
|
+
* be defined. When `minQuietPeriodMs` is not defined and this option is, they
|
|
111
|
+
* will both share the same value.
|
|
112
|
+
* @param options.minGapMs - A minimum duration between calls of `execute`.
|
|
113
|
+
* This is maintained regardless of the shape of the burst and is ensured even
|
|
114
|
+
* if the `maxBurstDurationMs` is reached before it. (aka "throttle").
|
|
115
|
+
* @returns A funnel with a `call` function that is used to trigger invocations.
|
|
116
|
+
* In addition to it the funnel also comes with the following functions and
|
|
117
|
+
* properties:
|
|
118
|
+
* - `cancel` - Resets the funnel to it's initial state, discarding the current
|
|
119
|
+
* `reducer` result without calling `execute` on it.
|
|
120
|
+
* - `flush` - Triggers an invocation even if there are active timeouts, and
|
|
121
|
+
* then resets the funnel to it's initial state.
|
|
122
|
+
* - `isIdle` - Checks if there are any active timeouts.
|
|
123
|
+
* @signature
|
|
124
|
+
* P.funnel(callback, options);
|
|
125
|
+
* @example
|
|
126
|
+
* const debouncer = P.funnel(
|
|
127
|
+
* () => {
|
|
128
|
+
* console.log("Callback executed!");
|
|
129
|
+
* },
|
|
130
|
+
* { minQuietPeriodMs: 100 },
|
|
131
|
+
* );
|
|
132
|
+
* debouncer.call();
|
|
133
|
+
* debouncer.call();
|
|
134
|
+
*
|
|
135
|
+
* const throttle = P.funnel(
|
|
136
|
+
* () => {
|
|
137
|
+
* console.log("Callback executed!");
|
|
138
|
+
* },
|
|
139
|
+
* { minGapMs: 100, triggerAt: "start" },
|
|
140
|
+
* );
|
|
141
|
+
* throttle.call();
|
|
142
|
+
* throttle.call();
|
|
143
|
+
* @category Function
|
|
144
|
+
*/
|
|
145
|
+
declare function funnel<Args extends RestArguments = [], R = never>(callback: (data: R) => void, { triggerAt, minQuietPeriodMs, maxBurstDurationMs, minGapMs, reducer, }: FunnelOptions<Args, R>): Funnel<Args>;
|
|
146
|
+
|
|
147
|
+
export { funnel };
|
package/dist/funnel.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"./chunk-AWXJSK4F.js";export{a as funnel};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict"; function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _chunkAQRYBCA3cjs = require('./chunk-AQRYBCA3.cjs');var _chunkHC3HZK4Qcjs = require('./chunk-HC3HZK4Q.cjs');var _chunkGOUUMCT7cjs = require('./chunk-GOUUMCT7.cjs');var _chunkWLNQOMKLcjs = require('./chunk-WLNQOMKL.cjs');function o(e,t=0,{leading:s=!1,trailing:r=!0,maxWait:u}={}){let d,{call:h,flush:f,cancel:b}=_chunkGOUUMCT7cjs.a.call(void 0, l=>{!s&&!r||(d=e(...l))},{reducer:(l,...x)=>x,minQuietPeriodMs:t,...u!==void 0&&{maxBurstDurationMs:u},...r?s?{triggerAt:"both"}:{triggerAt:"end"}:{triggerAt:"start"}});return Object.assign((...l)=>(h(...l),d),{flush:()=>(f(),d),cancel:b})}var n=16;describe("https://github.com/lodash/lodash/blob/4.17.21/test/test.js#L4187",()=>{it("should debounce a function",async()=>{let e=vi.fn(_chunkAQRYBCA3cjs.a.call(void 0, )),t=o(e,n);expect(t("a")).toBeUndefined(),expect(t("b")).toBeUndefined(),expect(t("c")).toBeUndefined(),expect(e).toHaveBeenCalledTimes(0),await _chunkHC3HZK4Qcjs.a.call(void 0, 4*n),expect(e).toHaveBeenCalledTimes(1),expect(t("d")).toBe("c"),expect(t("e")).toBe("c"),expect(t("f")).toBe("c"),expect(e).toHaveBeenCalledTimes(1),await _chunkHC3HZK4Qcjs.a.call(void 0, 4*n),expect(e).toHaveBeenCalledTimes(2)}),it("subsequent debounced calls return the last `func` result",async()=>{let e=o(_chunkAQRYBCA3cjs.a.call(void 0, ),n);e("a"),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*n),expect(e("b")).not.toBe("b"),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*n),expect(e("c")).not.toBe("c")}),it("subsequent leading debounced calls return the last `func` result",async()=>{let e=o(_chunkAQRYBCA3cjs.a.call(void 0, ),n,{leading:!0,trailing:!1});expect(e("a")).toBe("a"),expect(e("b")).toBe("a"),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*n),expect(e("c")).toBe("c"),expect(e("d")).toBe("c")}),it("should invoke the trailing call with the correct arguments and `this` binding",async()=>{let e={},t=vi.fn(_chunkWLNQOMKLcjs.a.call(void 0, !1)),s=o(t,n,{maxWait:2*n});for(;_nullishCoalesce(s(e,"a"), () => (!0));)await _chunkHC3HZK4Qcjs.a.call(void 0, 0);await _chunkHC3HZK4Qcjs.a.call(void 0, 2*n),expect(t).toHaveBeenCalledTimes(2),expect(t).toHaveBeenLastCalledWith(e,"a")})});describe("https://github.com/lodash/lodash/blob/4.17.21/test/test.js#L23038",()=>{it("should reset `lastCalled` after cancelling",async()=>{let e=0,t=o(()=>(e+=1,e),n,{leading:!0});expect(t()).toBe(1),t.cancel(),expect(t()).toBe(2),t(),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*n),expect(e).toBe(3)}),it("should support flushing delayed calls",async()=>{let e=0,t=o(()=>(e+=1,e),n,{leading:!1});t(),expect(t.flush()).toBe(1),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*n),expect(e).toBe(1)}),it("should noop `cancel` and `flush` when nothing is queued",async()=>{let e=vi.fn(_chunkWLNQOMKLcjs.a.call(void 0, "hello")),t=o(e,n);t.cancel(),expect(t.flush()).toBeUndefined(),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*n),expect(e).toHaveBeenCalledTimes(0)})});describe("features not tested by Lodash",()=>{it("does nothing when neither leading nor trailing are enabled",async()=>{let e=o(_chunkAQRYBCA3cjs.a.call(void 0, ),n,{leading:!1,trailing:!1});expect(e("hello")).toBeUndefined(),expect(e("world")).toBeUndefined(),await _chunkHC3HZK4Qcjs.a.call(void 0, 4*n),expect(e("goodbye")).toBeUndefined()})});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as c}from"./chunk-46GBCFAG.js";import{a}from"./chunk-6SYP2DRD.js";import{a as p}from"./chunk-AWXJSK4F.js";import{a as i}from"./chunk-T5XG33UI.js";function o(e,t=0,{leading:s=!1,trailing:r=!0,maxWait:u}={}){let d,{call:h,flush:f,cancel:b}=p(l=>{!s&&!r||(d=e(...l))},{reducer:(l,...x)=>x,minQuietPeriodMs:t,...u!==void 0&&{maxBurstDurationMs:u},...r?s?{triggerAt:"both"}:{triggerAt:"end"}:{triggerAt:"start"}});return Object.assign((...l)=>(h(...l),d),{flush:()=>(f(),d),cancel:b})}var n=16;describe("https://github.com/lodash/lodash/blob/4.17.21/test/test.js#L4187",()=>{it("should debounce a function",async()=>{let e=vi.fn(c()),t=o(e,n);expect(t("a")).toBeUndefined(),expect(t("b")).toBeUndefined(),expect(t("c")).toBeUndefined(),expect(e).toHaveBeenCalledTimes(0),await a(4*n),expect(e).toHaveBeenCalledTimes(1),expect(t("d")).toBe("c"),expect(t("e")).toBe("c"),expect(t("f")).toBe("c"),expect(e).toHaveBeenCalledTimes(1),await a(4*n),expect(e).toHaveBeenCalledTimes(2)}),it("subsequent debounced calls return the last `func` result",async()=>{let e=o(c(),n);e("a"),await a(2*n),expect(e("b")).not.toBe("b"),await a(2*n),expect(e("c")).not.toBe("c")}),it("subsequent leading debounced calls return the last `func` result",async()=>{let e=o(c(),n,{leading:!0,trailing:!1});expect(e("a")).toBe("a"),expect(e("b")).toBe("a"),await a(2*n),expect(e("c")).toBe("c"),expect(e("d")).toBe("c")}),it("should invoke the trailing call with the correct arguments and `this` binding",async()=>{let e={},t=vi.fn(i(!1)),s=o(t,n,{maxWait:2*n});for(;s(e,"a")??!0;)await a(0);await a(2*n),expect(t).toHaveBeenCalledTimes(2),expect(t).toHaveBeenLastCalledWith(e,"a")})});describe("https://github.com/lodash/lodash/blob/4.17.21/test/test.js#L23038",()=>{it("should reset `lastCalled` after cancelling",async()=>{let e=0,t=o(()=>(e+=1,e),n,{leading:!0});expect(t()).toBe(1),t.cancel(),expect(t()).toBe(2),t(),await a(2*n),expect(e).toBe(3)}),it("should support flushing delayed calls",async()=>{let e=0,t=o(()=>(e+=1,e),n,{leading:!1});t(),expect(t.flush()).toBe(1),await a(2*n),expect(e).toBe(1)}),it("should noop `cancel` and `flush` when nothing is queued",async()=>{let e=vi.fn(i("hello")),t=o(e,n);t.cancel(),expect(t.flush()).toBeUndefined(),await a(2*n),expect(e).toHaveBeenCalledTimes(0)})});describe("features not tested by Lodash",()=>{it("does nothing when neither leading nor trailing are enabled",async()=>{let e=o(c(),n,{leading:!1,trailing:!1});expect(e("hello")).toBeUndefined(),expect(e("world")).toBeUndefined(),await a(4*n),expect(e("goodbye")).toBeUndefined()})});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var _chunkHC3HZK4Qcjs = require('./chunk-HC3HZK4Q.cjs');var _chunkGOUUMCT7cjs = require('./chunk-GOUUMCT7.cjs');function i(e,t=0,{leading:o=!1,trailing:s=!0,maxWait:c}={}){let{call:m,isIdle:v,...r}=_chunkGOUUMCT7cjs.a.call(void 0, d=>{!s&&!o||e(...d)},{reducer:(d,...p)=>p,minQuietPeriodMs:t,...c!==void 0&&{maxBurstDurationMs:c},...s?o?{triggerAt:"both"}:{triggerAt:"end"}:{triggerAt:"start"}});return Object.assign(m,r)}var a=16;describe("https://github.com/lodash/lodash/blob/4.17.21/test/test.js#L4187",()=>{it("should debounce a function",async()=>{let e=vi.fn(),t=i(e,a);t("a"),t("b"),t("c"),expect(e).toHaveBeenCalledTimes(0),await _chunkHC3HZK4Qcjs.a.call(void 0, 4*a),expect(e).toHaveBeenCalledTimes(1),expect(e).toHaveBeenCalledWith("c"),t("d"),t("e"),t("f"),expect(e).toHaveBeenCalledTimes(1),await _chunkHC3HZK4Qcjs.a.call(void 0, 4*a),expect(e).toHaveBeenCalledTimes(2)}),it("should not immediately call `func` when `wait` is `0`",async()=>{let e=vi.fn(),t=i(e,0);t(),t(),expect(e).toHaveBeenCalledTimes(0),await l(),expect(e).toHaveBeenCalledTimes(1)}),it("should apply default options",async()=>{let e=vi.fn();i(e,a,{})(),expect(e).toHaveBeenCalledTimes(0),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*a),expect(e).toHaveBeenCalledTimes(1)}),it("should support a `leading` option",async()=>{let e=vi.fn(),t=vi.fn(),o=i(e,a,{leading:!0,trailing:!1}),s=i(t,a,{leading:!0,trailing:!0});o(),expect(e).toHaveBeenCalledTimes(1),s(),s(),expect(t).toHaveBeenCalledTimes(1),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*a),expect(e).toHaveBeenCalledTimes(1),expect(t).toHaveBeenCalledTimes(2),o(),expect(e).toHaveBeenCalledTimes(2)}),it("should support a `trailing` option",async()=>{let e=vi.fn(),t=vi.fn(),o=i(e,a,{trailing:!0}),s=i(t,a,{trailing:!1});o(),expect(e).toHaveBeenCalledTimes(0),s(),expect(t).toHaveBeenCalledTimes(0),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*a),expect(e).toHaveBeenCalledTimes(1),expect(t).toHaveBeenCalledTimes(0)}),it("should support a `maxWait` option",async()=>{let e=vi.fn(),t=i(e,a,{maxWait:2*a});t(),t(),expect(e).toHaveBeenCalledTimes(0),await _chunkHC3HZK4Qcjs.a.call(void 0, 4*a),expect(e).toHaveBeenCalledTimes(1),t(),t(),expect(e).toHaveBeenCalledTimes(1),await _chunkHC3HZK4Qcjs.a.call(void 0, 4*a),expect(e).toHaveBeenCalledTimes(2)}),it("should support `maxWait` in a tight loop",async()=>{let e=vi.fn(),t=vi.fn(),o=i(e,2*a,{maxWait:4*a}),s=i(t,3*a),c=Date.now()+10*a;for(;Date.now()<c;)o(),s();expect(t).toHaveBeenCalledTimes(0),expect(e).toHaveBeenCalledTimes(0),await l(),expect(t).toHaveBeenCalledTimes(0),expect(e).toHaveBeenCalledTimes(1)}),it("should queue a trailing call for subsequent debounced calls after `maxWait`",async()=>{let e=vi.fn(),t=i(e,6*a,{maxWait:6*a});t(),await _chunkHC3HZK4Qcjs.a.call(void 0, 5.5*a),t(),await _chunkHC3HZK4Qcjs.a.call(void 0, .5*a),t(),await _chunkHC3HZK4Qcjs.a.call(void 0, .5*a),t(),await _chunkHC3HZK4Qcjs.a.call(void 0, 9.5*a),expect(e).toHaveBeenCalledTimes(2)}),it("should cancel `maxDelayed` when `delayed` is invoked",async()=>{let e=vi.fn(),t=i(e,a,{maxWait:2*a});t(),await _chunkHC3HZK4Qcjs.a.call(void 0, 4*a),t(),expect(e).toHaveBeenCalledTimes(1),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*a),expect(e).toHaveBeenCalledTimes(2)}),it("should invoke the trailing call with the correct arguments and `this` binding",async()=>{let e=vi.fn(),t={},o=i(e,a,{leading:!0,maxWait:2*a});for(;e.mock.calls.length<2;)o(t,"a"),await l();await _chunkHC3HZK4Qcjs.a.call(void 0, 2*a),expect(e).toHaveBeenCalledTimes(2),expect(e).toHaveBeenLastCalledWith(t,"a")})});describe("https://github.com/lodash/lodash/blob/4.17.21/test/test.js#L23038",()=>{it("should use a default `wait` of `0`",async()=>{let e=vi.fn(),t=i(e);t(),await _chunkHC3HZK4Qcjs.a.call(void 0, a),t(),expect(e).toHaveBeenCalledTimes(1)}),it("supports recursive calls",async()=>{let e=[],t=["a","b","c"],o=i(s=>{e.push(s);let c=t.shift();c!==void 0&&o(c)},a);o(t.shift()),expect(e).toStrictEqual([]),await _chunkHC3HZK4Qcjs.a.call(void 0, 8*a),expect(e).toStrictEqual(["a","b","c"])}),it("should support cancelling delayed calls",async()=>{let e=vi.fn(),t=i(e,a,{leading:!1});t(),t.cancel(),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*a),expect(e).toHaveBeenCalledTimes(0)}),it("should reset `lastCalled` after cancelling",async()=>{let e=vi.fn(),t=i(e,a,{leading:!0});t(),expect(e).toHaveBeenCalledTimes(1),t.cancel(),t(),expect(e).toHaveBeenCalledTimes(2),t(),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*a),expect(e).toHaveBeenCalledTimes(3)}),it("should support flushing delayed calls",async()=>{let e=vi.fn(),t=i(e,a,{leading:!1});t(),t.flush(),expect(e).toHaveBeenCalledTimes(1),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*a),expect(e).toHaveBeenCalledTimes(1)}),it("should noop `cancel` and `flush` when nothing is queued",async()=>{let e=vi.fn(),t=i(e,a);t.cancel(),t.flush(),expect(e).toHaveBeenCalledTimes(0),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*a),expect(e).toHaveBeenCalledTimes(0)})});var l=async()=>await _chunkHC3HZK4Qcjs.a.call(void 0, 0);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as n}from"./chunk-6SYP2DRD.js";import{a as u}from"./chunk-AWXJSK4F.js";function i(e,t=0,{leading:o=!1,trailing:s=!0,maxWait:c}={}){let{call:m,isIdle:v,...r}=u(d=>{!s&&!o||e(...d)},{reducer:(d,...p)=>p,minQuietPeriodMs:t,...c!==void 0&&{maxBurstDurationMs:c},...s?o?{triggerAt:"both"}:{triggerAt:"end"}:{triggerAt:"start"}});return Object.assign(m,r)}var a=16;describe("https://github.com/lodash/lodash/blob/4.17.21/test/test.js#L4187",()=>{it("should debounce a function",async()=>{let e=vi.fn(),t=i(e,a);t("a"),t("b"),t("c"),expect(e).toHaveBeenCalledTimes(0),await n(4*a),expect(e).toHaveBeenCalledTimes(1),expect(e).toHaveBeenCalledWith("c"),t("d"),t("e"),t("f"),expect(e).toHaveBeenCalledTimes(1),await n(4*a),expect(e).toHaveBeenCalledTimes(2)}),it("should not immediately call `func` when `wait` is `0`",async()=>{let e=vi.fn(),t=i(e,0);t(),t(),expect(e).toHaveBeenCalledTimes(0),await l(),expect(e).toHaveBeenCalledTimes(1)}),it("should apply default options",async()=>{let e=vi.fn();i(e,a,{})(),expect(e).toHaveBeenCalledTimes(0),await n(2*a),expect(e).toHaveBeenCalledTimes(1)}),it("should support a `leading` option",async()=>{let e=vi.fn(),t=vi.fn(),o=i(e,a,{leading:!0,trailing:!1}),s=i(t,a,{leading:!0,trailing:!0});o(),expect(e).toHaveBeenCalledTimes(1),s(),s(),expect(t).toHaveBeenCalledTimes(1),await n(2*a),expect(e).toHaveBeenCalledTimes(1),expect(t).toHaveBeenCalledTimes(2),o(),expect(e).toHaveBeenCalledTimes(2)}),it("should support a `trailing` option",async()=>{let e=vi.fn(),t=vi.fn(),o=i(e,a,{trailing:!0}),s=i(t,a,{trailing:!1});o(),expect(e).toHaveBeenCalledTimes(0),s(),expect(t).toHaveBeenCalledTimes(0),await n(2*a),expect(e).toHaveBeenCalledTimes(1),expect(t).toHaveBeenCalledTimes(0)}),it("should support a `maxWait` option",async()=>{let e=vi.fn(),t=i(e,a,{maxWait:2*a});t(),t(),expect(e).toHaveBeenCalledTimes(0),await n(4*a),expect(e).toHaveBeenCalledTimes(1),t(),t(),expect(e).toHaveBeenCalledTimes(1),await n(4*a),expect(e).toHaveBeenCalledTimes(2)}),it("should support `maxWait` in a tight loop",async()=>{let e=vi.fn(),t=vi.fn(),o=i(e,2*a,{maxWait:4*a}),s=i(t,3*a),c=Date.now()+10*a;for(;Date.now()<c;)o(),s();expect(t).toHaveBeenCalledTimes(0),expect(e).toHaveBeenCalledTimes(0),await l(),expect(t).toHaveBeenCalledTimes(0),expect(e).toHaveBeenCalledTimes(1)}),it("should queue a trailing call for subsequent debounced calls after `maxWait`",async()=>{let e=vi.fn(),t=i(e,6*a,{maxWait:6*a});t(),await n(5.5*a),t(),await n(.5*a),t(),await n(.5*a),t(),await n(9.5*a),expect(e).toHaveBeenCalledTimes(2)}),it("should cancel `maxDelayed` when `delayed` is invoked",async()=>{let e=vi.fn(),t=i(e,a,{maxWait:2*a});t(),await n(4*a),t(),expect(e).toHaveBeenCalledTimes(1),await n(2*a),expect(e).toHaveBeenCalledTimes(2)}),it("should invoke the trailing call with the correct arguments and `this` binding",async()=>{let e=vi.fn(),t={},o=i(e,a,{leading:!0,maxWait:2*a});for(;e.mock.calls.length<2;)o(t,"a"),await l();await n(2*a),expect(e).toHaveBeenCalledTimes(2),expect(e).toHaveBeenLastCalledWith(t,"a")})});describe("https://github.com/lodash/lodash/blob/4.17.21/test/test.js#L23038",()=>{it("should use a default `wait` of `0`",async()=>{let e=vi.fn(),t=i(e);t(),await n(a),t(),expect(e).toHaveBeenCalledTimes(1)}),it("supports recursive calls",async()=>{let e=[],t=["a","b","c"],o=i(s=>{e.push(s);let c=t.shift();c!==void 0&&o(c)},a);o(t.shift()),expect(e).toStrictEqual([]),await n(8*a),expect(e).toStrictEqual(["a","b","c"])}),it("should support cancelling delayed calls",async()=>{let e=vi.fn(),t=i(e,a,{leading:!1});t(),t.cancel(),await n(2*a),expect(e).toHaveBeenCalledTimes(0)}),it("should reset `lastCalled` after cancelling",async()=>{let e=vi.fn(),t=i(e,a,{leading:!0});t(),expect(e).toHaveBeenCalledTimes(1),t.cancel(),t(),expect(e).toHaveBeenCalledTimes(2),t(),await n(2*a),expect(e).toHaveBeenCalledTimes(3)}),it("should support flushing delayed calls",async()=>{let e=vi.fn(),t=i(e,a,{leading:!1});t(),t.flush(),expect(e).toHaveBeenCalledTimes(1),await n(2*a),expect(e).toHaveBeenCalledTimes(1)}),it("should noop `cancel` and `flush` when nothing is queued",async()=>{let e=vi.fn(),t=i(e,a);t.cancel(),t.flush(),expect(e).toHaveBeenCalledTimes(0),await n(2*a),expect(e).toHaveBeenCalledTimes(0)})});var l=async()=>await n(0);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var _chunkAQRYBCA3cjs = require('./chunk-AQRYBCA3.cjs');var _chunkHC3HZK4Qcjs = require('./chunk-HC3HZK4Q.cjs');var _chunkGOUUMCT7cjs = require('./chunk-GOUUMCT7.cjs');var _chunkWLNQOMKLcjs = require('./chunk-WLNQOMKL.cjs');function o(e,t=0,{leading:a=!0,trailing:i=!0}={}){let c,{call:h,flush:p,cancel:f}=_chunkGOUUMCT7cjs.a.call(void 0, r=>{!a&&!i||(c=e(...r))},{reducer:(r,...g)=>g,minQuietPeriodMs:t,maxBurstDurationMs:t,...i?a?{triggerAt:"both"}:{triggerAt:"end"}:{triggerAt:"start"}});return Object.assign((...r)=>(h(...r),c),{flush:()=>(p(),c),cancel:f})}var n=16;describe("https://github.com/lodash/lodash/blob/4.17.21/test/test.js#L22768",()=>{it("subsequent calls should return the result of the first call",async()=>{let e=o(_chunkAQRYBCA3cjs.a.call(void 0, ),n);expect(e("a")).toBe("a"),expect(e("b")).toBe("a"),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*n);let t=e("c"),a=e("d");expect(t).not.toBe("a"),expect(t).toBeDefined(),expect(a).not.toBe("d"),expect(a).toBeDefined()}),it("should support a `leading` option",()=>{let e=o(_chunkAQRYBCA3cjs.a.call(void 0, ),n,{leading:!0}),t=o(_chunkAQRYBCA3cjs.a.call(void 0, ),n,{leading:!1});expect(e("a")).toBe("a"),expect(t("a")).toBeUndefined()}),it("should support a `trailing` option",async()=>{let e=vi.fn(_chunkAQRYBCA3cjs.a.call(void 0, )),t=vi.fn(_chunkAQRYBCA3cjs.a.call(void 0, )),a=o(e,2*n,{trailing:!0}),i=o(t,2*n,{trailing:!1});expect(a("a")).toBe("a"),expect(a("b")).toBe("a"),expect(i("a")).toBe("a"),expect(i("b")).toBe("a"),await _chunkHC3HZK4Qcjs.a.call(void 0, 8*n),expect(e).toHaveBeenCalledTimes(2),expect(t).toHaveBeenCalledTimes(1)})});describe("https://github.com/lodash/lodash/blob/4.17.21/test/test.js#L23038",()=>{it("should reset `lastCalled` after cancelling",async()=>{let e=0,t=o(()=>(e+=1,e),n,{leading:!0});expect(t()).toBe(1),t.cancel(),expect(t()).toBe(2),t(),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*n),expect(e).toBe(3)}),it("should support flushing delayed calls",async()=>{let e=0,t=o(()=>(e+=1,e),n,{leading:!1});t(),expect(t.flush()).toBe(1),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*n),expect(e).toBe(1)}),it("should noop `cancel` and `flush` when nothing is queued",async()=>{let e=vi.fn(_chunkWLNQOMKLcjs.a.call(void 0, "hello")),t=o(e,n);t.cancel(),expect(t.flush()).toBeUndefined(),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*n),expect(e).toHaveBeenCalledTimes(0)})});describe("features not tested by Lodash",()=>{it("does nothing when neither leading nor trailing are enabled",async()=>{let e=o(_chunkAQRYBCA3cjs.a.call(void 0, ),n,{leading:!1,trailing:!1});expect(e("hello")).toBeUndefined(),expect(e("world")).toBeUndefined(),await _chunkHC3HZK4Qcjs.a.call(void 0, 4*n),expect(e("goodbye")).toBeUndefined()})});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as l}from"./chunk-46GBCFAG.js";import{a as s}from"./chunk-6SYP2DRD.js";import{a as u}from"./chunk-AWXJSK4F.js";import{a as d}from"./chunk-T5XG33UI.js";function o(e,t=0,{leading:a=!0,trailing:i=!0}={}){let c,{call:h,flush:p,cancel:f}=u(r=>{!a&&!i||(c=e(...r))},{reducer:(r,...g)=>g,minQuietPeriodMs:t,maxBurstDurationMs:t,...i?a?{triggerAt:"both"}:{triggerAt:"end"}:{triggerAt:"start"}});return Object.assign((...r)=>(h(...r),c),{flush:()=>(p(),c),cancel:f})}var n=16;describe("https://github.com/lodash/lodash/blob/4.17.21/test/test.js#L22768",()=>{it("subsequent calls should return the result of the first call",async()=>{let e=o(l(),n);expect(e("a")).toBe("a"),expect(e("b")).toBe("a"),await s(2*n);let t=e("c"),a=e("d");expect(t).not.toBe("a"),expect(t).toBeDefined(),expect(a).not.toBe("d"),expect(a).toBeDefined()}),it("should support a `leading` option",()=>{let e=o(l(),n,{leading:!0}),t=o(l(),n,{leading:!1});expect(e("a")).toBe("a"),expect(t("a")).toBeUndefined()}),it("should support a `trailing` option",async()=>{let e=vi.fn(l()),t=vi.fn(l()),a=o(e,2*n,{trailing:!0}),i=o(t,2*n,{trailing:!1});expect(a("a")).toBe("a"),expect(a("b")).toBe("a"),expect(i("a")).toBe("a"),expect(i("b")).toBe("a"),await s(8*n),expect(e).toHaveBeenCalledTimes(2),expect(t).toHaveBeenCalledTimes(1)})});describe("https://github.com/lodash/lodash/blob/4.17.21/test/test.js#L23038",()=>{it("should reset `lastCalled` after cancelling",async()=>{let e=0,t=o(()=>(e+=1,e),n,{leading:!0});expect(t()).toBe(1),t.cancel(),expect(t()).toBe(2),t(),await s(2*n),expect(e).toBe(3)}),it("should support flushing delayed calls",async()=>{let e=0,t=o(()=>(e+=1,e),n,{leading:!1});t(),expect(t.flush()).toBe(1),await s(2*n),expect(e).toBe(1)}),it("should noop `cancel` and `flush` when nothing is queued",async()=>{let e=vi.fn(d("hello")),t=o(e,n);t.cancel(),expect(t.flush()).toBeUndefined(),await s(2*n),expect(e).toHaveBeenCalledTimes(0)})});describe("features not tested by Lodash",()=>{it("does nothing when neither leading nor trailing are enabled",async()=>{let e=o(l(),n,{leading:!1,trailing:!1});expect(e("hello")).toBeUndefined(),expect(e("world")).toBeUndefined(),await s(4*n),expect(e("goodbye")).toBeUndefined()})});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var _chunkHC3HZK4Qcjs = require('./chunk-HC3HZK4Q.cjs');var _chunkGOUUMCT7cjs = require('./chunk-GOUUMCT7.cjs');function l(e,t=0,{leading:o=!0,trailing:s=!0}={}){let{call:i,isIdle:u,...r}=_chunkGOUUMCT7cjs.a.call(void 0, c=>{!o&&!s||e(...c)},{reducer:(c,...h)=>h,minQuietPeriodMs:t,maxBurstDurationMs:t,...s?o?{triggerAt:"both"}:{triggerAt:"end"}:{triggerAt:"start"}});return Object.assign(i,r)}var a=16;describe("https://github.com/lodash/lodash/blob/4.17.21/test/test.js#L22768",()=>{it("should throttle a function",async()=>{let e=vi.fn(),t=l(e,a);t(),t(),t();let o=e.mock.calls.length;expect(o).toBeGreaterThan(0),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*a),expect(e.mock.calls.length).toBeGreaterThan(o)}),it("should clear timeout when `func` is called",async()=>{let e=vi.fn(),t=l(e,a);t(),expect(e).toHaveBeenCalledTimes(1),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*a),t(),expect(e).toHaveBeenCalledTimes(2)}),it("should not trigger a trailing call when invoked once",async()=>{let e=vi.fn();l(e,a)(),expect(e).toHaveBeenCalledTimes(1),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*a),expect(e).toHaveBeenCalledTimes(1)}),it("should trigger a call when invoked repeatedly",()=>{let e=vi.fn(),t=l(e,a),o=Date.now()+10*a;for(;Date.now()<o;)t();expect(e).toHaveBeenCalledWith()}),it("should trigger a call when invoked repeatedly and `leading` is `false`",async()=>{let e=vi.fn(),t=l(e,a,{leading:!1}),o=Date.now()+10*a;for(;Date.now()<o;)t();await _chunkHC3HZK4Qcjs.a.call(void 0, 0),expect(e).toHaveBeenCalledWith()}),it("should trigger a second throttled call as soon as possible",async()=>{let e=vi.fn(),t=l(e,4*a,{leading:!1});t(),await _chunkHC3HZK4Qcjs.a.call(void 0, 6*a),expect(e).toHaveBeenCalledTimes(1),t(),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*a),expect(e).toHaveBeenCalledTimes(1),await _chunkHC3HZK4Qcjs.a.call(void 0, 4*a),expect(e).toHaveBeenCalledTimes(2)}),it("should apply default options",async()=>{let e=vi.fn(),t=l(e,a,{});t(),t(),expect(e).toHaveBeenCalledTimes(1),await _chunkHC3HZK4Qcjs.a.call(void 0, 4*a),expect(e).toHaveBeenCalledTimes(2)}),it("should support a `leading` option",()=>{let e=vi.fn(),t=vi.fn(),o=l(e,a,{leading:!0}),s=l(t,a,{leading:!1});o(),s(),expect(e).toHaveBeenCalledTimes(1),expect(t).toHaveBeenCalledTimes(0)}),it("should support a `trailing` option",async()=>{let e=vi.fn(),t=vi.fn(),o=l(e,2*a,{trailing:!0}),s=l(t,2*a,{trailing:!1});o("a"),o("b"),s("a"),s("b"),expect(e).toHaveBeenCalledTimes(1),expect(e).toHaveBeenCalledWith("a"),expect(t).toHaveBeenCalledTimes(1),expect(t).toHaveBeenCalledWith("a"),await _chunkHC3HZK4Qcjs.a.call(void 0, 8*a),expect(e).toHaveBeenCalledTimes(2),expect(t).toHaveBeenCalledTimes(1)}),it("should not update `lastCalled`, at the end of the timeout, when `trailing` is `false`",async()=>{let e=vi.fn(),t=l(e,64,{trailing:!1});t(),t(),await _chunkHC3HZK4Qcjs.a.call(void 0, 3*a),t(),t(),await _chunkHC3HZK4Qcjs.a.call(void 0, 3*a),expect(e).toHaveBeenCalledWith()})});describe("https://github.com/lodash/lodash/blob/4.17.21/test/test.js#L23038",()=>{it("should use a default `wait` of `0`",async()=>{let e=vi.fn(),t=l(e);t(),await _chunkHC3HZK4Qcjs.a.call(void 0, a),t(),expect(e).toHaveBeenCalledTimes(2)}),it("supports recursive calls",async()=>{let e=[],t=["a","b","c"],o=l(s=>{e.push(s);let i=t.shift();i!==void 0&&o(i)},a);o(t.shift()),expect(e).toStrictEqual(["a"]),await _chunkHC3HZK4Qcjs.a.call(void 0, 8*a),expect(e).toStrictEqual(["a","b","c"])}),it("should support cancelling delayed calls",async()=>{let e=vi.fn(),t=l(e,a,{leading:!1});t(),t.cancel(),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*a),expect(e).toHaveBeenCalledTimes(0)}),it("should reset `lastCalled` after cancelling",async()=>{let e=vi.fn(),t=l(e,a,{leading:!0});t(),expect(e).toHaveBeenCalledTimes(1),t.cancel(),t(),expect(e).toHaveBeenCalledTimes(2),t(),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*a),expect(e).toHaveBeenCalledTimes(3)}),it("should support flushing delayed calls",async()=>{let e=vi.fn(),t=l(e,a,{leading:!1});t(),t.flush(),expect(e).toHaveBeenCalledTimes(1),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*a),expect(e).toHaveBeenCalledTimes(1)}),it("should noop `cancel` and `flush` when nothing is queued",async()=>{let e=vi.fn(),t=l(e,a);t.cancel(),t.flush(),expect(e).toHaveBeenCalledTimes(0),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*a),expect(e).toHaveBeenCalledTimes(0)})});describe("not tested by Lodash",()=>{it("should do nothing when `leading` and `trailing` are both `disabled`",async()=>{let e=vi.fn(),t=l(e,a,{leading:!1,trailing:!1});t(),t(),t(),expect(e).toHaveBeenCalledTimes(0),await _chunkHC3HZK4Qcjs.a.call(void 0, 2*a),expect(e).toHaveBeenCalledTimes(0)})});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as n}from"./chunk-6SYP2DRD.js";import{a as d}from"./chunk-AWXJSK4F.js";function l(e,t=0,{leading:o=!0,trailing:s=!0}={}){let{call:i,isIdle:u,...r}=d(c=>{!o&&!s||e(...c)},{reducer:(c,...h)=>h,minQuietPeriodMs:t,maxBurstDurationMs:t,...s?o?{triggerAt:"both"}:{triggerAt:"end"}:{triggerAt:"start"}});return Object.assign(i,r)}var a=16;describe("https://github.com/lodash/lodash/blob/4.17.21/test/test.js#L22768",()=>{it("should throttle a function",async()=>{let e=vi.fn(),t=l(e,a);t(),t(),t();let o=e.mock.calls.length;expect(o).toBeGreaterThan(0),await n(2*a),expect(e.mock.calls.length).toBeGreaterThan(o)}),it("should clear timeout when `func` is called",async()=>{let e=vi.fn(),t=l(e,a);t(),expect(e).toHaveBeenCalledTimes(1),await n(2*a),t(),expect(e).toHaveBeenCalledTimes(2)}),it("should not trigger a trailing call when invoked once",async()=>{let e=vi.fn();l(e,a)(),expect(e).toHaveBeenCalledTimes(1),await n(2*a),expect(e).toHaveBeenCalledTimes(1)}),it("should trigger a call when invoked repeatedly",()=>{let e=vi.fn(),t=l(e,a),o=Date.now()+10*a;for(;Date.now()<o;)t();expect(e).toHaveBeenCalledWith()}),it("should trigger a call when invoked repeatedly and `leading` is `false`",async()=>{let e=vi.fn(),t=l(e,a,{leading:!1}),o=Date.now()+10*a;for(;Date.now()<o;)t();await n(0),expect(e).toHaveBeenCalledWith()}),it("should trigger a second throttled call as soon as possible",async()=>{let e=vi.fn(),t=l(e,4*a,{leading:!1});t(),await n(6*a),expect(e).toHaveBeenCalledTimes(1),t(),await n(2*a),expect(e).toHaveBeenCalledTimes(1),await n(4*a),expect(e).toHaveBeenCalledTimes(2)}),it("should apply default options",async()=>{let e=vi.fn(),t=l(e,a,{});t(),t(),expect(e).toHaveBeenCalledTimes(1),await n(4*a),expect(e).toHaveBeenCalledTimes(2)}),it("should support a `leading` option",()=>{let e=vi.fn(),t=vi.fn(),o=l(e,a,{leading:!0}),s=l(t,a,{leading:!1});o(),s(),expect(e).toHaveBeenCalledTimes(1),expect(t).toHaveBeenCalledTimes(0)}),it("should support a `trailing` option",async()=>{let e=vi.fn(),t=vi.fn(),o=l(e,2*a,{trailing:!0}),s=l(t,2*a,{trailing:!1});o("a"),o("b"),s("a"),s("b"),expect(e).toHaveBeenCalledTimes(1),expect(e).toHaveBeenCalledWith("a"),expect(t).toHaveBeenCalledTimes(1),expect(t).toHaveBeenCalledWith("a"),await n(8*a),expect(e).toHaveBeenCalledTimes(2),expect(t).toHaveBeenCalledTimes(1)}),it("should not update `lastCalled`, at the end of the timeout, when `trailing` is `false`",async()=>{let e=vi.fn(),t=l(e,64,{trailing:!1});t(),t(),await n(3*a),t(),t(),await n(3*a),expect(e).toHaveBeenCalledWith()})});describe("https://github.com/lodash/lodash/blob/4.17.21/test/test.js#L23038",()=>{it("should use a default `wait` of `0`",async()=>{let e=vi.fn(),t=l(e);t(),await n(a),t(),expect(e).toHaveBeenCalledTimes(2)}),it("supports recursive calls",async()=>{let e=[],t=["a","b","c"],o=l(s=>{e.push(s);let i=t.shift();i!==void 0&&o(i)},a);o(t.shift()),expect(e).toStrictEqual(["a"]),await n(8*a),expect(e).toStrictEqual(["a","b","c"])}),it("should support cancelling delayed calls",async()=>{let e=vi.fn(),t=l(e,a,{leading:!1});t(),t.cancel(),await n(2*a),expect(e).toHaveBeenCalledTimes(0)}),it("should reset `lastCalled` after cancelling",async()=>{let e=vi.fn(),t=l(e,a,{leading:!0});t(),expect(e).toHaveBeenCalledTimes(1),t.cancel(),t(),expect(e).toHaveBeenCalledTimes(2),t(),await n(2*a),expect(e).toHaveBeenCalledTimes(3)}),it("should support flushing delayed calls",async()=>{let e=vi.fn(),t=l(e,a,{leading:!1});t(),t.flush(),expect(e).toHaveBeenCalledTimes(1),await n(2*a),expect(e).toHaveBeenCalledTimes(1)}),it("should noop `cancel` and `flush` when nothing is queued",async()=>{let e=vi.fn(),t=l(e,a);t.cancel(),t.flush(),expect(e).toHaveBeenCalledTimes(0),await n(2*a),expect(e).toHaveBeenCalledTimes(0)})});describe("not tested by Lodash",()=>{it("should do nothing when `leading` and `trailing` are both `disabled`",async()=>{let e=vi.fn(),t=l(e,a,{leading:!1,trailing:!1});t(),t(),t(),expect(e).toHaveBeenCalledTimes(0),await n(2*a),expect(e).toHaveBeenCalledTimes(0)})});
|