Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/geometryzen/debounce
A debounce function for JavaScript and TypeScript
https://github.com/geometryzen/debounce
Last synced: 9 days ago
JSON representation
A debounce function for JavaScript and TypeScript
- Host: GitHub
- URL: https://github.com/geometryzen/debounce
- Owner: geometryzen
- License: mit
- Created: 2024-06-17T14:56:00.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-06-17T15:31:27.000Z (5 months ago)
- Last Synced: 2024-10-29T21:22:03.628Z (17 days ago)
- Language: TypeScript
- Size: 159 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# debounce
A debounce function for JavaScript and TypeScript.
```typescript
import { debounce } from "@geometryzen/debounce";function foo(a: string, b: number) {
if (b >= 0) {
return a.length + b;
} else {
throw new Error("b must be positive");
}
}describe("debounce", function () {
it("resolve", async function () {
const handler = debounce(foo, 100);
const retval = await handler("Hello", 1);
expect(retval).toBe(6);
});
it("reject", async function () {
const handler = debounce(foo, 100);
try {
await handler("Hello", -1);
fail();
} catch (e) {
expect(`${e}`).toBe("Error: b must be positive");
}
});
});
```[![version](https://img.shields.io/npm/v/@geometryzen/debounce.svg)](https://www.npmjs.com/package/@geometryzen/debounce)
[![npm downloads](https://img.shields.io/npm/dm/@geometryzen/debounce.svg)](https://npm-stat.com/charts.html?package=@geometryzen/debounce&from=2022-09-01)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](./CONTRIBUTING.md)