AnyArgs
A small utility module that converts function arguments to an object for use within the function based on a supplied metadata object. This allows parameters to be passed in any order, making the resultant function very flexible.
Features
- Adds type safety to function parameters
- Adds ability to specify default parameters in any order
- Adds ability to pass parameters in any order
- Adds ability to skip parameters at any position in the function signature
NPM
Official home on NPM: https://www.npmjs.com/package/anyargs
Github
Official home on Github: https://github.com/eenewbsauce/anyargs
Setup
-
Install the module
npm i anyargs
Usage
Add anyargs to your function
- anyargs does not support multiple keys having the same type in the metadata object.
let anyArgs = ; { let metadata = one: type: 'number' required: true two: type: 'string' required: true cb: type: 'function' required: false {} ; let args = ; return { let sum = argsone + ; ; args; };}
Use function how ever you'd like
let sum = ; let sumV2 = ;
Tests
Run test suite
npm test