mirror of
https://github.com/chylex/Discord-History-Tracker.git
synced 2025-04-14 23:50:33 +03:00
21 lines
508 B
JavaScript
21 lines
508 B
JavaScript
var TEMPLATE_REGEX = /{([^{}]+?)}/g;
|
|
|
|
class TEMPLATE{
|
|
constructor(contents){
|
|
this.contents = contents;
|
|
};
|
|
|
|
apply(obj, processor){
|
|
return this.contents.replace(TEMPLATE_REGEX, (full, match) => {
|
|
var value = match.split(".").reduce((o, property) => o[property], obj);
|
|
|
|
if (processor){
|
|
var updated = processor(match, value);
|
|
return typeof updated === "undefined" ? DOM.escapeHTML(value) : updated;
|
|
}
|
|
|
|
return DOM.escapeHTML(value);
|
|
});
|
|
}
|
|
}
|