Comparing version 3.0.0 to 3.1.0
declare const pTap: { | ||
/** | ||
* Tap into a promise chain without affecting its value or state. Use this in a `.then()` method. | ||
* | ||
* @param tapHandler - Any return value is ignored. Exceptions thrown in `tapHandler` are relayed back to the original promise chain. If `tapHandler` returns a `Promise`, it will be awaited before passing through the original value. | ||
* @returns A [thunk](https://en.wikipedia.org/wiki/Thunk) that returns a `Promise`. | ||
*/ | ||
Tap into a promise chain without affecting its value or state. Use this in a `.then()` method. | ||
@param tapHandler - Any return value is ignored. Exceptions thrown in `tapHandler` are relayed back to the original promise chain. If `tapHandler` returns a `Promise`, it will be awaited before passing through the original value. | ||
@returns A [thunk](https://en.wikipedia.org/wiki/Thunk) that returns a `Promise`. | ||
@example | ||
``` | ||
import pTap = require('p-tap'); | ||
Promise.resolve('unicorn') | ||
.then(pTap(console.log)) // Logs `unicorn` | ||
.then(value => { | ||
// `value` is still `unicorn` | ||
}); | ||
getUser() | ||
.then(pTap(user => recordStatsAsync(user))) // Stats are saved about `user` async before the chain continues | ||
.then(user => { | ||
// `user` is the user from getUser(), not recordStatsAsync() | ||
}); | ||
``` | ||
*/ | ||
<ValueType = unknown>(tapHandler: (value: ValueType) => unknown): ( | ||
@@ -13,12 +30,25 @@ value: ValueType | ||
/** | ||
* Tap into a promise chain without affecting its value or state. Use this in a `.catch()` method. | ||
* | ||
* @param tapHandler - Any return value is ignored. Exceptions thrown in `tapHandler` are relayed back to the original promise chain. If `tapHandler` returns a `Promise`, it will be awaited before passing through the original value. | ||
* @returns A [thunk](https://en.wikipedia.org/wiki/Thunk) that returns a `Promise`. | ||
*/ | ||
Tap into a promise chain without affecting its value or state. Use this in a `.catch()` method. | ||
@param tapHandler - Any return value is ignored. Exceptions thrown in `tapHandler` are relayed back to the original promise chain. If `tapHandler` returns a `Promise`, it will be awaited before passing through the original value. | ||
@returns A [thunk](https://en.wikipedia.org/wiki/Thunk) that returns a `Promise`. | ||
@example | ||
``` | ||
import pTap = require('p-tap'); | ||
Promise.resolve(() => doSomething()) | ||
.catch(pTap.catch(console.error)) // prints any errors | ||
.then(handleSuccess) | ||
.catch(handleError); | ||
``` | ||
*/ | ||
catch<ErrorType = unknown>( | ||
tapHandler: (error: ErrorType) => unknown | ||
): (error: ErrorType) => Promise<never>; | ||
} | ||
export default pTap; | ||
// TODO: Remove this for the next major release | ||
default: typeof pTap; | ||
}; | ||
export = pTap; |
@@ -9,2 +9,3 @@ 'use strict'; | ||
module.exports = pTap; | ||
// TODO: Remove this for the next major release | ||
module.exports.default = pTap; | ||
@@ -11,0 +12,0 @@ |
{ | ||
"name": "p-tap", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Tap into a promise chain without affecting its value or state", | ||
@@ -16,3 +16,3 @@ "license": "MIT", | ||
"scripts": { | ||
"test": "xo && ava && tsd-check" | ||
"test": "xo && ava && tsd" | ||
}, | ||
@@ -41,8 +41,8 @@ "files": [ | ||
"devDependencies": { | ||
"ava": "^1.3.1", | ||
"ava": "^1.4.1", | ||
"delay": "^4.1.0", | ||
"time-span": "^3.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
5694
55