Comparing version 0.2.1 to 0.2.2
@@ -34,2 +34,8 @@ /* | ||
// set a heuristic indicating the method should be expanded | ||
expander.fn = function(method) { | ||
method.__expanderFn__ = true; | ||
return method; | ||
}; | ||
// recursively expand a string until it doesn't contain any template strings | ||
@@ -70,3 +76,5 @@ expander.stringExpand = function (data, lookup) { | ||
expander.process = function (data, lookup) { | ||
if(_.isString(lookup)) { | ||
if(_.isFunction(lookup) && lookup.__expanderFn__ === true) { | ||
return lookup.call(this, data); | ||
} else if(_.isString(lookup)) { | ||
return expander.stringExpand(data, lookup); | ||
@@ -73,0 +81,0 @@ } else if(_.isArray(lookup)) { |
{ | ||
"name": "expander", | ||
"description": "Expand template strings in declarative configurations.", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"homepage": "https://github.com/tkellen/expander", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -8,3 +8,3 @@ # expander [![Build Status](https://secure.travis-ci.org/tkellen/node-expander.png?branch=master)](http://travis-ci.org/tkellen/node-expander) | ||
```js | ||
var expander = require('expander'); | ||
var expander = require('./lib/expander'); | ||
@@ -27,18 +27,10 @@ var data = { | ||
interpolatedRecursiveRef: 'test <%= keyRef %>', | ||
_key: 'value', | ||
_keyRef: '${_key}', | ||
_recursiveKeyRef: '${_keyRef}', | ||
_arrayRef: ['test', '${_key}'], | ||
_recursiveArrayRef: ['test', '${_arrayRef}'], | ||
_obj: { | ||
_keyRef: '${_key}', | ||
_recursiveKeyRef: '${_keyRef}', | ||
_arrayRef: ['test', '${_key}'], | ||
_recursiveArrayRef: ['test', '${_arrayRef}'] | ||
}, | ||
_dotRef: '${ _obj._keyRef }', | ||
_objRef: '${_obj}', | ||
_interpolated: 'test ${ _key}', | ||
_interpolatedRecursiveRef: 'test ${_keyRef }' | ||
methodRef: expander.fn(function (config) { | ||
// config is the entire config | ||
return config.key; | ||
}), | ||
methodRefContext: expander.fn(function (config) { | ||
// this is a reference to expander | ||
return this.get(config, 'keyRef'); | ||
}) | ||
}; | ||
@@ -64,2 +56,4 @@ | ||
expander.get(data, 'interpolatedRecursiveRef'); // test value | ||
expander.get(data, 'methodRef'); // value | ||
expander.get(data, 'methodRefContext'); // value | ||
``` | ||
@@ -69,4 +63,5 @@ | ||
* 2013-12-15 - v0.2.2 - support auto expansion of functions | ||
* 2013-11-21 - v0.2.1 - support ${value} strings | ||
* 2013-11-08 - v0.2.0 - correctly handle recursively interpolated values | ||
* 2013-11-05 - v0.1.0 - initial release |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7625
92
63