// remove text variables in a DOCX template that uses a custom symbol (${})

import { CreateDocx, OptionsRemoveVariableText } from "../../../build";
import * as fs from "fs";

const docxTemplate = fs.readFileSync(
    "../../files/TemplateVariables_symbols.docx"
);

const docx = new CreateDocx();
// load the template
docx.openTemplate(docxTemplate).then(docx => {
    // set a custom template symbol
    docx.setTemplateSymbols("${", "}");

    // variables to be removed in the document
    const variablesDocument = ["VARNAME", "OTHERVAR"];
    // remove template variables in the document target
    docx.removeVariableText(variablesDocument);

    // variables to be removed in the header target
    const variablesHeader = ["HEADERVAR"];
    // remove template variables in the header target
    docx.removeVariableText(variablesHeader, "header");

    // variables to be removed in the footer target
    const variablesFooter = ["FOOTERVAR"];
    // remove template variables in the foter target using a block type removal
    const optionsRemoveVariable: OptionsRemoveVariableText = {
        type: "block",
    };
    docx.removeVariableText(variablesFooter, "footer", optionsRemoveVariable);

    // save the DOCX
    docx.save().then(contents => {
        fs.writeFileSync("removeVariableText_2.docx", Buffer.from(contents));
    });
});
