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

thenify

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

thenify - npm Package Compare versions

Comparing version 3.3.0 to 3.3.1

6

History.md
3.3.1 / 2020-06-18
==================
**fixes**
* [[`0d94a24`](http://github.com/thenables/thenify/commit/0d94a24eb933bc835d568f3009f4d269c4c4c17a)] - fix: remove eval (#30) (Yiyu He <<dead_horse@qq.com>>)
3.3.0 / 2017-05-19

@@ -3,0 +9,0 @@ ==================

63

index.js

@@ -10,3 +10,3 @@

*
* @param {Function} $$__fn__$$
* @param {Function} fn
* @return {Function}

@@ -16,5 +16,5 @@ * @api public

function thenify($$__fn__$$, options) {
assert(typeof $$__fn__$$ === 'function')
return eval(createWrapper($$__fn__$$.name, options))
function thenify(fn, options) {
assert(typeof fn === 'function')
return createWrapper(fn, options)
}

@@ -25,3 +25,3 @@

*
* @param {Function} $$__fn__$$
* @param {Function} fn
* @return {Function}

@@ -31,11 +31,12 @@ * @api public

thenify.withCallback = function ($$__fn__$$, options) {
assert(typeof $$__fn__$$ === 'function')
thenify.withCallback = function (fn, options) {
assert(typeof fn === 'function')
options = options || {}
options.withCallback = true
if (options.multiArgs === undefined) options.multiArgs = true
return eval(createWrapper($$__fn__$$.name, options))
return createWrapper(fn, options)
}
function createCallback(resolve, reject, multiArgs) {
// default to true
if (multiArgs === undefined) multiArgs = true
return function(err, value) {

@@ -59,27 +60,23 @@ if (err) return reject(err)

function createWrapper(name, options) {
function createWrapper(fn, options) {
options = options || {}
var name = fn.name;
name = (name || '').replace(/\s|bound(?!$)/g, '')
options = options || {}
// default to true
var multiArgs = options.multiArgs !== undefined ? options.multiArgs : true
multiArgs = 'var multiArgs = ' + JSON.stringify(multiArgs) + '\n'
var withCallback = options.withCallback ?
'var lastType = typeof arguments[len - 1]\n'
+ 'if (lastType === "function") return $$__fn__$$.apply(self, arguments)\n'
: ''
return '(function ' + name + '() {\n'
+ 'var self = this\n'
+ 'var len = arguments.length\n'
+ multiArgs
+ withCallback
+ 'var args = new Array(len + 1)\n'
+ 'for (var i = 0; i < len; ++i) args[i] = arguments[i]\n'
+ 'var lastIndex = i\n'
+ 'return new Promise(function (resolve, reject) {\n'
+ 'args[lastIndex] = createCallback(resolve, reject, multiArgs)\n'
+ '$$__fn__$$.apply(self, args)\n'
+ '})\n'
+ '})'
var newFn = function () {
var self = this
var len = arguments.length
if (options.withCallback) {
var lastType = typeof arguments[len - 1]
if (lastType === 'function') return fn.apply(self, arguments)
}
var args = new Array(len + 1)
for (var i = 0; i < len; ++i) args[i] = arguments[i]
var lastIndex = i
return new Promise(function (resolve, reject) {
args[lastIndex] = createCallback(resolve, reject, options.multiArgs)
fn.apply(self, args)
})
}
Object.defineProperty(newFn, 'name', { value: name })
return newFn
}
{
"name": "thenify",
"description": "Promisify a callback-based function",
"version": "3.3.0",
"version": "3.3.1",
"author": "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)",

@@ -6,0 +6,0 @@ "license": "MIT",

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