{"name":"option-chain","version":"1.0.0","description":"Use fluent property chains in lieu of options objects","license":"MIT","repository":{"type":"git","url":"git+https://github.com/avajs/option-chain.git"},"author":{"name":"James Talmage","email":"james@talmage.io","url":"github.com/jamestalmage"},"engines":{"node":">=4"},"scripts":{"test":"xo && nyc ava"},"files":["index.js"],"keywords":["option","options","chain","chains","chainable","fluent"],"devDependencies":{"ava":"^0.19.1","coveralls":"^2.11.6","nyc":"^10.3.2","xo":"^0.18.2"},"nyc":{"reporter":["lcov","text"]},"gitHead":"c0c10c4b405594cf80d8801afb0d8f7d941b4242","bugs":{"url":"https://github.com/avajs/option-chain/issues"},"homepage":"https://github.com/avajs/option-chain#readme","_id":"option-chain@1.0.0","_shasum":"938d73bd4e1783f948d34023644ada23669e30f2","_from":".","_npmVersion":"2.15.11","_nodeVersion":"4.8.3","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"938d73bd4e1783f948d34023644ada23669e30f2","tarball":"http://registry-npm.ywwl.com/option-chain/download/option-chain-1.0.0.tgz","integrity":"sha512-IUhG7PlO/bKThfrJE5MhhUPfVpRlbKVx42VM1oG3UWeaVvjcf0/52VKp6uQEgvr5/ThLMPWkGwPE0PJ1DSDc0A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAq7DOJtNDymEaGPuaeirZcVeuE+vyy/ZaPoTJH2N4WJAiEA+Wg5x54ziaJAYUfXfhH/Syf8B5wSfGAnuyVJOP2mNiY="}],"size":2701,"noattachment":false,"key":"/option-chain/-/option-chain-1.0.0.tgz"},"maintainers":[{"name":"jamestalmage","email":"james@talmage.io"},{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/option-chain-1.0.0.tgz_1494602408211_0.3149425445590168"},"directories":{},"readme":"# option-chain [![Build Status](https://travis-ci.org/avajs/option-chain.svg?branch=master)](https://travis-ci.org/avajs/option-chain) [![Coverage Status](https://coveralls.io/repos/github/avajs/option-chain/badge.svg?branch=master)](https://coveralls.io/github/avajs/option-chain?branch=master)\n\n> Use fluent property chains in lieu of options objects\n\n\n## Install\n\n```\n$ npm install --save option-chain\n```\n\n\n## Usage\n\n```js\nconst optionChain = require('option-chain');\n\nconst optionDefinition = {\n\tdefaults: {\n\t\tbar: false\n\t},\n\tchainableMethods: {\n\t\tfoo: {foo: true},\n\t\tnotFoo: {foo: false},\n\t\tbar: {bar: true}\n\t}\n};\n\nfunction printOptionsAndArgs(options, args) {\n\tconsole.log(options);\n\n\tif (args.length) {\n\t\tconsole.log(args);\n\t}\n}\n\nconst fn = optionChain(optionDefinition, printOptionsAndArgs);\n\nfn();\n//=> [{bar: false}]\nfn.bar();\n//=> [{bar: true}]\nfn.foo.bar();\n//=> [{foo: true, bar: false}]\n\nfn.foo('a', 'b');\n//=> [{foo: true, bar: false}]\n//=> ['a', 'b']\n```\n\n\n## API\n\n### optionChain(options, callback, [target])\n\n#### options\n\n##### chainableMethods\n\n*Required*<br>\nType: `Object`\n\nA map of chainable property names to the options set by adding property to the chain.\n\nGiven the following:\n\n```js\nconst chainableMethods = {\n\tfoo: {foo: true},\n\tnotFoo: {foo: false},\n\tbar: {bar: true},\n\tboth: {foo: true, bar: true}\n}\n```\n\nThen:\n\n- `fn.foo` would set `foo` to `true`.\n- `fn.bar` would set `bar` to `true`.\n- `fn.both` sets both `foo` and `bar` to `true`.\n- The last property in the chain takes precedence, so `fn.foo.notFoo` would result in `foo` being `false`.\n\n\n##### defaults\n\nType: `Object`<br>\nDefault: `{}`\n\nA set of default starting properties.\n\n##### spread\n\nType: `boolean`<br>\nDefault: `false`\n\nBy default, any arguments passed to the wrapper are passed as an array to the second argument of the wrapped function. When this is `true`, additional arguments will be spread out as additional arguments:\n\n```js\nfunction withoutSpread(opts, args) {\n\tlet foo = args[0];\n\tlet bar = args[1];\n\t// ...\n}\n\nfunction withSpread(opts, foo, bar) {\n\t// ...\n}\n```\n\n#### callback\n\nType: `Function`\n\nThis callback is called with the accumulated options as the first argument. Depending on the value of `options.spread`, arguments passed to the wrapper will either be an array as the second argument or spread out as the 2nd, 3rd, 4th... arguments.\n\n#### target\n\nIf supplied, the `target` object is extended with the property getters and returned. Otherwise a wrapper function is created for `options.defaults`, then that wrapper is extended and returned.\n\n*Hint:* If you want to extend a `target` and add a method that simply uses the defaults, add a chainable method definition with an empty spec:\n\n```js\nconst chainableMethods = {\n\tdefaultMethodName: {}\n}\n```\n\n\n## License\n\nMIT © [James Talmage](https://github.com/jamestalmage)\n","publish_time":1494602408453,"_cnpm_publish_time":1494602408453,"dist-tags":{"latest":"1.0.0"}}