Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@common-utilities/debounce

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@common-utilities/debounce - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

4

package.json
{
"name": "@common-utilities/debounce",
"version": "0.0.1",
"version": "0.0.2",
"description": "A basic implementation of the common utility function, Debounce 🏓",

@@ -31,3 +31,3 @@ "main": "dist/index.js",

],
"gitHead": "0c2892395dbb2963f10f5cddda5b311591d2dbad"
"gitHead": "306640dddfb574cc3958dd3b312fdae5c8933d5f"
}

@@ -10,28 +10,3 @@ # @common-utilities/debounce 🧰 🏓

## Install
Check out the [debounce page](https://www.common-utilities.com/utilities/packages/debounce) in the [docs](https://www.common-utilities.com)! License, MIT
```bash
yarn add @common-utilities/debounce -D
```
## Usage
```javascript
let result = 1
const add1 = (val) => {
result = val + 1
}
debounce(add1, 1000)(1) // returns 2, after 1 second
```
---
## Common Utilities 🧰
**No cruft. No bloat. No dependencies.**
Simple, typed, functional, documented, and tested javascript utility functions.
---
View other [common utilities](https://github.com/yowainwright/common-utilities).

@@ -11,7 +11,9 @@ type Fn = (args?: unknown) => void

*/
export const debounce = (fn: Fn, delay: number, timeout = 0): Fn => (args?: unknown) => {
clearTimeout(timeout)
// adds `as unknown as number` to ensure setTimeout returns a number
// like window.setTimeout
timeout = (setTimeout((): void => fn(args), delay) as unknown) as number
}
export const debounce =
(fn: Fn, delay: number, timeout = 0): Fn =>
(args?: unknown) => {
clearTimeout(timeout)
// adds `as unknown as number` to ensure setTimeout returns a number
// like window.setTimeout
timeout = setTimeout((): void => fn(args), delay) as unknown as number
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc