Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Node.js 6, add TypeScript definition (#5)
- Loading branch information
1 parent
70c0c3f
commit 126eb89
Showing
11 changed files
with
100 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
* text=auto | ||
*.js text eol=lf | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- '10' | ||
- '8' | ||
- '6' | ||
- '4' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export interface Options { | ||
/** | ||
* Call the `fn` on the [leading edge of the timeout](https://css-tricks.com/debouncing-throttling-explained-examples/#article-header-id-1). Meaning immediately, instead of waiting for `wait` milliseconds. | ||
* | ||
* @default false | ||
*/ | ||
readonly leading?: boolean; | ||
} | ||
|
||
/** | ||
* [Debounce](https://css-tricks.com/debouncing-throttling-explained-examples/) promise-returning & async functions. | ||
* | ||
* @param fn - Promise-returning/async function to debounce. | ||
* @param wait - Milliseconds to wait before calling `fn`. | ||
* @returns Returns a function that delays calling `fn` until after `wait` milliseconds have elapsed since the last time it was called. | ||
*/ | ||
export default function pDebounce<ArgumentsType extends unknown[], ReturnType>( | ||
fn: (...arguments: ArgumentsType) => PromiseLike<ReturnType> | ReturnType, | ||
wait: number, | ||
options?: Options | ||
): (...arguments: ArgumentsType) => Promise<ReturnType>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {expectType} from 'tsd-check'; | ||
import pDebounce from '.'; | ||
|
||
const expensiveCall = (input: number) => Promise.resolve(input); | ||
|
||
expectType<(input: number) => Promise<number>>(pDebounce(expensiveCall, 200)); | ||
expectType<(input: number) => Promise<number>>( | ||
pDebounce(expensiveCall, 200, {leading: true}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,54 @@ | ||
{ | ||
"name": "p-debounce", | ||
"version": "1.0.0", | ||
"description": "Debounce promise-returning & async functions", | ||
"license": "MIT", | ||
"repository": "sindresorhus/p-debounce", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"promise", | ||
"debounce", | ||
"debounced", | ||
"limit", | ||
"limited", | ||
"concurrency", | ||
"throttle", | ||
"throat", | ||
"limited", | ||
"interval", | ||
"rate", | ||
"batch", | ||
"ratelimit", | ||
"task", | ||
"queue", | ||
"async", | ||
"await", | ||
"promises", | ||
"bluebird" | ||
], | ||
"devDependencies": { | ||
"ava": "*", | ||
"delay": "^1.3.1", | ||
"in-range": "^1.0.0", | ||
"time-span": "^1.0.0", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
"name": "p-debounce", | ||
"version": "1.0.0", | ||
"description": "Debounce promise-returning & async functions", | ||
"license": "MIT", | ||
"repository": "sindresorhus/p-debounce", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd-check" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"promise", | ||
"debounce", | ||
"debounced", | ||
"limit", | ||
"limited", | ||
"concurrency", | ||
"throttle", | ||
"throat", | ||
"limited", | ||
"interval", | ||
"rate", | ||
"batch", | ||
"ratelimit", | ||
"task", | ||
"queue", | ||
"async", | ||
"await", | ||
"promises", | ||
"bluebird" | ||
], | ||
"devDependencies": { | ||
"ava": "^1.3.1", | ||
"delay": "^4.1.0", | ||
"in-range": "^1.0.0", | ||
"time-span": "^2.0.0", | ||
"tsd-check": "^0.3.0", | ||
"xo": "^0.24.0" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters