p-log

Log the value/error of a promise

Usage no npm install needed!

<script type="module">
  import pLog from 'https://cdn.skypack.dev/p-log';
</script>

README

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ā€¦