Comparing version 0.0.8 to 0.0.9
27
main.js
@@ -193,6 +193,29 @@ | ||
string: { | ||
template: function (data, obj, remove) { | ||
return data.replace(/\{([\w]+)\}/g, function (str, key) { | ||
/** | ||
* replace placeholders inside graph brackets {} with obj dictionary | ||
* ~ES6 template string, but safer | ||
* @param {string} str | ||
* @param {type} obj | ||
* @param {bool} [remove=false] remove missing placeholders from obj | ||
* @returns {unresolved} | ||
*/ | ||
template: function (str, obj, remove) { | ||
return str.replace(/\{([\w]+)\}/g, function (str, key) { | ||
return obj[key] ? obj[key] : (remove ? '' : str); | ||
}); | ||
}, | ||
/** | ||
* trim string | ||
* @see http://google.github.io/closure-library/api/namespace_goog_string.html | ||
* @param {string} str | ||
* @param {?string[]} cuts | ||
* @returns {string} | ||
*/ | ||
trim: function(str, cuts) { | ||
if(!cuts) | ||
return str.replace(/^[\s\xa0]+|[\s\xa0]+$/g, ''); | ||
else { | ||
var _cuts = cuts.join(); | ||
return str.replace(new RegExp('^[' + _cuts + ']+|[' + _cuts + ']+$', 'gm'), ''); | ||
} | ||
} | ||
@@ -199,0 +222,0 @@ } |
{ | ||
"name": "a-toolbox", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "lightweight tools", | ||
@@ -17,7 +17,7 @@ "keywords": ["tools", "lib", "misc", "toolbox", "array", "task", "random"], | ||
"scripts": { | ||
"test": "node test.js" | ||
"test": "istanbul cover test.js -x test.js" | ||
}, | ||
"files": ["main.js"], | ||
"main": "main", | ||
"dependencies": { } | ||
"tonicExampleFilename": "test.js", | ||
"files": ["main.js", "test.js"], | ||
"main": "main" | ||
} |
@@ -116,2 +116,14 @@ # a-toolbox | ||
#### string trim | ||
Trim string using custom chars | ||
```js | ||
var str = '({cut these silly brackets please)}'; | ||
console.log('trim:', tools.string.trim(str, ['{','}','(',')'])); | ||
//> trim: cut these silly brackets please | ||
``` | ||
#### replaceAll in String prototype | ||
@@ -118,0 +130,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
17163
5
304
267