1.1.1 • Published 5 years ago

throttle-debounce-ts v1.1.1

Weekly downloads
27
License
MIT
Repository
github
Last release
5 years ago

throttle-debounce-ts · GitHub license

Throttle and debounce functions written in Typescript.

Features:

  • No thirdparty dependecies
  • Easy to use
  • ES Modules and CommonJS format

Install

npm i throttle-debounce-ts

Usage

Throttle

import { throttle } from "throttle-debounce-ts";

const throttleFunc = throttle(1000, () => {
  console.log("Hello Throttle!");
});

Debounce

import { debounce } from "throttle-debounce-ts";

const debounceFunc = debounce(1000, () => {
    console.log("Hello Debounce!");
});

Cancel

const throttleFunc = throttle(1000, () => {
    // ...
});
// will cancel throttleFunc
throttleFunc.cancel();

const debounceFunc = debounce(1000, () => {
    // ...
});
// will cancel delay of debounceFunc
// callback will exec immediately when you call debounceFunc next time
debounceFunc.cancel();

API

throttle(options, callback)

Returns: Function

Throttle execution of a function.

options

Type: Number

A zero-or-greater delay in milliseconds.

Type: Object

options.delay A zero-or-greater delay in milliseconds.

options.leading Optional, defaults to false. If it's true, the function will exec on the first call.

options.trailing Optional, defaults to false. If it's true, the function will exec after last call.

callback

Type: Function

A function to be executed after delay milliseconds.


debounce(options, callback)

Returns: Function

Debounce execution of a function.

options

Type: Number

A zero-or-greater delay in milliseconds.

Type: Object

options.delay A zero-or-greater delay in milliseconds.

options.leading Optional, defaults to false. If it's true, the function will exec on the first call.

callback

Type: Function

A function to be executed after delay milliseconds.

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago