git ssb

0+

mixmix / map-args



Commit a613d7d871a2785faadddb73e2d8117f58855d9e

README

mix irving committed on 2/11/2018, 9:50:41 AM

Files changed

README.mdadded
package.jsonadded
README.mdView
@@ -1,0 +1,83 @@
1 +# map-args
2 +
3 +Functions that take flexible arguments are fun to use but not fun to read or write:
4 +```js
5 +function (keys, opts, cb) {
6 + if (typeof keys == 'function') {
7 + cb = keys
8 + keys = null
9 + opts = null
10 + }
11 + else if (typeof opts == 'function') {
12 + cb = opts
13 + opts = keys
14 + keys = null
15 + }
16 +
17 + // etc
18 +}
19 +```
20 +
21 +In case it's not immediately obvious, you can use this function like :
22 +
23 +```
24 +func(keys, opts, cb)
25 +func(opts, cb)
26 +func(cb)
27 +```
28 +
29 +## Usage
30 +
31 +```js
32 +const mapArgs = require('map-args')
33 +
34 +function (keys, opts, cb) {
35 + mapArgs(
36 + ['object function', [opts, cb]],
37 + ['function', [cb] ]
38 + )
39 +
40 + // get on with your day
41 +}
42 +```
43 +
44 +## API
45 +
46 +```js
47 +const mapArgs = require('map-args')
48 +```
49 +
50 +`mapArgs([match1, match2, ...])`
51 +
52 +Each match is an as array with two elements: `[inputMatcher, outputMap]`
53 +
54 +The `inputMatcher` can be:
55 +- a String of `n` space-seperate types e.g. `'string object function'`
56 +- an Array of `n` type matching functions or strings e.g `[isFeed, 'object', 'function']`
57 +
58 +The `outputMap` is an array of the `n` arguments you're mapping to.
59 +
60 +Map-args goes through the matchers in order, and if it finds a match it maps the arguments accordingly.
61 +If no match is found the arguments will be left as as they were.
62 +
63 +Matches which map less than the total number of possible args will set non-mapped args to `null`.
64 +
65 +
66 +## Install
67 +
68 +With [npm](https://npmjs.org/) installed, run
69 +
70 +```
71 +$ npm install map-args
72 +```
73 +
74 +
75 +## See Also
76 +
77 +- [`noffle/common-readme`](https://github.com/noffle/common-readme)
78 +- ...
79 +
80 +## License
81 +
82 +AGPL-3.0
83 +
package.jsonView
@@ -1,0 +1,22 @@
1 +{
2 + "name": "map-args",
3 + "version": "0.0.1",
4 + "description": "sick of wrangling variable number of args? map-args solves that",
5 + "main": "index.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "repository": {
10 + "type": "git",
11 + "url": "git+https://github.com/mixmix/map-args.git"
12 + },
13 + "keywords": [
14 + "arguments"
15 + ],
16 + "author": "mixmix",
17 + "license": "AGPL-3.0",
18 + "bugs": {
19 + "url": "https://github.com/mixmix/map-args/issues"
20 + },
21 + "homepage": "https://github.com/mixmix/map-args#readme"
22 +}

Built with git-ssb-web