{"_id":"option-chain","_rev":"299586","name":"option-chain","description":"Use fluent property chains in lieu of options objects","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"novemberborn","email":"mark@novemberborn.net"}],"time":{"modified":"2021-06-03T19:03:24.000Z","created":"2016-01-15T20:34:10.888Z","1.0.0":"2017-05-12T15:20:08.453Z","0.1.1":"2016-01-24T04:14:30.430Z","0.1.0":"2016-01-15T20:34:10.888Z"},"users":{"oleg_tsyba":true,"wheelo":true},"author":{"name":"James Talmage","email":"james@talmage.io","url":"github.com/jamestalmage"},"repository":{"type":"git","url":"git+https://github.com/avajs/option-chain.git"},"versions":{"1.0.0":{"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","size":2701,"noattachment":false,"key":"/option-chain/-/option-chain-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/option-chain/download/option-chain-1.0.0.tgz"},"maintainers":[{"name":"novemberborn","email":"mark@novemberborn.net"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/option-chain-1.0.0.tgz_1494602408211_0.3149425445590168"},"directories":{},"publish_time":1494602408453,"_hasShrinkwrap":false,"_cnpm_publish_time":1494602408453},"0.1.1":{"name":"option-chain","version":"0.1.1","description":"Use fluent property chains in lieu of options objects","license":"MIT","repository":{"type":"git","url":"git+https://github.com/jamestalmage/option-chain.git"},"author":{"name":"James Talmage","email":"james@talmage.io","url":"github.com/jamestalmage"},"engines":{"node":">=0.10.0"},"scripts":{"test":"xo && nyc --cache --reporter=lcov --reporter=text ava"},"files":["index.js"],"keywords":["option","options","chain","chains","chainable","fluent"],"devDependencies":{"ava":"^0.10.0","coveralls":"^2.11.6","nyc":"^5.3.0","xo":"^0.12.1"},"dependencies":{"object-assign":"^4.0.1"},"gitHead":"69666a183f9145095459562d47f5d8d5f31d1296","bugs":{"url":"https://github.com/jamestalmage/option-chain/issues"},"homepage":"https://github.com/jamestalmage/option-chain#readme","_id":"option-chain@0.1.1","_shasum":"e9b811e006f1c0f54802f28295bfc8970f8dcfbd","_from":".","_npmVersion":"3.5.3","_nodeVersion":"5.4.1","_npmUser":{"name":"jamestalmage","email":"james@talmage.io"},"dist":{"shasum":"e9b811e006f1c0f54802f28295bfc8970f8dcfbd","size":2729,"noattachment":false,"key":"/option-chain/-/option-chain-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/option-chain/download/option-chain-0.1.1.tgz"},"maintainers":[{"name":"novemberborn","email":"mark@novemberborn.net"}],"directories":{},"publish_time":1453608870430,"_cnpm_publish_time":1453608870430,"_hasShrinkwrap":false},"0.1.0":{"name":"option-chain","version":"0.1.0","description":"Use fluent property chains in lieu of options objects","license":"MIT","repository":{"type":"git","url":"git+https://github.com/jamestalmage/option-chain.git"},"author":{"name":"James Talmage","email":"james@talmage.io","url":"github.com/jamestalmage"},"engines":{"node":">=0.10.0"},"scripts":{"test":"xo && nyc --cache --reporter=lcov --reporter=text ava"},"files":["index.js"],"keywords":["option","options","chain","chains","chainable","fluent"],"devDependencies":{"ava":"^0.10.0","coveralls":"^2.11.6","nyc":"^5.3.0","xo":"^0.12.1"},"dependencies":{"object-assign":"^4.0.1"},"gitHead":"c28ac0359248441bee8b701f5a81e85b739f4deb","bugs":{"url":"https://github.com/jamestalmage/option-chain/issues"},"homepage":"https://github.com/jamestalmage/option-chain#readme","_id":"option-chain@0.1.0","_shasum":"6519de2e01f2dfa76e7c5f3bb2b2755af785d5bf","_from":".","_npmVersion":"3.5.3","_nodeVersion":"5.3.0","_npmUser":{"name":"jamestalmage","email":"james@talmage.io"},"dist":{"shasum":"6519de2e01f2dfa76e7c5f3bb2b2755af785d5bf","size":2707,"noattachment":false,"key":"/option-chain/-/option-chain-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/option-chain/download/option-chain-0.1.0.tgz"},"maintainers":[{"name":"novemberborn","email":"mark@novemberborn.net"}],"directories":{},"publish_time":1452890050888,"_cnpm_publish_time":1452890050888,"_hasShrinkwrap":false}},"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","_attachments":{},"homepage":"https://github.com/avajs/option-chain#readme","bugs":{"url":"https://github.com/avajs/option-chain/issues"},"license":"MIT"}