aboutsummaryrefslogtreecommitdiff
path: root/ext/js/templates/template-patcher.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-11-27 12:48:14 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-11-27 12:48:14 -0500
commit4da4827bcbcdd1ef163f635d9b29416ff272b0bb (patch)
treea8a0f1a8befdb78a554e1be91f2c6059ca3ad5f9 /ext/js/templates/template-patcher.js
parentfd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff)
Add JSDoc type annotations to project (rebased)
Diffstat (limited to 'ext/js/templates/template-patcher.js')
-rw-r--r--ext/js/templates/template-patcher.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/ext/js/templates/template-patcher.js b/ext/js/templates/template-patcher.js
index 6bc012bc..33abb08e 100644
--- a/ext/js/templates/template-patcher.js
+++ b/ext/js/templates/template-patcher.js
@@ -18,12 +18,20 @@
export class TemplatePatcher {
constructor() {
+ /** @type {RegExp} */
this._diffPattern1 = /\n?\{\{<<<<<<<\}\}\n/g;
+ /** @type {RegExp} */
this._diffPattern2 = /\n\{\{=======\}\}\n/g;
+ /** @type {RegExp} */
this._diffPattern3 = /\n\{\{>>>>>>>\}\}\n*/g;
+ /** @type {RegExp} */
this._lookupMarkerPattern = /[ \t]*\{\{~?>\s*\(\s*lookup\s*\.\s*"marker"\s*\)\s*~?\}\}/g;
}
+ /**
+ * @param {string} content
+ * @returns {import('template-patcher').Patch}
+ */
parsePatch(content) {
const diffPattern1 = this._diffPattern1;
const diffPattern2 = this._diffPattern2;
@@ -61,6 +69,11 @@ export class TemplatePatcher {
return {addition: content, modifications};
}
+ /**
+ * @param {string} template
+ * @param {import('template-patcher').Patch} patch
+ * @returns {string}
+ */
applyPatch(template, patch) {
for (const {current, replacement} of patch.modifications) {
let fromIndex = 0;
@@ -77,6 +90,11 @@ export class TemplatePatcher {
// Private
+ /**
+ * @param {string} template
+ * @param {string} addition
+ * @returns {string}
+ */
_addFieldTemplatesBeforeEnd(template, addition) {
if (addition.length === 0) { return template; }
const newline = '\n';