template-obj
v0.0.2
Published
template strings in the javascript object.
Downloads
5
Maintainers
Readme
template-obj
template strings in the javascript object.
lightweight utility module. (production file is 1.29KB)
Install
npm
$ npm install template-obj
Bower
$ bower install template-obj
CommonJS
var templateObj = require("template-obj");
Basic
- Download the template-obj.min.js.
- Load it in the script tag.
<script type="text/javascript" src="template-obj.min.js"></script>
Usage
Basic
var obj = templateObj({
key1: "value1",
key2: "${key1} value2"
});
console.log(obj);
/*
{
key1: "value1",
key2: "value1 value2"
}
*/
Nested value
Access to the nested value using the dot syntax, and bracket notation.
var params = templateObj({
ns: "app",
events: {
click : "click.${ns}",
mouseenter: "mouseenter.${ns}",
mouseleave: "mouseleave.${ns}"
},
logs: {
click : "${events.click} was triggered.",
mouseenter: "${events.mouseenter} was triggered.",
mouseleave: "${events.mouseleave} was triggered."
},
defaultEvent: "${events.click}",
loaders: [
"coffee-loader",
"babel-loader"
],
loader: "${loaders[0]} & ${loaders[1]}"
});
console.log(params);
/*
{
ns: "app",
events: {
click : "click.app",
mouseenter: "mouseenter.app",
mouseleave: "mouseleave.app"
},
logs: {
click : "click.app was triggered.",
mouseenter: "mouseenter.app was triggered.",
mouseleave: "mouseleave.app was triggered."
},
defaultEvent: "click.app",
loaders: [
"coffee-loader",
"babel-loader"
],
loader: "coffee-loader & babel-loader"
}
*/
Browser Support
- IE6 +
- Chrome
- Firefox
- Safari
- iOS
- Android
License
Released under the MIT Licence