https://github.com/ddo/fn-arg
handle optional function arguments
https://github.com/ddo/fn-arg
Last synced: 5 months ago
JSON representation
handle optional function arguments
- Host: GitHub
- URL: https://github.com/ddo/fn-arg
- Owner: ddo
- License: mit
- Created: 2014-10-12T17:16:21.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-10-13T07:57:15.000Z (over 11 years ago)
- Last Synced: 2025-09-14T11:55:48.193Z (9 months ago)
- Language: JavaScript
- Size: 148 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
fn-arg
======
handle optional function arguments
##installation
```bash
$ npm i fn-arg
```
##example
```js
var Args = require('fn-arg');
function i_handle_many_arguments(a, b, c, d, callback) {
//set rules
var args = Args({
2: ['a', 'callback'],
3: ['a', 'b', 'callback'],
4: ['a', 'b', 'c', 'callback'],
5: ['a', 'b', 'c', 'd', 'callback'] // require
});
//update the params
a = args.a;
b = args.b;
c = args.c;
d = args.d;
callback = args.callback;
console.log(args);
}
testing('a_val');
// => false
testing('a_val', function callback(){});
// => { a: 'a_val', callback: [Function: callback] }
testing('a_val', 'b_val', function callback(){});
// => { a: 'a_val', b: 'b_val', callback: [Function: callback] }
testing('a_val', 'b_val', 'c_val', function callback(){});
// => { a: 'a_val', b: 'b_val', c: 'c_val', callback: [Function: callback] }
```
##usage
* rules: ``object`` set the function rules, key is the number of the passing params. The missing rule will be return as ``false``