attempts

1.1.0 • Public • Published

attempts npm-version

Try func with different args.

Methods

  • attempts.sync(values, fn) ⇒ result / undefined
    Invoke fn with values[n] one by one, until get a truthy return value.

  • attempts.async(values, fn) Promise (resolved with result / rejected with undefined)
    Invoke fn with values[n] one by one, until get a truthy return value or resolved Promise.

NOTE: Exceptions within fn will be catched & treated as a falsy return, handy for some Node.js API (fs.accessSync, fs.statSync, etc.) throw errors regularly.

Example

Get availiable config:

const attempts = require('attempts')
 
const readConfig = filename => require(filename)
const possibleConfigs = [
  './config.json',
  './config.default.json'
]
 
const config = attempts.sync(possibleConfigs, readConfig)

License

MIT © Amio

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.0
    4
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.1.0
    4
  • 1.0.0
    0
  • 0.0.0
    1

Package Sidebar

Install

npm i attempts

Weekly Downloads

5

Version

1.1.0

License

MIT

Last publish

Collaborators

  • amio