@midmare/argify
v2.0.3
Published
named arguments
Downloads
9
Readme
Argify
Simple library that can compare arguments to one object like named/unnamed.
const { argify, na } = require('@midmare/argify');
// Supporting default value
// Supporting ArrowFunction
const someFnArgifyAF = argify((a,b = 10,c, __kwargs) => {
console.log(a,b,c, __kwargs);
});
someFnArgifyAF(1,undefined, 123); // 1,10,c, __kwargs {}
// You can use `__kwargs` in any part of your arguments
// Supporting FunctionDeclaration
const someFnArgifyFD = argify(function(a, __kwargs,b,c) {
console.log(a,__kwargs, b,c);
});
someFnArgifyFD.bind(null, 1)(2,3);
// If arguments less, __kwargs anyway will be on place where you set it
// Supporting FunctionGeneratorDeclaration
const someFnArgifyFGD = argify(function* (a,b,c, __kwargs) {
console.log(__kwargs);
});
someFnArgifyFGD(1); // __kwargs {}
// You can use named arguments in any part of function an be sure that it will be in place
const someFnArgifyFD2 = argify(function (a,b,__kwargs) {
console.log(a,b,c,__kwargs.argumentName);
});
someFnArgifyFD2(1,na("argumentName", 999),3);
someFnArgifyFD2(1,3,na("argumentName", 999));