Re-name templater to patcher

This commit is contained in:
Dolan Miu
2023-02-25 20:18:00 +00:00
parent 3f6c006716
commit 4e875b4744
9 changed files with 1 additions and 1 deletions

19
src/patcher/util.ts Normal file
View File

@ -0,0 +1,19 @@
import { xml2js, Element } from "xml-js";
import * as xml from "xml";
import { Formatter } from "@export/formatter";
import { Text } from "@file/paragraph/run/run-components/text";
const formatter = new Formatter();
export const toJson = (xmlData: string): Element => {
const xmlObj = xml2js(xmlData, { compact: false }) as Element;
return xmlObj;
};
// eslint-disable-next-line functional/prefer-readonly-type
export const createTextElementContents = (text: string): Element[] => {
const textJson = toJson(xml(formatter.format(new Text({ text }))));
return textJson.elements![0].elements ?? [];
};