work on docx patcher
This commit is contained in:
@ -1,16 +1,27 @@
|
||||
import * as JSZip from "jszip";
|
||||
import { xml2js, ElementCompact, js2xml } from "xml-js";
|
||||
import { replacer } from "./replacer";
|
||||
|
||||
// eslint-disable-next-line functional/prefer-readonly-type
|
||||
type InputDataType = Buffer | string | number[] | Uint8Array | ArrayBuffer | Blob | NodeJS.ReadableStream;
|
||||
|
||||
export const fromDocx = async (data: InputDataType): Promise<Buffer> => {
|
||||
export interface PatchDocumentOptions {
|
||||
readonly children: any[];
|
||||
}
|
||||
|
||||
export const patchDocument = async (data: InputDataType, options: PatchDocumentOptions): Promise<Buffer> => {
|
||||
const zipContent = await JSZip.loadAsync(data);
|
||||
|
||||
const map = new Map<string, ElementCompact>();
|
||||
console.log(options);
|
||||
|
||||
for (const [key, value] of Object.entries(zipContent.files)) {
|
||||
const json = toJson(await value.async("text"));
|
||||
if (key === "word/document.xml") {
|
||||
console.log(json);
|
||||
replacer(json, options);
|
||||
}
|
||||
|
||||
map.set(key, json);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user