perfect-debounce 0.0.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -67,8 +67,8 @@ const debounced = debounce(async () => {
67
67
 
68
68
  - Clone this repository
69
69
  - Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable` (use `npm i -g corepack` for Node.js < 16.10)
70
- - Install dependencies using `yarn install`
71
- - Run interactive tests using `yarn dev`
70
+ - Install dependencies using `pnpm install`
71
+ - Run interactive tests using `pnpm dev`
72
72
 
73
73
  ## License
74
74
 
package/dist/index.cjs CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  const DEBOUNCE_DEFAULTS = {
6
6
  trailing: true
7
7
  };
8
- function debounce(fn, wait, options = {}) {
8
+ function debounce(fn, wait = 25, options = {}) {
9
9
  options = { ...DEBOUNCE_DEFAULTS, ...options };
10
10
  if (!Number.isFinite(wait)) {
11
11
  throw new TypeError("Expected `wait` to be a finite number");
package/dist/index.d.ts CHANGED
@@ -14,13 +14,13 @@ interface DebounceOptions {
14
14
  /**
15
15
  Debounce functions
16
16
  @param fn - Promise-returning/async function to debounce.
17
- @param wait - Milliseconds to wait before calling `fn`.
17
+ @param wait - Milliseconds to wait before calling `fn`. Default value is 25ms
18
18
  @returns A function that delays calling `fn` until after `wait` milliseconds have elapsed since the last time it was called.
19
19
  @example
20
20
  ```
21
- import pDebounce from 'p-debounce';
21
+ import { debounce } from 'perfect-debounce';
22
22
  const expensiveCall = async input => input;
23
- const debouncedFn = pDebounce(expensiveCall, 200);
23
+ const debouncedFn = debounce(expensiveCall, 200);
24
24
  for (const number of [1, 2, 3]) {
25
25
  console.log(await debouncedFn(number));
26
26
  }
@@ -29,6 +29,6 @@ for (const number of [1, 2, 3]) {
29
29
  //=> 3
30
30
  ```
31
31
  */
32
- declare function debounce<ArgumentsType extends unknown[], ReturnType>(fn: (...args: ArgumentsType) => PromiseLike<ReturnType> | ReturnType, wait: number, options?: DebounceOptions): (...args: any[]) => Promise<unknown>;
32
+ declare function debounce<ArgumentsType extends unknown[], ReturnType>(fn: (...args: ArgumentsType) => PromiseLike<ReturnType> | ReturnType, wait?: number, options?: DebounceOptions): (...args: any[]) => Promise<unknown>;
33
33
 
34
34
  export { DebounceOptions, debounce };
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  const DEBOUNCE_DEFAULTS = {
2
2
  trailing: true
3
3
  };
4
- function debounce(fn, wait, options = {}) {
4
+ function debounce(fn, wait = 25, options = {}) {
5
5
  options = { ...DEBOUNCE_DEFAULTS, ...options };
6
6
  if (!Number.isFinite(wait)) {
7
7
  throw new TypeError("Expected `wait` to be a finite number");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perfect-debounce",
3
- "version": "0.0.1",
3
+ "version": "0.1.2",
4
4
  "description": "",
5
5
  "repository": "unjs/perfect-debounce",
6
6
  "license": "MIT",
@@ -18,14 +18,6 @@
18
18
  "files": [
19
19
  "dist"
20
20
  ],
21
- "scripts": {
22
- "build": "unbuild",
23
- "dev": "vitest dev",
24
- "lint": "eslint --ext .ts,.js,.mjs,.cjs .",
25
- "prepack": "unbuild",
26
- "release": "yarn test && standard-version && git push --follow-tags && npm publish",
27
- "test": "vitest run --coverage"
28
- },
29
21
  "dependencies": {},
30
22
  "devDependencies": {
31
23
  "@nuxtjs/eslint-config-typescript": "latest",
@@ -37,5 +29,14 @@
37
29
  "typescript": "latest",
38
30
  "unbuild": "latest",
39
31
  "vitest": "latest"
40
- }
41
- }
32
+ },
33
+ "packageManager": "pnpm@6.32.3",
34
+ "scripts": {
35
+ "build": "unbuild",
36
+ "dev": "vitest dev",
37
+ "lint": "eslint --ext .ts,.js,.mjs,.cjs .",
38
+ "release": "pnpm test && standard-version && git push --follow-tags && pnpm publish",
39
+ "test": "vitest run --coverage"
40
+ },
41
+ "readme": "# perfect-debounce\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![Github Actions][github-actions-src]][github-actions-href]\n[![Codecov][codecov-src]][codecov-href]\n\n> An improved debounce function with Promise support.\n\n- Well tested debounce implementation\n- Native Promise support\n- Avoid duplicate calls while promise is being resolved\n- Configurable `trailing` and `leading` behavior\n\n## Usage\n\nInstall package:\n\n```sh\n# npm\nnpm install perfect-debounce\n\n# yarn\nyarn install perfect-debounce\n\n# pnpm\npnpm install perfect-debounce\n```\n\nImport:\n\n```js\n// ESM\nimport { debounce } from 'perfect-debounce'\n\n// CommonJS\nconst { debounce } = require('perfect-debounce')\n```\n\nDebounce function:\n\n```js\nconst debounced = debounce(async () => {\n // Some heavy stuff\n}, 25)\n```\n\nWhen calling `debounced`, it will wait at least for `25ms` as configured before actually calling our function. This helps to avoid multiple calls.\n\nTo avoid initial wait, we can set `leading: true` option. It will cause function to be immediately called if there is no other call:\n\n```js\nconst debounced = debounce(async () => {\n // Some heavy stuff\n}, 25, { leading: true })\n```\n\nIf executing async function takes longer than debounce value, duplicate calls will be still prevented a last call will happen. To disable this behavior, we can set `trailing: false` option:\n\n```js\nconst debounced = debounce(async () => {\n // Some heavy stuff\n}, 25, { trailing: false })\n```\n\n## 💻 Development\n\n- Clone this repository\n- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable` (use `npm i -g corepack` for Node.js < 16.10)\n- Install dependencies using `pnpm install`\n- Run interactive tests using `pnpm dev`\n\n## License\n\nMade with 💛\n\nBased on [sindresorhus/p-debounce](https://github.com/sindresorhus/p-debounce).\n\nPublished under [MIT License](./LICENSE).\n\n<!-- Badges -->\n[npm-version-src]: https://img.shields.io/npm/v/perfect-debounce?style=flat-square\n[npm-version-href]: https://npmjs.com/package/perfect-debounce\n\n[npm-downloads-src]: https://img.shields.io/npm/dm/perfect-debounce?style=flat-square\n[npm-downloads-href]: https://npmjs.com/package/perfect-debounce\n\n[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/perfect-debounce/ci/main?style=flat-square\n[github-actions-href]: https://github.com/unjs/perfect-debounce/actions?query=workflow%3Aci\n\n[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/perfect-debounce/main?style=flat-square\n[codecov-href]: https://codecov.io/gh/unjs/perfect-debounce\n"
42
+ }