"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = promisify;

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

function promisify(fn) {
  return function () {
    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return new Promise(function (resolve, reject) {
      fn.apply(undefined, _toConsumableArray(args).concat([function (err, res) {
        if (err) return reject(err);
        return resolve(res);
      }]));
    });
  };
}