Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

universalify

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

universalify - npm Package Compare versions

Comparing version 0.2.0 to 1.0.0

26

index.js
'use strict'
exports.fromCallback = function (fn) {
return Object.defineProperty(function () {
if (typeof arguments[arguments.length - 1] === 'function') fn.apply(this, arguments)
return Object.defineProperty(function (...args) {
if (typeof args[args.length - 1] === 'function') fn.apply(this, args)
else {
return new Promise((resolve, reject) => {
arguments[arguments.length] = (err, res) => {
if (err) return reject(err)
resolve(res)
}
arguments.length++
fn.apply(this, arguments)
fn.apply(
this,
args.concat([(err, res) => err ? reject(err) : resolve(res)])
)
})

@@ -20,11 +18,7 @@ }

exports.fromPromise = function (fn) {
return Object.defineProperty(function () {
const cb = arguments[arguments.length - 1]
if (typeof cb !== 'function') return fn.apply(this, arguments)
else {
delete arguments[arguments.length - 1]
arguments.length--
fn.apply(this, arguments).then(r => cb(null, r), cb)
}
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 })
}
{
"name": "universalify",
"version": "0.2.0",
"version": "1.0.0",
"description": "Make a callback- or promise-based function support both promises and callbacks.",

@@ -27,9 +27,9 @@ "keywords": [

"coveralls": "^3.0.1",
"nyc": "^10.2.0",
"standard": "^10.0.1",
"nyc": "^15.0.0",
"standard": "^14.3.1",
"tape": "^4.6.3"
},
"engines": {
"node": ">= 4.0.0"
"node": ">= 10.0.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc