JSPM

promise-find

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q43441F
  • License MIT

Find the promise call that satisfies the testing function

Package Exports

  • promise-find

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (promise-find) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

promise-find

Build Status Code Style Known Vulnerabilities

Find the promise call that satisfies the testing function.

Installation

npm install promise-find

Usage

const promiseFind = require('promise-find')

promiseFind([
  () => Promise.resolve(null),
  () => Promise.resolve('match'),
  () => Promise.reject(new Error('never called')),
  () => Promise.resolve('never called either')
]).then(function(result) {
  console.log(result) // prints 'match'
})

API

promiseFind(list, test)

Returns a Promise that will resolve to the result of the first function call that passes the test or null if no one passes the test. If any function fails, the promise will be a rejected the error.

list

An array of functions that receive no arguments and return either a value or a promis.

test

The function used to check for a match. It defaults to the "identity" function so any truthy value will pass.

License

MIT