Trying to upgrade docx to use Vite

This commit is contained in:
Dolan Miu
2023-05-01 20:37:39 +01:00
parent 18b2e91da2
commit a26292a0fd
20 changed files with 1178 additions and 312 deletions

View File

@ -44,7 +44,8 @@ describe("Properties", () => {
expect(Object.keys(tree)).to.deep.equal(["cp:coreProperties"]);
expect(tree["cp:coreProperties"]).to.be.an.instanceof(Array);
const key = (obj) => Object.keys(obj)[0];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const key = (obj: { readonly [key: string]: any }) => Object.keys(obj)[0];
expect(tree["cp:coreProperties"].map(key)).to.include.members([
"_attr",
"cp:keywords",

View File

@ -25,7 +25,8 @@ describe("Numbering", () => {
const tree = new Formatter().format(numbering);
expect(Object.keys(tree)).to.deep.equal(["w:numbering"]);
const abstractNums = tree["w:numbering"].filter((el) => el["w:abstractNum"]);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const abstractNums: readonly any[] = tree["w:numbering"].filter((el) => el["w:abstractNum"]);
expect(abstractNums).to.have.lengthOf(1);
expect(abstractNums[0]["w:abstractNum"]).to.deep.include.members([
{ _attr: { "w:abstractNumId": 0, "w15:restartNumberingAfterBreak": 0 } },

View File

@ -29,7 +29,8 @@ export interface INumberingOptions {
export class Numbering extends XmlComponent {
private readonly abstractNumberingMap = new Map<string, AbstractNumbering>();
private readonly concreteNumberingMap = new Map<string, ConcreteNumbering>();
private readonly referenceConfigMap = new Map<string, object>();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private readonly referenceConfigMap = new Map<string, Record<string, any>>();
public constructor(options: INumberingOptions) {
super("w:numbering");
@ -231,7 +232,8 @@ export class Numbering extends XmlComponent {
public get ConcreteNumbering(): readonly ConcreteNumbering[] {
return Array.from(this.concreteNumberingMap.values());
}
public get ReferenceConfig(): readonly object[] {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public get ReferenceConfig(): readonly Record<string, any>[] {
return Array.from(this.referenceConfigMap.values());
}
}

View File

@ -3,7 +3,7 @@ import { expect } from "chai";
import { ExternalStylesFactory } from "./external-styles-factory";
describe("External styles factory", () => {
let externalStyles;
let externalStyles: string;
beforeEach(() => {
externalStyles = `

View File

@ -14,11 +14,14 @@ export abstract class XmlAttributeComponent<T extends object> extends BaseXmlCom
}
public prepForXml(_: IContext): IXmlableObject {
const attrs = {};
// eslint-disable-next-line functional/prefer-readonly-type
const attrs: { [key: string]: string } = {};
Object.keys(this.root).forEach((key) => {
const value = this.root[key];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const value = (this.root as any)[key];
if (value !== undefined) {
const newKey = (this.xmlKeys && this.xmlKeys[key]) || key;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const newKey = (this.xmlKeys && (this.xmlKeys as any)[key]) || key;
// eslint-disable-next-line functional/immutable-data
attrs[newKey] = value;
}

View File

@ -2,7 +2,9 @@ export interface IXmlAttribute {
readonly [key: string]: string | number | boolean;
}
export interface IXmlableObject extends Object {
readonly _attr?: IXmlAttribute;
// readonly _attr?: IXmlAttribute;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
readonly [key: string]: any;
}
// Needed because of: https://github.com/s-panferov/awesome-typescript-loader/issues/432