Comparing version
'use strict'; | ||
var promisify = require('es6-promisify').promisify; | ||
var currify = require('currify/legacy'); | ||
module.exports = function (fn, ctx) { | ||
check(fn); | ||
checkCount(fn.length); | ||
var f = fn.bind(ctx); | ||
var funcs = [function (a) { | ||
return promisify(f, ctx)(a); | ||
}, function (a, b) { | ||
return promisify(f, ctx)(a, b); | ||
}, function (a, b, c) { | ||
return promisify(f, ctx)(a, b, c); | ||
}, function (a, b, c, d) { | ||
return promisify(f, ctx)(a, b, c, d); | ||
}, function (a, b, c, d, e) { | ||
return promisify(f, ctx)(a, b, c, d, e); | ||
}, function (a, b, c, d, e, x) { | ||
return promisify(f, ctx)(a, b, c, d, e, x); | ||
}, function (a, b, c, d, e, x, g) { | ||
return promisify(f, ctx)(a, b, c, d, e, x, g); | ||
}]; | ||
var count = f.length - 2; | ||
return currify(funcs[count]); | ||
check(fn); | ||
checkCount(fn.length); | ||
var f = fn.bind(ctx); | ||
var funcs = [function (a) { | ||
return promisify(f, ctx)(a); | ||
}, function (a, b) { | ||
return promisify(f, ctx)(a, b); | ||
}, function (a, b, c) { | ||
return promisify(f, ctx)(a, b, c); | ||
}, function (a, b, c, d) { | ||
return promisify(f, ctx)(a, b, c, d); | ||
}, function (a, b, c, d, e) { | ||
return promisify(f, ctx)(a, b, c, d, e); | ||
}, function (a, b, c, d, e, x) { | ||
return promisify(f, ctx)(a, b, c, d, e, x); | ||
}, function (a, b, c, d, e, x, g) { | ||
return promisify(f, ctx)(a, b, c, d, e, x, g); | ||
}]; | ||
var count = f.length - 2; | ||
return currify(funcs[count]); | ||
}; | ||
function check(fn) { | ||
if (typeof fn !== 'function') throw Error('fn should be a function!'); | ||
if (typeof fn !== 'function') throw Error('fn should be a function!'); | ||
} | ||
function checkCount(count) { | ||
if (count > 8) throw Error('fn takes to much arguments, up to 8 supported'); | ||
if (count > 8) throw Error('fn takes to much arguments, up to 8 supported'); | ||
} |
{ | ||
"name": "zames", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", | ||
@@ -40,3 +40,3 @@ "description": "converts callback-based functions to Promises and apply currying to arguments", | ||
"dependencies": { | ||
"currify": "^2.0.0", | ||
"currify": "^3.0.0", | ||
"es6-promisify": "^6.0.0" | ||
@@ -46,11 +46,12 @@ }, | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-preset-env": "^1.6.1", | ||
"@babel/cli": "^7.0.0", | ||
"@babel/core": "^7.0.0", | ||
"@babel/preset-env": "^7.0.0", | ||
"coveralls": "^3.0.0", | ||
"eslint": "^4.0.0", | ||
"eslint": "^5.6.0", | ||
"nodemon": "^1.11.0", | ||
"nyc": "^11.0.2", | ||
"redrun": "^6.0.0", | ||
"nyc": "^13.0.1", | ||
"redrun": "^7.0.0", | ||
"tape": "^4.5.1" | ||
} | ||
} |
@@ -80,7 +80,7 @@ # Zames [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage Status][CoverageIMGURL]][CoverageURL] | ||
[BuildStatusIMGURL]: https://img.shields.io/travis/coderaiser/zames/master.svg?style=flat | ||
[DependencyStatusIMGURL]: https://img.shields.io/gemnasium/coderaiser/zames.svg?style=flat | ||
[DependencyStatusIMGURL]: https://img.shields.io/david/coderaiser/zames.svg?style=flat | ||
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat | ||
[NPMURL]: https://npmjs.org/package/zames "npm" | ||
[BuildStatusURL]: https://travis-ci.org/coderaiser/zames "Build Status" | ||
[DependencyStatusURL]: https://gemnasium.com/coderaiser/zames "Dependency Status" | ||
[DependencyStatusURL]: https://david-dm.org/coderaiser/zames "Dependency Status" | ||
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License" | ||
@@ -87,0 +87,0 @@ |
Sorry, the diff of this file is not supported yet
8590
1.75%9
12.5%+ Added
- Removed
Updated