index.js
function(func, resolves = false){
    if(typeof resolves !== 'boolean' && typeof resolves !== 'number' && resolves != 'all'){
      throw new Error('Invalid value submitted for \'resolves\' argument.')
    }
    return function(){
      return new Promise((resolve, reject)=>{
        var params = [...arguments, function(...args){

          //check for error hooks
          var error = false;
          for(let arg of args){
            if(arg instanceof Error){
              error = arg;
              break;
            }
          }

          if(error){
            reject(error)
          }else{
            switch(resolves){
              case false:
                resolve(arguments.length == 1 ? arguments[0] : arguments[1])
                break;
              case true:
                resolve(true)
                break;
              case 'all':
                resolve(args)
                break;
              default:
                resolve(args[resolve])
            }
          }
        }]
        func.apply(null, params)
      })
    }
  }
function(func, resolves = false){
    if(typeof resolves !== 'boolean' && typeof resolves !== 'number' && resolves != 'all'){
      throw new Error('Invalid value submitted for \'resolves\' argument.')
    }
    return function(){
      return new Promise((resolve, reject)=>{
        var params = [...arguments, function(...args){

          //check for error hooks
          var error = false;
          for(let arg of args){
            if(arg instanceof Error){
              error = arg;
              break;
            }
          }

          if(error){
            reject(error)
          }else{
            switch(resolves){
              case false:
                resolve(arguments.length == 1 ? arguments[0] : arguments[1])
                break;
              case true:
                resolve(true)
                break;
              case 'all':
                resolve(args)
                break;
              default:
                resolve(args[resolve])
            }
          }
        }]
        func.apply(null, params)
      })
    }
  }
function ( func , resolves = false ) { if ( typeof resolves !== 'boolean' && typeof resolves !== 'number' && resolves != 'all' ) { throw new Error ( 'Invalid value submitted for \'resolves\' argument.' ) } return function ( ) { return new Promise ( ( resolve , reject ) => { var params = [ ... arguments , function ( ... args ) { //check for error hooks var error = false ; for ( let arg of args ) { if ( arg instanceof Error ) { error = arg ; break ; } } if ( error ) { reject ( error ) } else { switch ( resolves ) { case false : resolve ( arguments . length == 1 ? arguments [ 0 ] : arguments [ 1 ] ) break ; case true : resolve ( true ) break ; case 'all' : resolve ( args ) break ; default : resolve ( args [ resolve ] ) } } } ] func . apply ( null , params ) } ) } }
Return a promise-based version of a callback-based async method.
Return a promise - based version of a callback - based async method .