@common.js/p-throttle 6.1.0 → 6.2.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/README.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  The [p-throttle](https://www.npmjs.com/package/p-throttle) package exported as CommonJS modules.
4
4
 
5
- Exported from [p-throttle@6.1.0](https://www.npmjs.com/package/p-throttle/v/6.1.0) using https://github.com/etienne-martin/common.js.
5
+ Exported from [p-throttle@6.2.0](https://www.npmjs.com/package/p-throttle/v/6.2.0) using https://github.com/etienne-martin/common.js.
package/index.d.ts CHANGED
@@ -44,7 +44,7 @@ export type Options = {
44
44
  readonly strict?: boolean;
45
45
 
46
46
  /**
47
- Get notified when function calls are delayed due to exceeding the `limit` of allowed calls within the given `interval`.
47
+ Get notified when function calls are delayed due to exceeding the `limit` of allowed calls within the given `interval`. The delayed call arguments are passed to the `onDelay` callback.
48
48
 
49
49
  Can be useful for monitoring the throttling efficiency.
50
50
 
@@ -55,25 +55,25 @@ export type Options = {
55
55
  const throttle = pThrottle({
56
56
  limit: 2,
57
57
  interval: 1000,
58
- onDelay: () => {
59
- console.log('Reached interval limit, call is delayed');
58
+ onDelay: (a, b) => {
59
+ console.log(`Reached interval limit, call is delayed for ${a} ${b}`);
60
60
  },
61
61
  });
62
62
 
63
- const throttled = throttle(() => {
64
- console.log('Executing...');
63
+ const throttled = throttle((a, b) => {
64
+ console.log(`Executing with ${a} ${b}...`);
65
65
  });
66
66
 
67
- await throttled();
68
- await throttled();
69
- await throttled();
70
- //=> Executing...
71
- //=> Executing...
72
- //=> Reached interval limit, call is delayed
73
- //=> Executing...
67
+ await throttled(1, 2);
68
+ await throttled(3, 4);
69
+ await throttled(5, 6);
70
+ //=> Executing with 1 2...
71
+ //=> Executing with 3 4...
72
+ //=> Reached interval limit, call is delayed for 5 6
73
+ //=> Executing with 5 6...
74
74
  ```
75
75
  */
76
- readonly onDelay?: () => void;
76
+ readonly onDelay?: (...arguments_: readonly any[]) => void;
77
77
  };
78
78
 
79
79
  /**
package/index.js CHANGED
@@ -16,6 +16,14 @@ _export(exports, {
16
16
  return pThrottle;
17
17
  }
18
18
  });
19
+ function _arrayLikeToArray(arr, len) {
20
+ if (len == null || len > arr.length) len = arr.length;
21
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
22
+ return arr2;
23
+ }
24
+ function _arrayWithoutHoles(arr) {
25
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
26
+ }
19
27
  function _assertThisInitialized(self) {
20
28
  if (self === void 0) {
21
29
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
@@ -106,6 +114,12 @@ function _inherits(subClass, superClass) {
106
114
  function _isNativeFunction(fn) {
107
115
  return Function.toString.call(fn).indexOf("[native code]") !== -1;
108
116
  }
117
+ function _iterableToArray(iter) {
118
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
119
+ }
120
+ function _nonIterableSpread() {
121
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
122
+ }
109
123
  function _possibleConstructorReturn(self, call) {
110
124
  if (call && (_typeof(call) === "object" || typeof call === "function")) {
111
125
  return call;
@@ -119,10 +133,21 @@ function _setPrototypeOf(o, p) {
119
133
  };
120
134
  return _setPrototypeOf(o, p);
121
135
  }
136
+ function _toConsumableArray(arr) {
137
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
138
+ }
122
139
  var _typeof = function(obj) {
123
140
  "@swc/helpers - typeof";
124
141
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
125
142
  };
143
+ function _unsupportedIterableToArray(o, minLen) {
144
+ if (!o) return;
145
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
146
+ var n = Object.prototype.toString.call(o).slice(8, -1);
147
+ if (n === "Object" && o.constructor) n = o.constructor.name;
148
+ if (n === "Map" || n === "Set") return Array.from(n);
149
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
150
+ }
126
151
  function _wrapNativeSuper(Class) {
127
152
  var _cache = typeof Map === "function" ? new Map() : undefined;
128
153
  _wrapNativeSuper = function _wrapNativeSuper(Class) {
@@ -355,7 +380,7 @@ function pThrottle(param) {
355
380
  if (delay > 0) {
356
381
  timeoutId = setTimeout(execute, delay);
357
382
  queue.set(timeoutId, reject);
358
- onDelay === null || onDelay === void 0 ? void 0 : onDelay();
383
+ onDelay === null || onDelay === void 0 ? void 0 : onDelay.apply(void 0, _toConsumableArray(arguments_));
359
384
  } else {
360
385
  execute();
361
386
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@common.js/p-throttle",
3
- "version": "6.1.0",
3
+ "version": "6.2.0",
4
4
  "description": "p-throttle package exported as CommonJS modules",
5
5
  "license": "MIT",
6
6
  "repository": "etienne-martin/common.js",