// remove text variables in a DOCX template

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

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

const docx = new CreateDocx();
// load the template
docx.openTemplate(docxTemplate).then(docx => {
    // variables to be removed in the document target
    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 footer 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_1.docx", Buffer.from(contents));
    });
});
