@common.js/debounce-fn 5.1.2 → 6.0.1

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
@@ -2,4 +2,4 @@
2
2
 
3
3
  The [debounce-fn](https://www.npmjs.com/package/debounce-fn) package exported as CommonJS modules.
4
4
 
5
- Exported from [debounce-fn@5.1.2](https://www.npmjs.com/package/debounce-fn/v/5.1.2) using https://github.com/etienne-martin/common.js.
5
+ Exported from [debounce-fn@6.0.0](https://www.npmjs.com/package/debounce-fn/v/6.0.0) using https://github.com/etienne-martin/common.js.
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export interface Options {
1
+ export type Options = {
2
2
  /**
3
3
  Time in milliseconds to wait until the `input` function is called.
4
4
 
@@ -30,21 +30,21 @@ export interface Options {
30
30
  @default true
31
31
  */
32
32
  readonly after?: boolean;
33
- }
33
+ };
34
34
 
35
- export interface BeforeOptions extends Options {
35
+ export type BeforeOptions = {
36
36
  readonly before: true;
37
- }
37
+ } & Options;
38
38
 
39
- export interface NoBeforeNoAfterOptions extends Options {
39
+ export type NoBeforeNoAfterOptions = {
40
40
  readonly after: false;
41
41
  readonly before?: false;
42
- }
42
+ } & Options;
43
43
 
44
- export interface DebouncedFunction<ArgumentsType extends unknown[], ReturnType> {
44
+ export type DebouncedFunction<ArgumentsType extends unknown[], ReturnType> = {
45
45
  (...arguments: ArgumentsType): ReturnType;
46
46
  cancel(): void;
47
- }
47
+ };
48
48
 
49
49
  /**
50
50
  [Debounce](https://davidwalsh.name/javascript-debounce-function) a function.
@@ -63,19 +63,17 @@ window.onresize = debounceFn(() => {
63
63
  }, {wait: 100});
64
64
  ```
65
65
  */
66
- declare function debounceFn<ArgumentsType extends unknown[], ReturnType>(
66
+ export default function debounceFn<ArgumentsType extends unknown[], ReturnType>(
67
67
  input: (...arguments: ArgumentsType) => ReturnType,
68
68
  options: BeforeOptions
69
69
  ): DebouncedFunction<ArgumentsType, ReturnType>;
70
70
 
71
- declare function debounceFn<ArgumentsType extends unknown[], ReturnType>(
71
+ export default function debounceFn<ArgumentsType extends unknown[], ReturnType>(
72
72
  input: (...arguments: ArgumentsType) => ReturnType,
73
73
  options: NoBeforeNoAfterOptions
74
74
  ): DebouncedFunction<ArgumentsType, undefined>;
75
75
 
76
- declare function debounceFn<ArgumentsType extends unknown[], ReturnType>(
76
+ export default function debounceFn<ArgumentsType extends unknown[], ReturnType>(
77
77
  input: (...arguments: ArgumentsType) => ReturnType,
78
78
  options?: Options
79
79
  ): DebouncedFunction<ArgumentsType, ReturnType | undefined>;
80
-
81
- export default debounceFn;
package/index.js CHANGED
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "default", {
8
8
  return _default;
9
9
  }
10
10
  });
11
- var _mimicFn = /*#__PURE__*/ _interopRequireDefault(require("mimic-fn"));
11
+ var _mimicFunction = /*#__PURE__*/ _interopRequireDefault(require("mimic-function"));
12
12
  function _interopRequireDefault(obj) {
13
13
  return obj && obj.__esModule ? obj : {
14
14
  default: obj
@@ -18,12 +18,15 @@ var _typeof = function(obj) {
18
18
  "@swc/helpers - typeof";
19
19
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
20
20
  };
21
- var debounceFn = function(inputFunction) {
21
+ var debounceFunction = function(inputFunction) {
22
22
  var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
23
23
  if (typeof inputFunction !== "function") {
24
24
  throw new TypeError("Expected the first argument to be a function, got `".concat(typeof inputFunction === "undefined" ? "undefined" : _typeof(inputFunction), "`"));
25
25
  }
26
26
  var _wait = options.wait, wait = _wait === void 0 ? 0 : _wait, _maxWait = options.maxWait, maxWait = _maxWait === void 0 ? Number.POSITIVE_INFINITY : _maxWait, _before = options.before, before = _before === void 0 ? false : _before, _after = options.after, after = _after === void 0 ? true : _after;
27
+ if (wait < 0 || maxWait < 0) {
28
+ throw new RangeError("`wait` and `maxWait` must not be negative.");
29
+ }
27
30
  if (!before && !after) {
28
31
  throw new Error("Both `before` and `after` are false, function wouldn't be called.");
29
32
  }
@@ -66,7 +69,7 @@ var debounceFn = function(inputFunction) {
66
69
  }
67
70
  return result;
68
71
  };
69
- (0, _mimicFn.default)(debouncedFunction, inputFunction);
72
+ (0, _mimicFunction.default)(debouncedFunction, inputFunction);
70
73
  debouncedFunction.cancel = function() {
71
74
  if (timeout) {
72
75
  clearTimeout(timeout);
@@ -79,4 +82,4 @@ var debounceFn = function(inputFunction) {
79
82
  };
80
83
  return debouncedFunction;
81
84
  };
82
- var _default = debounceFn;
85
+ var _default = debounceFunction;
package/package.json CHANGED
@@ -1,13 +1,18 @@
1
1
  {
2
2
  "name": "@common.js/debounce-fn",
3
- "version": "5.1.2",
4
- "description": "Debounce a function",
3
+ "version": "6.0.1",
4
+ "description": "debounce-fn package exported as CommonJS modules",
5
5
  "license": "MIT",
6
6
  "repository": "etienne-martin/common.js",
7
7
  "funding": "https://github.com/sponsors/sindresorhus",
8
8
  "type": "commonjs",
9
+ "exports": {
10
+ "types": "./index.d.ts",
11
+ "default": "./index.js"
12
+ },
13
+ "sideEffects": false,
9
14
  "engines": {
10
- "node": ">=12"
15
+ "node": ">=18"
11
16
  },
12
17
  "scripts": {
13
18
  "test": "xo && ava && tsd"
@@ -17,14 +22,23 @@
17
22
  "index.d.ts"
18
23
  ],
19
24
  "dependencies": {
20
- "@common.js/mimic-fn": "^4.0.0"
25
+ "mimic-function": "npm:@common.js/mimic-function@5.0.2"
21
26
  },
22
27
  "devDependencies": {
23
- "ava": "^3.15.0",
24
- "delay": "^5.0.0",
25
- "tsd": "^0.19.1",
26
- "xo": "^0.47.0"
28
+ "ava": "^5.3.1",
29
+ "delay": "^6.0.0",
30
+ "tsd": "^0.29.0",
31
+ "xo": "^0.56.0"
27
32
  },
28
33
  "homepage": "https://github.com/etienne-martin/common.js#readme",
29
- "main": "./index.js"
34
+ "commonjs": {
35
+ "source": {
36
+ "name": "debounce-fn",
37
+ "version": "6.0.0"
38
+ },
39
+ "transformRevision": 1,
40
+ "buildKey": "e8254f4a12d0b434b37d45e205ac08fbe26c5b221b643e7c2a0540b0266a4663"
41
+ },
42
+ "main": "./index.js",
43
+ "types": "./index.d.ts"
30
44
  }
package/readme.md DELETED
@@ -1,73 +0,0 @@
1
- # debounce-fn
2
-
3
- > [Debounce](https://davidwalsh.name/javascript-debounce-function) a function
4
-
5
- ## Install
6
-
7
- ```sh
8
- npm install debounce-fn
9
- ```
10
-
11
- ## Usage
12
-
13
- ```js
14
- import debounceFn from 'debounce-fn';
15
-
16
- window.onresize = debounceFn(() => {
17
- // Do something on window resize
18
- }, {wait: 100});
19
- ```
20
-
21
- ## API
22
-
23
- ### debounceFn(input, options?)
24
-
25
- Returns a debounced function that delays calling the `input` function until after `wait` milliseconds have elapsed since the last time the debounced function was called.
26
-
27
- It comes with a `.cancel()` method to cancel any scheduled `input` function calls.
28
-
29
- #### input
30
-
31
- Type: `Function`
32
-
33
- Function to debounce.
34
-
35
- #### options
36
-
37
- Type: `object`
38
-
39
- ##### wait
40
-
41
- Type: `number`\
42
- Default: `0`
43
-
44
- Time in milliseconds to wait until the `input` function is called.
45
-
46
- ##### maxWait
47
-
48
- Type: `number`\
49
- Default: `Infinity`
50
-
51
- The maximum time the `input` function is allowed to be delayed before it's invoked.
52
-
53
- This can be used to limit the number of calls handled in a constant stream. For example, a media player sending updates every few milliseconds but wants to be handled only once a second.
54
-
55
- ##### before
56
-
57
- Type: `boolean`\
58
- Default: `false`
59
-
60
- Trigger the function on the leading edge of the `wait` interval.
61
-
62
- For example, can be useful for preventing accidental double-clicks on a "submit" button from firing a second time.
63
-
64
- ##### after
65
-
66
- Type: `boolean`\
67
- Default: `true`
68
-
69
- Trigger the function on the trailing edge of the `wait` interval.
70
-
71
- ## Related
72
-
73
- - [p-debounce](https://github.com/sindresorhus/p-debounce) - Debounce promise-returning & async functions