p-log
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

p-log

Log the value/error of a promise

Install

$ npm install p-log

Usage

import pLog from 'p-log';

Promise.resolve('unicorn')
	.then(pLog()) // Logs `unicorn`
	.then(value => {
		// `value` is still `unicorn`
	});
import pLog from 'p-log';

Promise.resolve()
	.then(() => {
		throw new Error('pony');
	})
	.catch(pLog.catch()) // Logs `Error: pony`
	.catch(error => {
		// `error` is still `Error: pony`
	});

API

pLog(logger?)

Use this in a .then() method.

Returns a thunk that returns a Promise.

pLog.catch(logger?)

Use this in a .catch() method.

Returns a thunk that returns a Promise.

logger

Type: Function
Default: console.log

The logger to use. Any return value or exception is ignored.

Related

  • p-tap - Tap into a promise chain without affecting its value or state
  • p-if - Conditional promise chains
  • p-catch-if - Conditional promise catch handler
  • More…

Package Sidebar

Install

npm i p-log

Weekly Downloads

613

Version

3.0.0

License

MIT

Unpacked Size

4.59 kB

Total Files

5

Last publish

Collaborators

  • sindresorhus