https://github.com/geometryzen/debounce
A debounce function for JavaScript and TypeScript
https://github.com/geometryzen/debounce
Last synced: 3 months 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 (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-17T15:31:27.000Z (about 1 year ago)
- Last Synced: 2025-03-18T16:59:18.597Z (4 months 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");
}
});
});
```[](https://www.npmjs.com/package/@geometryzen/debounce)
[](https://npm-stat.com/charts.html?package=@geometryzen/debounce&from=2022-09-01)
[](./LICENSE)
[](./CONTRIBUTING.md)