Skip to content

Commit 1f0956b

Browse files
committed
Update replaceVars to ignore not found translations
1 parent 38a5e5c commit 1f0956b

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wurd",
3-
"version": "7.0.0",
3+
"version": "7.0.1",
44
"description": "Wurd CMS client for Node",
55
"repository": {
66
"type": "git",

src/utils.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @return {String}
55
*/
6-
exports.encodeQueryString = function(data) {
6+
exports.encodeQueryString = function (data) {
77
let parts = Object.keys(data).map(key => {
88
let value = data[key];
99

@@ -22,16 +22,10 @@ exports.encodeQueryString = function(data) {
2222
*
2323
* @return {String}
2424
*/
25-
exports.replaceVars = function(text, vars = {}) {
25+
exports.replaceVars = function (text, vars = {}) {
2626
if (typeof text !== 'string') return text;
2727

28-
Object.keys(vars).forEach(key => {
29-
let val = vars[key];
30-
31-
text = text.replace(new RegExp(`{{${key}}}`, 'g'), val);
32-
});
33-
34-
return text;
28+
return text.replace(/{{([\w.-]+)}}/g, (_, key) => vars[key] || '');
3529
};
3630

3731

@@ -43,7 +37,7 @@ exports.replaceVars = function(text, vars = {}) {
4337
*
4438
* @return {String} cacheId
4539
*/
46-
exports.getCacheId = function(id, options = {}) {
40+
exports.getCacheId = function (id, options = {}) {
4741
let lang = options.lang || ''
4842

4943
return `${lang}/${id}`;

0 commit comments

Comments
 (0)