# map-args Functions that take flexible arguments are fun to use but not fun to read or write: ```js function (keys, opts, cb) { if (typeof keys == 'function') { cb = keys keys = null opts = null } else if (typeof opts == 'function') { cb = opts opts = keys keys = null } // etc } ``` In case it's not immediately obvious, you can use this function like : ``` func(keys, opts, cb) func(opts, cb) func(cb) ``` ## Usage ```js const mapArgs = require('map-args') function (keys, opts, cb) { mapArgs( ['object function', [opts, cb]], ['function', [cb] ] ) // get on with your day } ``` ## API ```js const mapArgs = require('map-args') ``` `mapArgs([match1, match2, ...])` Each match is an as array with two elements: `[inputMatcher, outputMap]` The `inputMatcher` can be: - a String of `n` space-seperate types e.g. `'string object function'` - an Array of `n` type matching functions or strings e.g `[isFeed, 'object', 'function']` The `outputMap` is an array of the `n` arguments you're mapping to. Map-args goes through the matchers in order, and if it finds a match it maps the arguments accordingly. If no match is found the arguments will be left as as they were. Matches which map less than the total number of possible args will set non-mapped args to `null`. ## Install With [npm](https://npmjs.org/) installed, run ``` $ npm install map-args ``` ## See Also - [`noffle/common-readme`](https://github.com/noffle/common-readme) - ... ## License AGPL-3.0