Comparing version 1.0.0 to 2.0.0
12
index.js
'use strict'; | ||
module.exports = fn => val => { | ||
const ret = () => val; | ||
return Promise.resolve(val).then(fn).then(ret, ret); | ||
module.exports = fn => value => { | ||
const ret = () => value; | ||
return Promise.resolve(value).then(fn).then(ret); | ||
}; | ||
module.exports.catch = fn => err => { | ||
const ret = () => Promise.reject(err); | ||
return Promise.resolve(err).then(fn).then(ret, ret); | ||
module.exports.catch = fn => error => { | ||
const ret = () => Promise.reject(error); | ||
return Promise.resolve(error).then(fn).then(ret); | ||
}; |
{ | ||
"name": "p-tap", | ||
"version": "1.0.0", | ||
"description": "Tap into a promise chain without affecting its value or state", | ||
"license": "MIT", | ||
"repository": "sindresorhus/p-tap", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"promise", | ||
"tap", | ||
"debug", | ||
"log", | ||
"then", | ||
"catch", | ||
"error", | ||
"chain", | ||
"pipeline", | ||
"thunk", | ||
"function", | ||
"async", | ||
"await", | ||
"promises", | ||
"bluebird" | ||
], | ||
"devDependencies": { | ||
"ava": "*", | ||
"delay": "^1.3.1", | ||
"time-span": "^1.0.0", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
"name": "p-tap", | ||
"version": "2.0.0", | ||
"description": "Tap into a promise chain without affecting its value or state", | ||
"license": "MIT", | ||
"repository": "sindresorhus/p-tap", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"promise", | ||
"tap", | ||
"debug", | ||
"log", | ||
"then", | ||
"catch", | ||
"error", | ||
"chain", | ||
"pipeline", | ||
"thunk", | ||
"function", | ||
"async", | ||
"await", | ||
"promises", | ||
"bluebird" | ||
], | ||
"devDependencies": { | ||
"ava": "*", | ||
"delay": "^3.0.0", | ||
"time-span": "^2.0.0", | ||
"xo": "*" | ||
} | ||
} |
@@ -9,3 +9,3 @@ # p-tap [![Build Status](https://travis-ci.org/sindresorhus/p-tap.svg?branch=master)](https://travis-ci.org/sindresorhus/p-tap) | ||
``` | ||
$ npm install --save p-tap | ||
$ npm install p-tap | ||
``` | ||
@@ -20,3 +20,3 @@ | ||
Promise.resolve('unicorn') | ||
.then(pTap(console.log)) // logs `unicorn` | ||
.then(pTap(console.log)) // Logs `unicorn` | ||
.then(value => { | ||
@@ -31,3 +31,3 @@ // `value` is still `unicorn` | ||
getUser() | ||
.then(tap(user => saveUser(user))) // `user` is saved async before the chain continues | ||
.then(pTap(user => recordStatsAsync(user))) // Stats are saved about `user` async before the chain continues | ||
.then(user => { | ||
@@ -66,3 +66,3 @@ // `user` is the user from getUser(), not recordStatsAsync() | ||
Any return value or exception is ignored. | ||
Any return value is ignored. Exceptions thrown in `input` are relayed back to the original promise chain. | ||
@@ -76,2 +76,3 @@ If `input` returns a `Promise`, it will be awaited before passing through the original value. | ||
- [p-if](https://github.com/sindresorhus/p-if) - Conditional promise chains | ||
- [p-catch-if](https://github.com/sindresorhus/p-catch-if) - Conditional promise catch handler | ||
- [More…](https://github.com/sindresorhus/promise-fun) | ||
@@ -78,0 +79,0 @@ |
Sorry, the diff of this file is not supported yet
3804
79