Sha256: 153453c4d84a3c2f13589c37055a7daff61d48475dcce554f7eedad15fc7b3e5

Contents?: true

Size: 905 Bytes

Versions: 1024

Compression:

Stored size: 905 Bytes

Contents

// Returns a wrapper function that returns a wrapped callback
// The wrapper function should do some stuff, and return a
// presumably different callback function.
// This makes sure that own properties are retained, so that
// decorations and such are not lost along the way.
module.exports = wrappy
function wrappy (fn, cb) {
  if (fn && cb) return wrappy(fn)(cb)

  if (typeof fn !== 'function')
    throw new TypeError('need wrapper function')

  Object.keys(fn).forEach(function (k) {
    wrapper[k] = fn[k]
  })

  return wrapper

  function wrapper() {
    var args = new Array(arguments.length)
    for (var i = 0; i < args.length; i++) {
      args[i] = arguments[i]
    }
    var ret = fn.apply(this, args)
    var cb = args[args.length-1]
    if (typeof ret === 'function' && ret !== cb) {
      Object.keys(cb).forEach(function (k) {
        ret[k] = cb[k]
      })
    }
    return ret
  }
}

Version data entries

1,024 entries across 402 versions & 46 rubygems

Version Path
opal-1.8.0.beta1 stdlib/nodejs/node_modules/wrappy/wrappy.js
immosquare-cleaner-0.1.14 node_modules/wrappy/wrappy.js
immosquare-cleaner-0.1.13 node_modules/wrappy/wrappy.js
immosquare-cleaner-0.1.12 node_modules/wrappy/wrappy.js
immosquare-cleaner-0.1.11 node_modules/wrappy/wrappy.js
immosquare-cleaner-0.1.10 node_modules/wrappy/wrappy.js
immosquare-cleaner-0.1.9 node_modules/wrappy/wrappy.js
immosquare-cleaner-0.1.8 node_modules/wrappy/wrappy.js
immosquare-cleaner-0.1.7 node_modules/wrappy/wrappy.js
immosquare-cleaner-0.1.6 node_modules/wrappy/wrappy.js
opal-1.7.4 stdlib/nodejs/node_modules/wrappy/wrappy.js
opal-1.8.0.alpha1 stdlib/nodejs/node_modules/wrappy/wrappy.js
decidim-0.26.8 packages/eslint-config/node_modules/wrappy/wrappy.js
reed_sdk-1.0.1 node_modules/wrappy/wrappy.js
reed_sdk-1.0.0 node_modules/wrappy/wrappy.js
boring_generators-0.12.0 tmp/templates/app_template/node_modules/wrappy/wrappy.js
opal-1.7.3 stdlib/nodejs/node_modules/wrappy/wrappy.js
opal-1.7.2 stdlib/nodejs/node_modules/wrappy/wrappy.js
opal-1.7.1 stdlib/nodejs/node_modules/wrappy/wrappy.js
opal-1.7.0 stdlib/nodejs/node_modules/wrappy/wrappy.js