Comparing version 0.0.6 to 0.0.7
14
main.js
@@ -6,2 +6,6 @@ | ||
String.prototype.capitalize = function () { | ||
return this.substr(0,1).toUpperCase() + this.substr(1).toLowerCase(); | ||
}; | ||
var tools = { | ||
@@ -188,5 +192,13 @@ /** | ||
}; | ||
}, | ||
string: { | ||
template: function (data, obj, remove) { | ||
return data.replace(/\{([\w]+)\}/g, function (str, key) { | ||
return obj[key] ? obj[key] : (remove ? '' : str); | ||
}); | ||
} | ||
} | ||
}; | ||
if (typeof window == 'undefined') | ||
if (module && module.exports) | ||
module.exports = tools; | ||
@@ -193,0 +205,0 @@ |
{ | ||
"name": "a-toolbox", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "lightweight tools", | ||
@@ -5,0 +5,0 @@ "keywords": ["tools", "lib", "misc", "toolbox", "array", "task", "random"], |
@@ -98,2 +98,18 @@ # a-toolbox | ||
#### string template | ||
Replace marker in template string with provided object data | ||
```js | ||
var data = { | ||
name: 'Alice', | ||
year: 2014, | ||
color: 'yellow' | ||
}; | ||
var str = '<div>My name is {name} I was born in {year} and my favourite color is {color}</div>{nothing}'; | ||
console.log('template:', tools.string.template(str, data)); | ||
//> template: <div>My name is Alice I was born in 2014 and my favourite color is yellow</div>{nothing} | ||
#### replaceAll in String prototype | ||
@@ -100,0 +116,0 @@ |
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
12910
196
254