# p-tap

> Tap into a promise chain without affecting its value or state

Latest version **4.0.0** (published 2021-04-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install p-tap
pnpm add p-tap
yarn add p-tap
bun add p-tap
```

## Health

**Score 28/100 (F)** — status: abandoned.

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2021-04-08 |
| First published | 2016-10-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/p-tap) |
| Module format | ESM |
| Node | >=12 |
| Dependencies | 0 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 134 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | promise, tap, debug, log, then, catch, error, chain, pipeline, thunk, function, async, await, promises, bluebird |

## Links

- npm: https://www.npmjs.com/package/p-tap
- Repository: https://github.com/sindresorhus/p-tap
- Homepage: https://github.com/sindresorhus/p-tap#readme
- Issues: https://github.com/sindresorhus/p-tap/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/p-tap

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 4.0.0 (latest) — 2021-04-08
- 3.1.0 — 2019-04-04
- 3.0.0 — 2019-03-12
- 2.0.0 — 2018-06-09
- 1.0.0 — 2016-10-21

## README

# p-tap

> Tap into a promise chain without affecting its value or state

## Install

```
$ npm install p-tap
```

## Usage

```js
import pTap from 'p-tap';

Promise.resolve('unicorn')
	.then(pTap(console.log)) // Logs `unicorn`
	.then(value => {
		// `value` is still `unicorn`
	});
```

```js
import pTap from 'p-tap';

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()
	});
```

```js
import pTap from 'p-tap';

Promise.resolve(() => doSomething())
	.catch(pTap.catch(console.error)) // Prints any errors
	.then(handleSuccess)
	.catch(handleError);
```

## API

### pTap(tapHandler)

Use this in a `.then()` method.

Returns a [thunk](https://en.wikipedia.org/wiki/Thunk) that returns a `Promise`.

### pTap.catch(tapHandler)

Use this in a `.catch()` method.

Returns a [thunk](https://en.wikipedia.org/wiki/Thunk) that returns a `Promise`.

#### tapHandler

Type: `Function`

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.

## Related

- [p-log](https://github.com/sindresorhus/p-log) - Log the value/error of a promise
- [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)

---
_Source: https://npm.io/package/p-tap · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
