@frankykubo/debounce-tools
TypeScript icon, indicating that this package has built-in type declarations

1.0.10 • Public • Published

Debounce Tools

Debounce Tools is a TypeScript library for debouncing function calls in both synchronous and asynchronous contexts.

Installation

To install Debounce Tools, you can use NPM:

npm install @frankykubo/debounce-tools

Usage

Here are the available functions in Debounce Tools:

Function Parameters Description
debounceMemoize callback: (...args: any[], prevArgs: any[][] = []) => any, delay: number Async function that debounces and memoizes the result of the callback function
syncDebounceMemoize callback: (...args: any[], prevArgs: any[][] = []) => void, delay: number Sync function that debounces and memoizes the result of the callback function

Example 1

import { debounceMemoize } from '@frankykubo/debounce-tools';

const printStr = (someString: string, prevArgs: string[][] = []) => {
    console.log(someString);
    console.log(prevArgs.flatMap(str => str));
}

const printStrWrapped = debounceMemoize(printStr, 100);

printStrWrapped('Test');
printStrWrapped('debounced');
printStrWrapped('printStr');
printStrWrapped('function');


$ 'function'
$ [ 'Test', 'debounced', 'printStr' ]

Example 2

import { syncDebounceMemoize } from '@frankykubo/debounce-tools';

const printStr = (someString: string, prevArgs: string[][] = []) => {
    console.log(someString);
    console.log(prevArgs.flatMap(str => str));
    return someString;
}

const printStrWrapped = syncDebounceMemoize(printStr, 100);

printStrWrapped('Test');
printStrWrapped('debounced');
printStrWrapped('printStr');
printStrWrapped('function');


$ 'function'
$ [ 'Test', 'debounced', 'printStr' ]

Contributing

Contributions are welcome! Please feel free to open issues and pull requests on GitHub.

License

This project is licensed under the MIT License.

Dependencies (0)

    Dev Dependencies (1)

    Package Sidebar

    Install

    npm i @frankykubo/debounce-tools

    Weekly Downloads

    1

    Version

    1.0.10

    License

    ISC

    Unpacked Size

    18.7 kB

    Total Files

    9

    Last publish

    Collaborators

    • frankykubo