1.0.2 • Published 3 years ago

@blinkmobile/maybe-run v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

Maybe run

This is not the Maybe Monad, it is a utility to make working with Promises and NodeJS callback errors a little nicer.

Usage

const maybeRun = require('@blinkmobile/maybe-run')

function writeFileContents (p, contents) {
  return new Promise((resolve, reject) => {
    const notError = maybeRun(reject)
    const dirname = path.dirname(p)

    mkdirp(dirname, (err) => {
      if (notError(err)) {
        fs.writeFile(p, contents, (err) => {
          notError(err) && resolve(p)
        })
      }
    })
  })
}