'use strict'

/* @flow */

module.exports = function promisify(callback: Function, throwError: boolean = true): Function {
  return function promisified(){
    const parameters = Array.from ? Array.from(arguments) : Array.prototype.slice.call(arguments)
    const parametersLength = parameters.length + 1
    let promise = new Promise((resolve, reject) => {
      parameters.push(function(error, data) {
        if (error) {
          reject(error)
        } else resolve(data)
      })
      if (parametersLength === 1) {
        callback.call(this, parameters[0])
      } else if (parametersLength === 2) {
        callback.call(this, parameters[0], parameters[1])
      } else if (parametersLength === 3) {
        callback.call(this, parameters[0], parameters[1], parameters[2])
      } else if (parametersLength === 4) {
        callback.call(this, parameters[0], parameters[1], parameters[2], parameters[3])
      } else {
        callback.apply(this, parameters)
      }
    })
    if (!throwError) {
      promise = promise.catch(function() {
        return null
      })
    }
    return promise
  }
}

@@ -24,25 +24,8 @@
 */%0A%0A
-module.exports = 
 func
@@ -1087,8 +1087,449 @@
 e%0A  %7D%0A%7D%0A
+%0Afunction promisifyAll(object: Object, throwError: boolean = true): Object %7B%0A  const duplicate = Object.assign(%7B%7D, object)%0A  for (const item in duplicate) %7B%0A    if (duplicate.hasOwnProperty(item)) %7B%0A      const value = duplicate%5Bitem%5D%0A      if (typeof value === 'function') %7B%0A        duplicate%5Bitem%5D = promisify(value, throwError)%0A      %7D%0A    %7D%0A  %7D%0A  return duplicate%0A%7D%0A%0Amodule.exports = promisify%0Amodule.exports.promisifyAll = promisifyAll%0A

Add promisifyAll helper