#2028 - Null check

This commit is contained in:
Dolan Miu
2023-03-31 00:13:36 +01:00
parent 6362b498a6
commit c3a617fefd
3 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,29 @@
// Patch a document with patches
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { IPatch, patchDocument, PatchType, TextRun } from "../src";
export const font = "Trebuchet MS";
export const getPatches = (fields: { [key: string]: string }) => {
const patches: { [key: string]: IPatch } = {};
for (const field in fields) {
patches[field] = {
type: PatchType.PARAGRAPH,
children: [new TextRun({ text: fields[field], font })],
};
}
return patches;
};
const patches = getPatches({
salutation: "Mr.",
"first-name": "John",
});
patchDocument(fs.readFileSync("demo/assets/simple-template-3.docx"), {
patches,
}).then((doc) => {
fs.writeFileSync("My Document.docx", doc);
});