index.js
 1  'use strict'
 2  
 3  exports.fromCallback = function (fn) {
 4    return Object.defineProperty(function () {
 5      if (typeof arguments[arguments.length - 1] === 'function') fn.apply(this, arguments)
 6      else {
 7        return new Promise((resolve, reject) => {
 8          arguments[arguments.length] = (err, res) => {
 9            if (err) return reject(err)
10            resolve(res)
11          }
12          arguments.length++
13          fn.apply(this, arguments)
14        })
15      }
16    }, 'name', { value: fn.name })
17  }
18  
19  exports.fromPromise = function (fn) {
20    return Object.defineProperty(function () {
21      const cb = arguments[arguments.length - 1]
22      if (typeof cb !== 'function') return fn.apply(this, arguments)
23      else fn.apply(this, arguments).then(r => cb(null, r), cb)
24    }, 'name', { value: fn.name })
25  }