p-throttle
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -1,43 +0,57 @@ | ||
export class AbortError extends Error { | ||
declare class AbortErrorClass extends Error { | ||
readonly name: 'AbortError'; | ||
/** | ||
* Abort pending execution. All unresolved promised are rejected with a `AbortError` error. | ||
*/ | ||
Abort pending execution. All unresolved promised are rejected with a `AbortError` error. | ||
*/ | ||
constructor(); | ||
} | ||
export type ThrottledFunction<Arguments extends unknown[], Return> = (( | ||
...arguments: Arguments | ||
) => Promise<Return>) & { | ||
declare namespace pThrottle { | ||
type ThrottledFunction<Arguments extends unknown[], Return> = (( | ||
...arguments: Arguments | ||
) => Promise<Return>) & { | ||
/** | ||
Abort pending executions. All unresolved promises are rejected with a `pThrottle.AbortError` error. | ||
*/ | ||
abort(): void; | ||
}; | ||
type AbortError = AbortErrorClass; | ||
} | ||
declare const pThrottle: { | ||
/** | ||
* Abort pending executions. All unresolved promises are rejected with a `pThrottle.AbortError` error. | ||
*/ | ||
abort(): void; | ||
[Throttle](https://css-tricks.com/debouncing-throttling-explained-examples/) promise-returning/async/normal functions. | ||
@param fn - Promise-returning/async function or a normal function. | ||
@param limit - Maximum number of calls within an `interval`. | ||
@param interval - Timespan for `limit` in milliseconds. | ||
@returns A throttled version of `fn`. | ||
@example | ||
``` | ||
import pThrottle from 'p-throttle'; | ||
const throttled = pThrottle(async index => { | ||
return index * 2; | ||
}, 2, 1000); | ||
for (let i = 1; i <= 6; i++) { | ||
throttled(i).then(console.log); | ||
} | ||
``` | ||
*/ | ||
<Arguments extends unknown[], Return>( | ||
fn: (...arguments: Arguments) => PromiseLike<Return> | Return, | ||
limit: number, | ||
interval: number | ||
): pThrottle.ThrottledFunction<Arguments, Return>; | ||
AbortError: typeof AbortErrorClass; | ||
// TODO: Remove this for the next major release | ||
default: typeof pThrottle; | ||
}; | ||
/** | ||
* [Throttle](https://css-tricks.com/debouncing-throttling-explained-examples/) promise-returning/async/normal functions. | ||
* | ||
* @param fn - Promise-returning/async function or a normal function. | ||
* @param limit - Maximum number of calls within an `interval`. | ||
* @param interval - Timespan for `limit` in milliseconds. | ||
* @returns A throttled version of `fn`. | ||
* | ||
* @example | ||
* | ||
* import pThrottle from 'p-throttle'; | ||
* | ||
* const throttled = pThrottle(async index => { | ||
* return index * 2; | ||
* }, 2, 1000); | ||
* | ||
* for (let i = 1; i <= 6; i++) { | ||
* throttled(i).then(console.log); | ||
* } | ||
*/ | ||
export default function<Arguments extends unknown[], Return>( | ||
fn: (...arguments: Arguments) => PromiseLike<Return> | Return, | ||
limit: number, | ||
interval: number | ||
): ThrottledFunction<Arguments, Return>; | ||
export = pThrottle; |
@@ -63,3 +63,4 @@ 'use strict'; | ||
module.exports = pThrottle; | ||
// TODO: Remove this for the next major release | ||
module.exports.default = pThrottle; | ||
module.exports.AbortError = AbortError; |
{ | ||
"name": "p-throttle", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Throttle promise-returning & async functions", | ||
@@ -16,3 +16,3 @@ "license": "MIT", | ||
"scripts": { | ||
"test": "xo && ava && tsd-check" | ||
"test": "xo && ava && tsd" | ||
}, | ||
@@ -44,9 +44,9 @@ "files": [ | ||
"devDependencies": { | ||
"ava": "^1.2.1", | ||
"ava": "^1.4.1", | ||
"delay": "^4.1.0", | ||
"in-range": "^1.0.0", | ||
"time-span": "^2.0.0", | ||
"tsd-check": "^0.3.0", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6432
97