PHP 7.4.33
Preview: index.js Size: 712 B
/usr/share/nodejs/universalify/index.js
'use strict'

exports.fromCallback = function (fn) {
  return Object.defineProperty(function (...args) {
    if (typeof args[args.length - 1] === 'function') fn.apply(this, args)
    else {
      return new Promise((resolve, reject) => {
        fn.call(
          this,
          ...args,
          (err, res) => (err != null) ? reject(err) : resolve(res)
        )
      })
    }
  }, 'name', { value: fn.name })
}

exports.fromPromise = function (fn) {
  return Object.defineProperty(function (...args) {
    const cb = args[args.length - 1]
    if (typeof cb !== 'function') return fn.apply(this, args)
    else fn.apply(this, args.slice(0, -1)).then(r => cb(null, r), cb)
  }, 'name', { value: fn.name })
}

Directory Contents

Dirs: 0 × Files: 2
Name Size Perms Modified Actions
712 B lrw-r--r-- 2020-07-25 13:33:03
Edit Download
821 B lrw-r--r-- 2020-07-25 13:33:03
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).