build/index.js
async function makePromise(fn, args, resolveValue) {
  const er = erotic(true)
  if (typeof fn !== 'function') {
    throw new Error('Function must be passed.')
  }
  const { length: fnLength } = fn
  if (!fnLength) {
    throw new Error('Function does not accept any arguments.')
  }

  const res = await new Promise((resolve, reject)=> {
    const cb = (err, res) => {
      if (err) {
        const error = er(err)
        return reject(error)
      }
      return resolve(resolveValue || res)
    }

    let allArgs = [cb]

    if (Array.isArray(args)) {
      args.forEach((arg, i) => {
        checkArgumentIndex(fnLength, i)
      })
      allArgs =  [...args, cb]
    } else if (Array.from(arguments).length > 1) { // args passed as a single argument, not array
      checkArgumentIndex(fnLength, 0)
      allArgs = [args, cb]
    }
    fn(...allArgs)
  })
  return res
}
async function makePromise(fn, args, resolveValue) {
  const er = erotic(true)
  if (typeof fn !== 'function') {
    throw new Error('Function must be passed.')
  }
  const { length: fnLength } = fn
  if (!fnLength) {
    throw new Error('Function does not accept any arguments.')
  }

  const res = await new Promise((resolve, reject)=> {
    const cb = (err, res) => {
      if (err) {
        const error = er(err)
        return reject(error)
      }
      return resolve(resolveValue || res)
    }

    let allArgs = [cb]

    if (Array.isArray(args)) {
      args.forEach((arg, i) => {
        checkArgumentIndex(fnLength, i)
      })
      allArgs =  [...args, cb]
    } else if (Array.from(arguments).length > 1) { // args passed as a single argument, not array
      checkArgumentIndex(fnLength, 0)
      allArgs = [args, cb]
    }
    fn(...allArgs)
  })
  return res
}
async function makePromise ( fn , args , resolveValue ) { const er = erotic ( true ) if ( typeof fn !== 'function' ) { throw new Error ( 'Function must be passed.' ) } const { length : fnLength } = fn if ( ! fnLength ) { throw new Error ( 'Function does not accept any arguments.' ) } const res = await new Promise ( ( resolve , reject ) => { const cb = ( err , res ) => { if ( err ) { const error = er ( err ) return reject ( error ) } return resolve ( resolveValue || res ) } let allArgs = [ cb ] if ( Array . isArray ( args ) ) { args . forEach ( ( arg , i ) => { checkArgumentIndex ( fnLength , i ) } ) allArgs = [ ... args , cb ] } else if ( Array . from ( arguments ) . length > 1 ) { // args passed as a single argument, not array checkArgumentIndex ( fnLength , 0 ) allArgs = [ args , cb ] } fn ( ... allArgs ) } ) return res }
Get a promise from a function which otherwise accepts a callback.
@param {Function} fn A function to promisify.
@param {*|Array<*>} [args] An array of arguments to use in the call, or a single argument.
@param {*} [resolveValue] A value to override the value with which the promise will be resolved.
@returns {Promise<*>} A promise resolved on callback invocation without an error and rejected on callback called with an error.
Get a promise from a function which otherwise accepts a callback .