{"name":"expander","description":"Expand template strings in declarative configurations.","version":"0.3.0","homepage":"https://github.com/tkellen/expander","author":{"name":"Tyler Kellen","url":"http://goingslowly.com/"},"repository":{"type":"git","url":"git://github.com/tkellen/expander.git"},"bugs":{"url":"https://github.com/tkellen/expander/issues"},"licenses":[{"type":"MIT","url":"https://github.com/tkellen/expander/blob/master/LICENSE-MIT"}],"main":"index.js","engines":{"node":">= 0.8.0"},"scripts":{"test":"mocha -R spec test/index.js"},"devDependencies":{"mocha":"~1.17.1","chai":"~1.9.0"},"keywords":["declarative configuration"],"dependencies":{"getobject":"0.1.0","lodash":"~2.2.1"},"_id":"expander@0.3.0","dist":{"shasum":"cb6fb0045f9460abdc9e6464e1832a0f71ad3023","tarball":"http://registry-npm.ywwl.com/expander/download/expander-0.3.0.tgz","integrity":"sha512-U6YMFxrmRFhNGBe13sc7LdPyGDkJjk3CRRuNTlxXiUW3Ep/B8di0tmhieV3iYsGzzQfwVFVkkxhoJW3KgzDE/g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDKn9p1oHxuSQxmk7kjIJFPxuo2Y2wka2dj1mSBVeNSsQIhAKI0I0JACIHHwmo3R08osRLN8VTHeRXg19IoMZcCNDYz"}],"size":3178,"noattachment":false,"key":"/expander/-/expander-0.3.0.tgz"},"_from":".","_npmVersion":"1.3.26","_npmUser":{"name":"tkellen","email":"tyler@sleekcode.net"},"maintainers":[{"name":"tkellen","email":"tyler@sleekcode.net"}],"directories":{},"readme":"# expander [![Build Status](https://secure.travis-ci.org/tkellen/node-expander.png?branch=master)](http://travis-ci.org/tkellen/node-expander)\n\n> Expand template strings in declarative configurations.\n\n## API\n\n### get(data, lookup, imports)\nRetrieve a value from the data object with all template strings resolved.\n\n`data` a configuration object\n`lookup` a dot-notated key\n`options` sent to [_.template](http://lodash.com/docs#template) when resolving values.\n\nExample:\n```js\nvar data = {\n  key: '<%= uppercase(\"foo\") %>'\n};\nexpander.get(data, 'key', {\n  imports: {\n    uppercase: function (str) {\n      return str.toUpperCase();\n    }\n  }\n}); // FOO\n```\n\n### getRaw(data, lookup)\nRetrieve a literal value from the data object.\n\n`data` a configuration object\n`lookup` a dot-notated string representing a key in the configuration\n\n### set(data, lookup, value)\nSet a value in the data object.\n\n`data` a configuration object\n`lookup` a dot-notated string representing a key in the data\n`value` the value to set\n\n### process(data, lookup, options)\nResolve any arbitrary template string.\n\n`data` a configuration object\n`lookup` any string value, typically a template string, e.g. \"<%= key %>\"\n`options` sent to [_.template](http://lodash.com/docs#template) when resolving values.\n\n### interface(data, options)\nBind the above API to a provided data object so you can access it more succinctly.\n\n`data` a configuration object\n`options` sent to [_.template](http://lodash.com/docs#template) automatically when resolving values.\n\n**Note:** When using the interface API, passing options to `get` or `process` will perform a shallow merge over `options` provided when the interface was instantiated.\n\nExample:\n```js\nvar configRaw = {\n  key: 'value',\n  keyRef: '<%= key %>'\n};\nvar config = expander.interface(config);\nconfig('key'); // value\nconfig.get('key'); // value\nconfig('keyRef'); // value\nconfig.get('keyRef'); // value\nconfig('key', 'changed'); // changed\nconfig('key'); // changed\n```\n\n## Examples\n\n```js\nvar expander = require('expander');\n\nvar data = {\n  key: 'value',\n  keyRef: '<%= key %>',\n  recursiveKeyRef: '<%= keyRef %>',\n  arrayRef: ['test', '<%= key %>'],\n  recursiveArrayRef: ['test', '<%= arrayRef %>'],\n  obj: {\n    keyRef: '<%= key %>',\n    recursiveKeyRef: '<%= keyRef %>',\n    arrayRef: ['test', '<%= key %>'],\n    recursiveArrayRef: ['test', '<%= arrayRef %>']\n  },\n  dotRef: '<%= obj.keyRef %>',\n  objRef: '<%= obj %>',\n  interpolated: 'test <%= key %>',\n  interpolatedRecursiveRef: 'test <%= keyRef %>',\n  methodRef: expander.fn(function (config) {\n    // config is the entire config\n    return config.key;\n  }),\n  methodRefContext: expander.fn(function (config) {\n    // this is a reference to expander\n    return this.get(config, 'keyRef');\n  })\n};\n\nexpander.get(data, 'keyRef'); // value\nexpander.get(data, 'recursiveKeyRef'); // value\nexpander.get(data, 'arrayRef'); // ['test', 'value']\nexpander.get(data, 'recursiveArrayRef'); // ['test', ['test', 'value']]\nexpander.get(data, 'obj'); // {\n                           //   keyRef: 'value',\n                           //   recursiveKeyRef: 'value',\n                           //   arrayRef: ['test', 'value'],\n                           //   recursiveArrayRef: ['test', ['test', 'value']]\n                           // }\nexpander.get(data, 'objRef'); // {\n                              //   keyRef: 'value',\n                              //   recursiveKeyRef: 'value',\n                              //   arrayRef: ['test', 'value'],\n                              //   recursiveArrayRef: ['test', ['test', 'value']]\n                              // }\nexpander.get(data, 'interpolated'); // test value\nexpander.get(data, 'interpolatedRecursiveRef'); // test value\nexpander.get(data, 'methodRef'); // value\nexpander.get(data, 'methodRefContext'); // value\n\n// getter setter api\nvar config = expander.interface(data);\nconfig('keyRef'); // value\nconfig('recursiveKeyRef'); // value\nconfig('arrayRef'); // ['test', 'value']\nconfig('recursiveArrayRef'); // ['test', ['test', 'value']]\nconfig('obj'); // {\n               //   keyRef: 'value',\n               //   recursiveKeyRef: 'value',\n               //   arrayRef: ['test', 'value'],\n               //   recursiveArrayRef: ['test', ['test', 'value']]\n               // }\nconfig('objRef'); // {\n                  //   keyRef: 'value',\n                  //   recursiveKeyRef: 'value',\n                  //   arrayRef: ['test', 'value'],\n                  //   recursiveArrayRef: ['test', ['test', 'value']]\n                  // }\nconfig('interpolated'); // test value\nconfig('interpolatedRecursiveRef'); // test value\nconfig('methodRef'); // value\nconfig('methodRefContext'); // value\n```\n\n## Release History\n\n* 2014-02-21 - v0.3.3 - allow overriding default options for _.template in interface api\n* 2014-02-20 - v0.3.2 - allow passing options to _.template\n* 2014-02-11 - v0.3.1 - interface emits events on set\n* 2014-02-10 - v0.3.0 - support a getter/setter api\n* 2013-12-15 - v0.2.2 - support auto expansion of functions\n* 2013-11-21 - v0.2.1 - support ${value} strings\n* 2013-11-08 - v0.2.0 - correctly handle recursively interpolated values\n* 2013-11-05 - v0.1.0 - initial release\n","publish_time":1392050786535,"_cnpm_publish_time":1392050786535,"dist-tags":{"latest":"0.3.3"}}