cm-web-modules
Advanced tools
Comparing version 1.9.6 to 1.9.7
{ | ||
"name": "cm-web-modules", | ||
"version": "1.9.6", | ||
"version": "1.9.7", | ||
"description": "Collection of clean and small ES6 modules for the web", | ||
@@ -5,0 +5,0 @@ "main": "src/LibraryManager.js", |
@@ -7,8 +7,19 @@ /** | ||
export class Template { | ||
constructor(template) { | ||
this.template = template | ||
constructor(templateOrContent) { | ||
if(templateOrContent instanceof HTMLElement) { | ||
this.content = "" | ||
for (const childNode of templateOrContent.content.childNodes) { | ||
if(childNode.nodeType === Node.TEXT_NODE) { | ||
this.content += childNode.wholeText | ||
} else if(childNode.nodeType === Node.ELEMENT_NODE) { | ||
this.content += childNode.outerHTML | ||
} | ||
} | ||
} else if (typeof templateOrContent === 'string' || templateOrContent instanceof String) { | ||
this.content = templateOrContent | ||
} | ||
} | ||
render(replacements) { | ||
return this.template.replace(/\${(.*?)}/g, (toReplace, key) => { | ||
return this.content.replace(/\${(.*?)}/g, (toReplace, key) => { | ||
if(replacements[key] === undefined) { | ||
@@ -15,0 +26,0 @@ return toReplace |
@@ -18,13 +18,2 @@ /** | ||
static replaceAll(str, replacementsObj, ignoreCase = false) { | ||
console.warn("replaceAll is deprecated and will be removed in future versions") | ||
let retStr = str | ||
const flags = ignoreCase ? "gi" : "g" | ||
for (let needle in replacementsObj) { | ||
// noinspection JSUnfilteredForInLoop | ||
retStr = retStr.replace(new RegExp(needle, flags), replacementsObj[needle]) | ||
} | ||
return retStr | ||
} | ||
static crop(str, maxLength) { | ||
@@ -31,0 +20,0 @@ if (str.length > maxLength) { |
Sorry, the diff of this file is not supported yet
92211
46
1674