perfect-debounce 0.1.2 → 1.0.0

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 - UnJS
3
+ Copyright (c) Pooya Parsa <pooya@pi0.io>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -21,10 +21,10 @@ Install package:
21
21
  npm install perfect-debounce
22
22
 
23
23
  # yarn
24
- yarn install perfect-debounce
24
+ yarn add perfect-debounce
25
25
 
26
26
  # pnpm
27
- pnpm install perfect-debounce
27
+ pnpm add perfect-debounce
28
28
  ```
29
29
 
30
30
  Import:
package/dist/index.cjs CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  const DEBOUNCE_DEFAULTS = {
6
4
  trailing: true
7
5
  };
@@ -15,7 +13,7 @@ function debounce(fn, wait = 25, options = {}) {
15
13
  let resolveList = [];
16
14
  let currentPromise;
17
15
  let trailingArgs;
18
- const applyFn = async (_this, args) => {
16
+ const applyFn = (_this, args) => {
19
17
  currentPromise = _applyPromised(fn, _this, args);
20
18
  currentPromise.finally(() => {
21
19
  currentPromise = null;
package/dist/index.d.ts CHANGED
@@ -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<ArgumentsT extends unknown[], ReturnT>(fn: (...args: ArgumentsT) => PromiseLike<ReturnT> | ReturnT, wait?: number, options?: DebounceOptions): (...args: ArgumentsT) => Promise<ReturnT>;
33
33
 
34
34
  export { DebounceOptions, debounce };
package/dist/index.mjs CHANGED
@@ -11,7 +11,7 @@ function debounce(fn, wait = 25, options = {}) {
11
11
  let resolveList = [];
12
12
  let currentPromise;
13
13
  let trailingArgs;
14
- const applyFn = async (_this, args) => {
14
+ const applyFn = (_this, args) => {
15
15
  currentPromise = _applyPromised(fn, _this, args);
16
16
  currentPromise.finally(() => {
17
17
  currentPromise = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perfect-debounce",
3
- "version": "0.1.2",
3
+ "version": "1.0.0",
4
4
  "description": "",
5
5
  "repository": "unjs/perfect-debounce",
6
6
  "license": "MIT",
@@ -8,6 +8,7 @@
8
8
  "type": "module",
9
9
  "exports": {
10
10
  ".": {
11
+ "types": "./dist/index.d.ts",
11
12
  "import": "./dist/index.mjs",
12
13
  "require": "./dist/index.cjs"
13
14
  }
@@ -18,25 +19,26 @@
18
19
  "files": [
19
20
  "dist"
20
21
  ],
21
- "dependencies": {},
22
- "devDependencies": {
23
- "@nuxtjs/eslint-config-typescript": "latest",
24
- "c8": "latest",
25
- "eslint": "latest",
26
- "in-range": "^3.0.0",
27
- "standard-version": "latest",
28
- "time-span": "^5.0.0",
29
- "typescript": "latest",
30
- "unbuild": "latest",
31
- "vitest": "latest"
32
- },
33
- "packageManager": "pnpm@6.32.3",
34
22
  "scripts": {
35
23
  "build": "unbuild",
36
24
  "dev": "vitest dev",
37
- "lint": "eslint --ext .ts,.js,.mjs,.cjs .",
38
- "release": "pnpm test && standard-version && git push --follow-tags && pnpm publish",
25
+ "lint": "eslint --ext .ts,.js,.mjs,.cjs . && prettier --check src test",
26
+ "lint:fix": "eslint --ext .ts,.js,.mjs,.cjs . --fix && prettier -w src test",
27
+ "release": "pnpm test && pnpm build && changelogen --release --push && npm publish",
39
28
  "test": "vitest run --coverage"
40
29
  },
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"
30
+ "devDependencies": {
31
+ "@types/node": "^18.16.3",
32
+ "@vitest/coverage-c8": "^0.31.0",
33
+ "changelogen": "^0.5.3",
34
+ "eslint": "^8.39.0",
35
+ "eslint-config-unjs": "^0.1.0",
36
+ "in-range": "^3.0.0",
37
+ "prettier": "^2.8.8",
38
+ "time-span": "^5.1.0",
39
+ "typescript": "^5.0.4",
40
+ "unbuild": "^1.2.1",
41
+ "vitest": "^0.31.0"
42
+ },
43
+ "packageManager": "pnpm@8.4.0"
42
44
  }