mirror of
https://github.com/chylex/Discord-History-Tracker.git
synced 2024-11-22 05:42:46 +01:00
23 lines
519 B
JavaScript
23 lines
519 B
JavaScript
import dom from "./dom.mjs";
|
|
|
|
const TEMPLATE_REGEX = /{([^{}]+?)}/g;
|
|
|
|
export default class {
|
|
constructor(contents) {
|
|
this.contents = contents;
|
|
};
|
|
|
|
apply(obj, processor) {
|
|
return this.contents.replace(TEMPLATE_REGEX, (full, match) => {
|
|
const value = match.split(".").reduce((o, property) => o[property], obj);
|
|
|
|
if (processor) {
|
|
const updated = processor(match, value);
|
|
return typeof updated === "undefined" ? dom.escapeHTML(value) : updated;
|
|
}
|
|
|
|
return dom.escapeHTML(value);
|
|
});
|
|
}
|
|
}
|