Use new eslint-plugin-functional instead of tslint-immutable
This commit is contained in:
@ -12,7 +12,7 @@ import { Paragraph } from "../paragraph";
|
||||
import { IStylesOptions } from "../styles";
|
||||
|
||||
export interface IPropertiesOptions {
|
||||
readonly sections: ISectionOptions[];
|
||||
readonly sections: readonly ISectionOptions[];
|
||||
readonly title?: string;
|
||||
readonly subject?: string;
|
||||
readonly creator?: string;
|
||||
@ -26,7 +26,7 @@ export interface IPropertiesOptions {
|
||||
readonly comments?: ICommentsOptions;
|
||||
readonly footnotes?: {
|
||||
readonly [key: string]: {
|
||||
readonly children: Paragraph[];
|
||||
readonly children: readonly Paragraph[];
|
||||
};
|
||||
};
|
||||
readonly background?: IDocumentBackgroundOptions;
|
||||
@ -35,7 +35,7 @@ export interface IPropertiesOptions {
|
||||
readonly updateFields?: boolean;
|
||||
};
|
||||
readonly compatabilityModeVersion?: number;
|
||||
readonly customProperties?: ICustomPropertyOptions[];
|
||||
readonly customProperties?: readonly ICustomPropertyOptions[];
|
||||
readonly evenAndOddHeaderAndFooters?: boolean;
|
||||
}
|
||||
|
||||
|
@ -3,11 +3,12 @@ import { CustomPropertiesAttributes } from "./custom-properties-attributes";
|
||||
import { CustomProperty, ICustomPropertyOptions } from "./custom-property";
|
||||
|
||||
export class CustomProperties extends XmlComponent {
|
||||
// tslint:disable-next-line:readonly-keyword
|
||||
// eslint-disable-next-line functional/prefer-readonly-type
|
||||
private nextId: number;
|
||||
// eslint-disable-next-line functional/prefer-readonly-type
|
||||
private readonly properties: CustomProperty[] = [];
|
||||
|
||||
public constructor(properties: ICustomPropertyOptions[]) {
|
||||
public constructor(properties: readonly ICustomPropertyOptions[]) {
|
||||
super("Properties");
|
||||
|
||||
this.root.push(
|
||||
|
@ -4,6 +4,7 @@ import { IContext, IXmlableObject, XmlComponent } from "@file/xml-components";
|
||||
import { ISectionPropertiesOptions, SectionProperties } from "./section-properties/section-properties";
|
||||
|
||||
export class Body extends XmlComponent {
|
||||
// eslint-disable-next-line functional/prefer-readonly-type
|
||||
private readonly sections: SectionProperties[] = [];
|
||||
|
||||
public constructor() {
|
||||
@ -16,6 +17,7 @@ export class Body extends XmlComponent {
|
||||
* The spec says:
|
||||
* - section element should be in the last paragraph of the section
|
||||
* - last section should be direct child of body
|
||||
*
|
||||
* @param options new section options
|
||||
*/
|
||||
public addSection(options: ISectionPropertiesOptions): void {
|
||||
|
@ -17,7 +17,7 @@ export interface IColumnsAttributes {
|
||||
readonly count?: number;
|
||||
readonly separate?: boolean;
|
||||
readonly equalWidth?: boolean;
|
||||
readonly children?: Column[];
|
||||
readonly children?: readonly Column[];
|
||||
}
|
||||
|
||||
export class ColumnsAttributes extends XmlAttributeComponent<IColumnsAttributes> {
|
||||
|
@ -6,8 +6,8 @@ import { IDrawingOptions } from "../drawing";
|
||||
import { TextWrappingType } from "../text-wrap";
|
||||
import { Anchor } from "./anchor";
|
||||
|
||||
const createAnchor = (drawingOptions: IDrawingOptions): Anchor => {
|
||||
return new Anchor(
|
||||
const createAnchor = (drawingOptions: IDrawingOptions): Anchor =>
|
||||
new Anchor(
|
||||
{
|
||||
fileName: "test.png",
|
||||
stream: new Buffer(""),
|
||||
@ -34,7 +34,6 @@ const createAnchor = (drawingOptions: IDrawingOptions): Anchor => {
|
||||
},
|
||||
drawingOptions,
|
||||
);
|
||||
};
|
||||
|
||||
describe("Anchor", () => {
|
||||
let anchor: Anchor;
|
||||
|
@ -6,8 +6,8 @@ import { Drawing, IDrawingOptions } from "./drawing";
|
||||
|
||||
const imageBase64Data = `iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAACzVBMVEUAAAAAAAAAAAAAAAA/AD8zMzMqKiokJCQfHx8cHBwZGRkuFxcqFSonJyckJCQiIiIfHx8eHh4cHBwoGhomGSYkJCQhISEfHx8eHh4nHR0lHBwkGyQjIyMiIiIgICAfHx8mHh4lHh4kHR0jHCMiGyIhISEgICAfHx8lHx8kHh4jHR0hHCEhISEgICAlHx8kHx8jHh4jHh4iHSIhHCE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SHFJHgVXUlxejCCbTvFAHiXdIJiXxyCK7KJ5FHoMZGK9xBcwyg2QpdlVMxEUM2iyIMuXXZQNF+HswxMsSAAJRQjoE//eoqDCXBSTO6f1xd+O0iyNRY6jaWi1ALNYCocZROj4JdEikroVkjFk9DcStXxpdfCD2MoXodu4RUU9ptxxmXssOfxnvDVcxRTod9FxyhqLoAqis5aPhwTDp9spRgEH2Q6KLbYoKqlaKTm6Isp0C/sJMnjFvhiERXPQvUNRe9p29lhR04CdBpC8Sl8YiuncIxEuzUUg4Dkgj+paVozygY9plPMh28SaymO9kabAopREGF3vt9MzeFFl8G7lRSZ8FFGK8XX4VA8QjEd7XrM3M0OXz8YCy+qKBLgq3wqnofiTorF0Ax56Rg1J1elW+BBAsVe+My6iYq7IK6keBdOIseV2qn5Pb8f3MqkWAXf9ThM8c8lAOIotuFsF875lRrH5klRcG0+xcPwQ1oLxfeRAP4heQTnGL78X2rqlw2DK59SXAV/zKaiGMAuko5InCt68mcOan5+ohf+z1pP8lQY/GHZQMV4YD3FpXDp4qerqbF/lBWBswyi+AL+ia+maLgcRRQj4IYlY/UpauqKBsPJAxQF8NM1TRQ/RudSPAD34rK3scOuR8/HGcspxsJfOVS8NZbiGXiUtPgINU3v3WFDmx8pEuG3EiqKKVbCC1vm2iZqap5LAtCtleQf8F9sFYWDohzeJczYyQ4V2bEZFGsQgJRGqqqhS2phHTWn9lDkIhBTqWqxQZ+IsRvtdHY9AvI2VX2hW68nfqGmuQsCEl3JdjfCF8OW1bPdtwhQ0gm2mQzfRE3a7KCYj0BNZJs8+Kxf/r6WtTEI2FIqlsMfFgRB5A6KUnSe/vUkX0AnuvUIt8SjM1m6wWQymUwmk8lkMgXRf5vi8rLQxtUhAAAAAElFTkSuQmCC`;
|
||||
|
||||
const createDrawing = (drawingOptions?: IDrawingOptions): Drawing => {
|
||||
return new Drawing(
|
||||
const createDrawing = (drawingOptions?: IDrawingOptions): Drawing =>
|
||||
new Drawing(
|
||||
{
|
||||
fileName: "test.jpg",
|
||||
stream: Buffer.from(imageBase64Data, "base64"),
|
||||
@ -24,7 +24,6 @@ const createDrawing = (drawingOptions?: IDrawingOptions): Drawing => {
|
||||
},
|
||||
drawingOptions,
|
||||
);
|
||||
};
|
||||
|
||||
describe("Drawing", () => {
|
||||
let currentBreak: Drawing;
|
||||
|
@ -33,15 +33,17 @@ export interface ISectionOptions {
|
||||
readonly even?: Footer;
|
||||
};
|
||||
readonly properties?: ISectionPropertiesOptions;
|
||||
readonly children: (Paragraph | Table | TableOfContents)[];
|
||||
readonly children: readonly (Paragraph | Table | TableOfContents)[];
|
||||
}
|
||||
|
||||
export class File {
|
||||
// tslint:disable-next-line:readonly-keyword
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
private currentRelationshipId: number = 1;
|
||||
|
||||
private readonly documentWrapper: DocumentWrapper;
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
private readonly headers: IDocumentHeader[] = [];
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
private readonly footers: IDocumentFooter[] = [];
|
||||
private readonly coreProperties: CoreProperties;
|
||||
private readonly numbering: Numbering;
|
||||
@ -268,11 +270,11 @@ export class File {
|
||||
return this.fileRelationships;
|
||||
}
|
||||
|
||||
public get Headers(): HeaderWrapper[] {
|
||||
public get Headers(): readonly HeaderWrapper[] {
|
||||
return this.headers.map((item) => item.header);
|
||||
}
|
||||
|
||||
public get Footers(): FooterWrapper[] {
|
||||
public get Footers(): readonly FooterWrapper[] {
|
||||
return this.footers.map((item) => item.footer);
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ describe("FooterWrapper", () => {
|
||||
it("should call the underlying footer's addChildElement", () => {
|
||||
const file = new FooterWrapper(new Media(), 1);
|
||||
const spy = sinon.spy(file.View, "addChildElement");
|
||||
// tslint:disable-next-line:no-any
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
file.addChildElement({} as any);
|
||||
|
||||
expect(spy.called).to.equal(true);
|
||||
|
@ -12,7 +12,7 @@ export enum FootnoteType {
|
||||
export interface IFootnoteOptions {
|
||||
readonly id: number;
|
||||
readonly type?: FootnoteType;
|
||||
readonly children: Paragraph[];
|
||||
readonly children: readonly Paragraph[];
|
||||
}
|
||||
|
||||
export class Footnote extends XmlComponent {
|
||||
|
@ -67,7 +67,7 @@ export class FootNotes extends XmlComponent {
|
||||
this.root.push(spacing);
|
||||
}
|
||||
|
||||
public createFootNote(id: number, paragraph: Paragraph[]): void {
|
||||
public createFootNote(id: number, paragraph: readonly Paragraph[]): void {
|
||||
const footnote = new Footnote({
|
||||
id: id,
|
||||
children: paragraph,
|
||||
|
@ -41,7 +41,7 @@ describe("HeaderWrapper", () => {
|
||||
it("should call the underlying header's addChildElement", () => {
|
||||
const file = new HeaderWrapper(new Media(), 1);
|
||||
const spy = sinon.spy(file.View, "addChildElement");
|
||||
// tslint:disable-next-line:no-any
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
file.addChildElement({} as any);
|
||||
|
||||
expect(spy.called).to.equal(true);
|
||||
|
@ -2,13 +2,17 @@ import { Paragraph } from "./paragraph";
|
||||
import { Table } from "./table";
|
||||
|
||||
export interface IHeaderOptions {
|
||||
readonly children: (Paragraph | Table)[];
|
||||
readonly children: readonly (Paragraph | Table)[];
|
||||
}
|
||||
|
||||
export class Header {
|
||||
public constructor(public readonly options: IHeaderOptions = { children: [] }) {}
|
||||
public constructor(public readonly options: IHeaderOptions = { children: [] }) {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
|
||||
export class Footer {
|
||||
public constructor(public readonly options: IHeaderOptions = { children: [] }) {}
|
||||
public constructor(public readonly options: IHeaderOptions = { children: [] }) {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ export interface IMediaTransformation {
|
||||
}
|
||||
|
||||
export class Media {
|
||||
// eslint-disable-next-line functional/prefer-readonly-type
|
||||
private readonly map: Map<string, IMediaData>;
|
||||
|
||||
public constructor() {
|
||||
@ -68,9 +69,8 @@ export class Media {
|
||||
.map((c) => c.charCodeAt(0)),
|
||||
);
|
||||
} else {
|
||||
/* eslint @typescript-eslint/no-require-imports: 0 */
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
||||
const b = require("buf" + "fer");
|
||||
/* eslint @typescript-eslint/no-require-imports: 2 */
|
||||
return new b.Buffer(dataURI, "base64");
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ class AbstractNumberingAttributes extends XmlAttributeComponent<{
|
||||
export class AbstractNumbering extends XmlComponent {
|
||||
public readonly id: number;
|
||||
|
||||
public constructor(id: number, levelOptions: ILevelsOptions[]) {
|
||||
public constructor(id: number, levelOptions: readonly ILevelsOptions[]) {
|
||||
super("w:abstractNum");
|
||||
this.root.push(
|
||||
new AbstractNumberingAttributes({
|
||||
|
@ -2,8 +2,8 @@ import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { Level, LevelFormat, LevelSuffix } from "./level";
|
||||
import { AlignmentType } from "..";
|
||||
import { Level, LevelFormat, LevelSuffix } from "./level";
|
||||
|
||||
describe("Level", () => {
|
||||
describe("#constructor", () => {
|
||||
|
@ -118,7 +118,7 @@ class Suffix extends XmlComponent {
|
||||
// http://officeopenxml.com/WPnumbering-isLgl.php
|
||||
// https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.islegalnumberingstyle?view=openxml-2.8.1
|
||||
class IsLegalNumberingStyle extends XmlComponent {
|
||||
constructor() {
|
||||
public constructor() {
|
||||
super("w:isLgl");
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ import { ILevelsOptions, LevelFormat } from "./level";
|
||||
import { ConcreteNumbering } from "./num";
|
||||
|
||||
export interface INumberingOptions {
|
||||
readonly config: {
|
||||
readonly levels: ILevelsOptions[];
|
||||
readonly config: readonly {
|
||||
readonly levels: readonly ILevelsOptions[];
|
||||
readonly reference: string;
|
||||
}[];
|
||||
}
|
||||
@ -203,33 +203,33 @@ export class Numbering extends XmlComponent {
|
||||
return;
|
||||
}
|
||||
|
||||
const referenceConfigLevels = this.referenceConfigMap.get(reference);
|
||||
const firstLevelStartNumber = referenceConfigLevels && referenceConfigLevels[0].start;
|
||||
|
||||
const concreteNumberingSettings = {
|
||||
numId: uniqueNumericId(),
|
||||
abstractNumId: abstractNumbering.id,
|
||||
reference,
|
||||
instance,
|
||||
overrideLevel: {
|
||||
num: 0,
|
||||
start: 1,
|
||||
},
|
||||
overrideLevel:
|
||||
firstLevelStartNumber && Number.isInteger(firstLevelStartNumber)
|
||||
? {
|
||||
num: 0,
|
||||
start: firstLevelStartNumber,
|
||||
}
|
||||
: {
|
||||
num: 0,
|
||||
start: 1,
|
||||
},
|
||||
};
|
||||
|
||||
const referenceConfigLevels = this.referenceConfigMap.get(reference);
|
||||
const firstLevelStartNumber = referenceConfigLevels && referenceConfigLevels[0].start;
|
||||
if (firstLevelStartNumber && Number.isInteger(firstLevelStartNumber)) {
|
||||
concreteNumberingSettings.overrideLevel = {
|
||||
num: 0,
|
||||
start: firstLevelStartNumber,
|
||||
};
|
||||
}
|
||||
|
||||
this.concreteNumberingMap.set(fullReference, new ConcreteNumbering(concreteNumberingSettings));
|
||||
}
|
||||
|
||||
public get ConcreteNumbering(): ConcreteNumbering[] {
|
||||
public get ConcreteNumbering(): readonly ConcreteNumbering[] {
|
||||
return Array.from(this.concreteNumberingMap.values());
|
||||
}
|
||||
public get ReferenceConfig(): object[] {
|
||||
public get ReferenceConfig(): readonly object[] {
|
||||
return Array.from(this.referenceConfigMap.values());
|
||||
}
|
||||
}
|
||||
|
@ -7,10 +7,10 @@ import { BookmarkEndAttributes, BookmarkStartAttributes } from "./bookmark-attri
|
||||
|
||||
export class Bookmark {
|
||||
public readonly start: BookmarkStart;
|
||||
public readonly children: ParagraphChild[];
|
||||
public readonly children: readonly ParagraphChild[];
|
||||
public readonly end: BookmarkEnd;
|
||||
|
||||
public constructor(options: { readonly id: string; readonly children: ParagraphChild[] }) {
|
||||
public constructor(options: { readonly id: string; readonly children: readonly ParagraphChild[] }) {
|
||||
const linkId = uniqueNumericId();
|
||||
|
||||
this.start = new BookmarkStart(options.id, linkId);
|
||||
|
@ -13,7 +13,7 @@ export enum HyperlinkType {
|
||||
export class ConcreteHyperlink extends XmlComponent {
|
||||
public readonly linkId: string;
|
||||
|
||||
public constructor(children: ParagraphChild[], relationshipId: string, anchor?: string) {
|
||||
public constructor(children: readonly ParagraphChild[], relationshipId: string, anchor?: string) {
|
||||
super("w:hyperlink");
|
||||
|
||||
this.linkId = relationshipId;
|
||||
@ -33,13 +33,13 @@ export class ConcreteHyperlink extends XmlComponent {
|
||||
}
|
||||
|
||||
export class InternalHyperlink extends ConcreteHyperlink {
|
||||
public constructor(options: { readonly children: ParagraphChild[]; readonly anchor: string }) {
|
||||
public constructor(options: { readonly children: readonly ParagraphChild[]; readonly anchor: string }) {
|
||||
super(options.children, uniqueId(), options.anchor);
|
||||
}
|
||||
}
|
||||
|
||||
export class ExternalHyperlink extends XmlComponent {
|
||||
public constructor(public readonly options: { readonly children: ParagraphChild[]; readonly link: string }) {
|
||||
public constructor(public readonly options: { readonly children: readonly ParagraphChild[]; readonly link: string }) {
|
||||
super("w:externalHyperlink");
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import { MathBase } from "../n-ary";
|
||||
import { MathBracketProperties } from "./math-bracket-properties";
|
||||
|
||||
export class MathAngledBrackets extends XmlComponent {
|
||||
public constructor(options: { readonly children: MathComponent[] }) {
|
||||
public constructor(options: { readonly children: readonly MathComponent[] }) {
|
||||
super("m:d");
|
||||
|
||||
this.root.push(
|
||||
|
@ -6,7 +6,7 @@ import { MathBase } from "../n-ary";
|
||||
import { MathBracketProperties } from "./math-bracket-properties";
|
||||
|
||||
export class MathCurlyBrackets extends XmlComponent {
|
||||
public constructor(options: { readonly children: MathComponent[] }) {
|
||||
public constructor(options: { readonly children: readonly MathComponent[] }) {
|
||||
super("m:d");
|
||||
|
||||
this.root.push(
|
||||
|
@ -6,7 +6,7 @@ import { MathBase } from "../n-ary";
|
||||
import { MathBracketProperties } from "./math-bracket-properties";
|
||||
|
||||
export class MathRoundBrackets extends XmlComponent {
|
||||
public constructor(options: { readonly children: MathComponent[] }) {
|
||||
public constructor(options: { readonly children: readonly MathComponent[] }) {
|
||||
super("m:d");
|
||||
|
||||
this.root.push(new MathBracketProperties());
|
||||
|
@ -6,7 +6,7 @@ import { MathBase } from "../n-ary";
|
||||
import { MathBracketProperties } from "./math-bracket-properties";
|
||||
|
||||
export class MathSquareBrackets extends XmlComponent {
|
||||
public constructor(options: { readonly children: MathComponent[] }) {
|
||||
public constructor(options: { readonly children: readonly MathComponent[] }) {
|
||||
super("m:d");
|
||||
|
||||
this.root.push(
|
||||
|
@ -3,7 +3,7 @@ import { XmlComponent } from "@file/xml-components";
|
||||
import { MathComponent } from "../math-component";
|
||||
|
||||
export class MathDenominator extends XmlComponent {
|
||||
public constructor(children: MathComponent[]) {
|
||||
public constructor(children: readonly MathComponent[]) {
|
||||
super("m:den");
|
||||
|
||||
for (const child of children) {
|
||||
|
@ -5,8 +5,8 @@ import { MathDenominator } from "./math-denominator";
|
||||
import { MathNumerator } from "./math-numerator";
|
||||
|
||||
export interface IMathFractionOptions {
|
||||
readonly numerator: MathComponent[];
|
||||
readonly denominator: MathComponent[];
|
||||
readonly numerator: readonly MathComponent[];
|
||||
readonly denominator: readonly MathComponent[];
|
||||
}
|
||||
|
||||
export class MathFraction extends XmlComponent {
|
||||
|
@ -3,7 +3,7 @@ import { XmlComponent } from "@file/xml-components";
|
||||
import { MathComponent } from "../math-component";
|
||||
|
||||
export class MathNumerator extends XmlComponent {
|
||||
public constructor(children: MathComponent[]) {
|
||||
public constructor(children: readonly MathComponent[]) {
|
||||
super("m:num");
|
||||
|
||||
for (const child of children) {
|
||||
|
@ -3,7 +3,7 @@ import { XmlComponent } from "@file/xml-components";
|
||||
import { MathComponent } from "../math-component";
|
||||
|
||||
export class MathFunctionName extends XmlComponent {
|
||||
public constructor(children: MathComponent[]) {
|
||||
public constructor(children: readonly MathComponent[]) {
|
||||
super("m:fName");
|
||||
|
||||
for (const child of children) {
|
||||
|
@ -7,8 +7,8 @@ import { MathFunctionName } from "./math-function-name";
|
||||
import { MathFunctionProperties } from "./math-function-properties";
|
||||
|
||||
export interface IMathFunctionOptions {
|
||||
readonly children: MathComponent[];
|
||||
readonly name: MathComponent[];
|
||||
readonly children: readonly MathComponent[];
|
||||
readonly name: readonly MathComponent[];
|
||||
}
|
||||
|
||||
export class MathFunction extends XmlComponent {
|
||||
|
@ -4,7 +4,7 @@ import { XmlComponent } from "@file/xml-components";
|
||||
import { MathComponent } from "./math-component";
|
||||
|
||||
export interface IMathOptions {
|
||||
readonly children: MathComponent[];
|
||||
readonly children: readonly MathComponent[];
|
||||
}
|
||||
|
||||
export class Math extends XmlComponent {
|
||||
|
@ -4,7 +4,7 @@ import { XmlComponent } from "@file/xml-components";
|
||||
import { MathComponent } from "../math-component";
|
||||
|
||||
export class MathBase extends XmlComponent {
|
||||
public constructor(children: MathComponent[]) {
|
||||
public constructor(children: readonly MathComponent[]) {
|
||||
super("m:e");
|
||||
|
||||
for (const child of children) {
|
||||
|
@ -4,7 +4,7 @@ import { XmlComponent } from "@file/xml-components";
|
||||
import { MathComponent } from "../math-component";
|
||||
|
||||
export class MathSubScriptElement extends XmlComponent {
|
||||
public constructor(children: MathComponent[]) {
|
||||
public constructor(children: readonly MathComponent[]) {
|
||||
super("m:sub");
|
||||
|
||||
for (const child of children) {
|
||||
|
@ -8,9 +8,9 @@ import { MathSubScriptElement } from "./math-sub-script";
|
||||
import { MathSuperScriptElement } from "./math-super-script";
|
||||
|
||||
export interface IMathSumOptions {
|
||||
readonly children: MathComponent[];
|
||||
readonly subScript?: MathComponent[];
|
||||
readonly superScript?: MathComponent[];
|
||||
readonly children: readonly MathComponent[];
|
||||
readonly subScript?: readonly MathComponent[];
|
||||
readonly superScript?: readonly MathComponent[];
|
||||
}
|
||||
|
||||
export class MathSum extends XmlComponent {
|
||||
|
@ -4,7 +4,7 @@ import { XmlComponent } from "@file/xml-components";
|
||||
import { MathComponent } from "../math-component";
|
||||
|
||||
export class MathSuperScriptElement extends XmlComponent {
|
||||
public constructor(children: MathComponent[]) {
|
||||
public constructor(children: readonly MathComponent[]) {
|
||||
super("m:sup");
|
||||
|
||||
for (const child of children) {
|
||||
|
@ -3,7 +3,7 @@ import { XmlComponent } from "@file/xml-components";
|
||||
import { MathComponent } from "../math-component";
|
||||
|
||||
export class MathDegree extends XmlComponent {
|
||||
public constructor(children?: MathComponent[]) {
|
||||
public constructor(children?: readonly MathComponent[]) {
|
||||
super("m:deg");
|
||||
|
||||
if (!!children) {
|
||||
|
@ -7,8 +7,8 @@ import { MathDegree } from "./math-degree";
|
||||
import { MathRadicalProperties } from "./math-radical-properties";
|
||||
|
||||
export interface IMathRadicalOptions {
|
||||
readonly children: MathComponent[];
|
||||
readonly degree?: MathComponent[];
|
||||
readonly children: readonly MathComponent[];
|
||||
readonly degree?: readonly MathComponent[];
|
||||
}
|
||||
|
||||
export class MathRadical extends XmlComponent {
|
||||
|
@ -6,9 +6,9 @@ import { MathBase, MathSubScriptElement, MathSuperScriptElement } from "../../n-
|
||||
import { MathPreSubSuperScriptProperties } from "./math-pre-sub-super-script-function-properties";
|
||||
|
||||
export interface IMathPreSubSuperScriptOptions {
|
||||
readonly children: MathComponent[];
|
||||
readonly subScript: MathComponent[];
|
||||
readonly superScript: MathComponent[];
|
||||
readonly children: readonly MathComponent[];
|
||||
readonly subScript: readonly MathComponent[];
|
||||
readonly superScript: readonly MathComponent[];
|
||||
}
|
||||
|
||||
export class MathPreSubSuperScript extends XmlComponent {
|
||||
|
@ -6,8 +6,8 @@ import { MathBase, MathSubScriptElement } from "../../n-ary";
|
||||
import { MathSubScriptProperties } from "./math-sub-script-function-properties";
|
||||
|
||||
export interface IMathSubScriptOptions {
|
||||
readonly children: MathComponent[];
|
||||
readonly subScript: MathComponent[];
|
||||
readonly children: readonly MathComponent[];
|
||||
readonly subScript: readonly MathComponent[];
|
||||
}
|
||||
|
||||
export class MathSubScript extends XmlComponent {
|
||||
|
@ -6,9 +6,9 @@ import { MathBase, MathSubScriptElement, MathSuperScriptElement } from "../../n-
|
||||
import { MathSubSuperScriptProperties } from "./math-sub-super-script-function-properties";
|
||||
|
||||
export interface IMathSubSuperScriptOptions {
|
||||
readonly children: MathComponent[];
|
||||
readonly subScript: MathComponent[];
|
||||
readonly superScript: MathComponent[];
|
||||
readonly children: readonly MathComponent[];
|
||||
readonly subScript: readonly MathComponent[];
|
||||
readonly superScript: readonly MathComponent[];
|
||||
}
|
||||
|
||||
export class MathSubSuperScript extends XmlComponent {
|
||||
|
@ -6,8 +6,8 @@ import { MathBase, MathSuperScriptElement } from "../../n-ary";
|
||||
import { MathSuperScriptProperties } from "./math-super-script-function-properties";
|
||||
|
||||
export interface IMathSuperScriptOptions {
|
||||
readonly children: MathComponent[];
|
||||
readonly superScript: MathComponent[];
|
||||
readonly children: readonly MathComponent[];
|
||||
readonly superScript: readonly MathComponent[];
|
||||
}
|
||||
|
||||
export class MathSuperScript extends XmlComponent {
|
||||
|
@ -36,7 +36,7 @@ export type ParagraphChild =
|
||||
|
||||
export interface IParagraphOptions extends IParagraphPropertiesOptions {
|
||||
readonly text?: string;
|
||||
readonly children?: ParagraphChild[];
|
||||
readonly children?: readonly ParagraphChild[];
|
||||
}
|
||||
|
||||
export class Paragraph extends XmlComponent {
|
||||
|
@ -26,9 +26,7 @@ describe("ParagraphProperties", () => {
|
||||
// tslint:disable-next-line: no-object-literal-type-assertion
|
||||
file: {
|
||||
Numbering: {
|
||||
createConcreteNumberingInstance: (_: string, __: number) => {
|
||||
return;
|
||||
},
|
||||
createConcreteNumberingInstance: (_: string, __: number) => undefined,
|
||||
},
|
||||
} as File,
|
||||
// tslint:disable-next-line: no-object-literal-type-assertion
|
||||
|
@ -41,7 +41,7 @@ export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOp
|
||||
readonly heading?: HeadingLevel;
|
||||
readonly bidirectional?: boolean;
|
||||
readonly pageBreakBefore?: boolean;
|
||||
readonly tabStops?: {
|
||||
readonly tabStops?: readonly {
|
||||
readonly position: number | TabStopPosition;
|
||||
readonly type: TabStopType;
|
||||
readonly leader?: LeaderType;
|
||||
@ -57,6 +57,7 @@ export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOp
|
||||
}
|
||||
|
||||
export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
|
||||
// eslint-disable-next-line functional/prefer-readonly-type
|
||||
private readonly numberingReferences: { readonly reference: string; readonly instance: number }[] = [];
|
||||
|
||||
public constructor(options?: IParagraphPropertiesOptions) {
|
||||
|
@ -12,7 +12,7 @@ export interface ICommentOptions {
|
||||
}
|
||||
|
||||
export interface ICommentsOptions {
|
||||
readonly children: ICommentOptions[];
|
||||
readonly children: readonly ICommentOptions[];
|
||||
}
|
||||
|
||||
class CommentAttributes extends XmlAttributeComponent<{
|
||||
|
@ -40,7 +40,7 @@ describe("ImageRun", () => {
|
||||
const tree = new Formatter().format(currentImageRun, {
|
||||
file: {
|
||||
Media: {
|
||||
// tslint:disable-next-line: no-empty
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
addImage: () => {},
|
||||
},
|
||||
} as unknown as File,
|
||||
@ -290,7 +290,7 @@ describe("ImageRun", () => {
|
||||
const tree = new Formatter().format(currentImageRun, {
|
||||
file: {
|
||||
Media: {
|
||||
// tslint:disable-next-line: no-empty
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
addImage: () => {},
|
||||
},
|
||||
} as unknown as File,
|
||||
@ -519,6 +519,7 @@ describe("ImageRun", () => {
|
||||
});
|
||||
|
||||
it("should return UInt8Array if atob is present", () => {
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
global.atob = () => "atob result";
|
||||
|
||||
const currentImageRun = new ImageRun({
|
||||
@ -542,7 +543,7 @@ describe("ImageRun", () => {
|
||||
const tree = new Formatter().format(currentImageRun, {
|
||||
file: {
|
||||
Media: {
|
||||
// tslint:disable-next-line: no-empty
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
addImage: () => {},
|
||||
},
|
||||
} as unknown as File,
|
||||
@ -775,6 +776,7 @@ describe("ImageRun", () => {
|
||||
});
|
||||
|
||||
it("should use data as is if its not a string", () => {
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
global.atob = () => "atob result";
|
||||
|
||||
const currentImageRun = new ImageRun({
|
||||
@ -798,7 +800,7 @@ describe("ImageRun", () => {
|
||||
const tree = new Formatter().format(currentImageRun, {
|
||||
file: {
|
||||
Media: {
|
||||
// tslint:disable-next-line: no-empty
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
addImage: () => {},
|
||||
},
|
||||
} as unknown as File,
|
||||
|
@ -62,6 +62,7 @@ export class ImageRun extends Run {
|
||||
.map((c) => c.charCodeAt(0)),
|
||||
);
|
||||
} else {
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
||||
const b = require("buf" + "fer");
|
||||
return new b.Buffer(dataURI, "base64");
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import { Text } from "./run-components/text";
|
||||
import { TextAttributes } from "./text-attributes";
|
||||
|
||||
export interface IRunOptions extends IRunPropertiesOptions {
|
||||
readonly children?: (Begin | FieldInstruction | Separate | End | PageNumber | FootnoteReferenceRun | string)[];
|
||||
readonly children?: readonly (Begin | FieldInstruction | Separate | End | PageNumber | FootnoteReferenceRun | string)[];
|
||||
readonly break?: number;
|
||||
readonly text?: string;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ describe("External styles factory", () => {
|
||||
|
||||
describe("#parse", () => {
|
||||
it("should parse w:styles attributes", () => {
|
||||
// tslint:disable-next-line:no-any
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const importedStyle = new ExternalStylesFactory().newInstance(externalStyles) as any;
|
||||
|
||||
expect(importedStyle.rootKey).to.equal("w:styles");
|
||||
@ -59,7 +59,7 @@ describe("External styles factory", () => {
|
||||
});
|
||||
|
||||
it("should parse other child elements of w:styles", () => {
|
||||
// tslint:disable-next-line:no-any
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const importedStyle = new ExternalStylesFactory().newInstance(externalStyles) as any;
|
||||
expect(importedStyle.root[1]).to.deep.equal({
|
||||
root: [
|
||||
@ -147,7 +147,7 @@ describe("External styles factory", () => {
|
||||
});
|
||||
|
||||
it("should parse styles elements", () => {
|
||||
// tslint:disable-next-line:no-any
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const importedStyle = new ExternalStylesFactory().newInstance(externalStyles) as any;
|
||||
|
||||
expect(importedStyle.root.length).to.equal(5);
|
||||
|
@ -23,6 +23,7 @@ export class ExternalStylesFactory {
|
||||
* <w:docDefaults>Or any other element will be parsed to</w:docDefaults>
|
||||
*
|
||||
* </w:styles>
|
||||
*
|
||||
* @param externalStyles context from styles.xml
|
||||
*/
|
||||
public newInstance(xmlData: string): Styles {
|
||||
|
@ -1,4 +1,4 @@
|
||||
const createLsdException = (name, uiPriority, qFormat?, semiHidden?, unhideWhenUsed?) => {
|
||||
const createLsdException = (name: string, uiPriority?: number, qFormat?: number, semiHidden?: number, unhideWhenUsed?: number) => {
|
||||
"use strict";
|
||||
|
||||
return [
|
||||
@ -14,8 +14,9 @@ const createLsdException = (name, uiPriority, qFormat?, semiHidden?, unhideWhenU
|
||||
];
|
||||
};
|
||||
|
||||
export const DefaultStyle = () => {
|
||||
var style = {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export const DefaultStyle = (): Record<string, any> => {
|
||||
const style = {
|
||||
"w:styles": [
|
||||
{
|
||||
_attr: {
|
||||
|
@ -7,9 +7,9 @@ import { IParagraphStyleOptions } from "./style/paragraph-style";
|
||||
export interface IStylesOptions {
|
||||
readonly default?: IDefaultStylesOptions;
|
||||
readonly initialStyles?: BaseXmlComponent;
|
||||
readonly paragraphStyles?: IParagraphStyleOptions[];
|
||||
readonly characterStyles?: ICharacterStyleOptions[];
|
||||
readonly importedStyles?: (XmlComponent | StyleForParagraph | StyleForCharacter | ImportedXmlComponent)[];
|
||||
readonly paragraphStyles?: readonly IParagraphStyleOptions[];
|
||||
readonly characterStyles?: readonly ICharacterStyleOptions[];
|
||||
readonly importedStyles?: readonly (XmlComponent | StyleForParagraph | StyleForCharacter | ImportedXmlComponent)[];
|
||||
}
|
||||
|
||||
// <xsd:complexType name="CT_Styles">
|
||||
|
@ -98,7 +98,7 @@ export interface ITableOfContentsOptions {
|
||||
* with each doublet being a comma-separated set of style name and table of content level.
|
||||
* \t can be combined with \o.
|
||||
*/
|
||||
readonly stylesWithLevels?: StyleLevel[];
|
||||
readonly stylesWithLevels?: readonly StyleLevel[];
|
||||
|
||||
/**
|
||||
* \u Uses the applied paragraph outline level.
|
||||
|
@ -14,9 +14,7 @@ describe("Table of Contents", () => {
|
||||
});
|
||||
|
||||
it("should construct a TOC with all the options and alias", () => {
|
||||
const styles = new Array<StyleLevel>();
|
||||
styles.push(new StyleLevel("SL", 1));
|
||||
styles.push(new StyleLevel("SL", 2));
|
||||
const styles = [new StyleLevel("SL", 1), new StyleLevel("SL", 2)];
|
||||
|
||||
const props = {
|
||||
captionLabel: "A",
|
||||
|
@ -13,7 +13,7 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { twipsMeasureValue } from "@util/values";
|
||||
|
||||
export class TableGrid extends XmlComponent {
|
||||
public constructor(widths: number[] | string[]) {
|
||||
public constructor(widths: readonly number[] | readonly string[]) {
|
||||
super("w:tblGrid");
|
||||
for (const width of widths) {
|
||||
this.root.push(new GridCol(width));
|
||||
|
@ -6,7 +6,7 @@ import { Table } from "../table";
|
||||
import { ITableCellPropertiesOptions, TableCellProperties } from "./table-cell-properties";
|
||||
|
||||
export interface ITableCellOptions extends ITableCellPropertiesOptions {
|
||||
readonly children: (Paragraph | Table)[];
|
||||
readonly children: readonly (Paragraph | Table)[];
|
||||
}
|
||||
|
||||
export class TableCell extends XmlComponent {
|
||||
|
@ -3,7 +3,7 @@ import { TableCell } from "../table-cell";
|
||||
import { ITableRowPropertiesOptions, TableRowProperties } from "./table-row-properties";
|
||||
|
||||
export interface ITableRowOptions extends ITableRowPropertiesOptions {
|
||||
readonly children: TableCell[];
|
||||
readonly children: readonly TableCell[];
|
||||
}
|
||||
|
||||
export class TableRow extends XmlComponent {
|
||||
@ -20,7 +20,7 @@ export class TableRow extends XmlComponent {
|
||||
return this.options.children.length;
|
||||
}
|
||||
|
||||
public get cells(): TableCell[] {
|
||||
public get cells(): readonly TableCell[] {
|
||||
return this.root.filter((xmlComponent) => xmlComponent instanceof TableCell);
|
||||
}
|
||||
|
||||
|
@ -21,9 +21,9 @@ import { ITableWidthProperties } from "./table-width";
|
||||
algorithm will expand columns to fit its content
|
||||
*/
|
||||
export interface ITableOptions {
|
||||
readonly rows: TableRow[];
|
||||
readonly rows: readonly TableRow[];
|
||||
readonly width?: ITableWidthProperties;
|
||||
readonly columnWidths?: number[];
|
||||
readonly columnWidths?: readonly number[];
|
||||
readonly margins?: ITableCellMarginOptions;
|
||||
readonly indent?: ITableWidthProperties;
|
||||
readonly float?: ITableFloatOptions;
|
||||
@ -38,6 +38,7 @@ export class Table extends XmlComponent {
|
||||
public constructor({
|
||||
rows,
|
||||
width,
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
columnWidths = Array<number>(Math.max(...rows.map((row) => row.CellCount))).fill(100),
|
||||
margins,
|
||||
indent,
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { BaseXmlComponent, IContext } from "./base";
|
||||
import { IXmlableObject } from "./xmlable-object";
|
||||
|
||||
export type AttributeMap<T> = { [P in keyof T]: string };
|
||||
export type AttributeMap<T> = { readonly [P in keyof T]: string };
|
||||
|
||||
export abstract class XmlAttributeComponent<T> extends BaseXmlComponent {
|
||||
export abstract class XmlAttributeComponent<T extends object> extends BaseXmlComponent {
|
||||
// tslint:disable-next-line:readonly-keyword
|
||||
protected root: T;
|
||||
protected readonly root: T;
|
||||
protected readonly xmlKeys?: AttributeMap<T>;
|
||||
|
||||
public constructor(properties: T) {
|
||||
@ -19,6 +19,7 @@ export abstract class XmlAttributeComponent<T> extends BaseXmlComponent {
|
||||
const value = this.root[key];
|
||||
if (value !== undefined) {
|
||||
const newKey = (this.xmlKeys && this.xmlKeys[key]) || key;
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
attrs[newKey] = value;
|
||||
}
|
||||
});
|
||||
|
@ -1,4 +1,4 @@
|
||||
// tslint:disable:no-any
|
||||
// eslint-disable @typescript-eslint/no-explicit-any
|
||||
import { Element as XmlElement, xml2js } from "xml-js";
|
||||
|
||||
import { IXmlableObject, XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
@ -7,6 +7,7 @@ import { IContext } from "./base";
|
||||
|
||||
/**
|
||||
* Converts the given xml element (in json format) into XmlComponent.
|
||||
*
|
||||
* @param element the xml element in json presentation
|
||||
*/
|
||||
|
||||
|
@ -4,7 +4,7 @@ import { IXmlableObject } from "./xmlable-object";
|
||||
export const EMPTY_OBJECT = Object.seal({});
|
||||
|
||||
export abstract class XmlComponent extends BaseXmlComponent {
|
||||
// tslint:disable-next-line:readonly-keyword no-any
|
||||
// eslint-disable-next-line functional/prefer-readonly-type, @typescript-eslint/no-explicit-any
|
||||
protected root: (BaseXmlComponent | string | any)[];
|
||||
|
||||
public constructor(rootKey: string) {
|
||||
@ -46,5 +46,7 @@ export abstract class IgnoreIfEmptyXmlComponent extends XmlComponent {
|
||||
if (result && (typeof result[this.rootKey] !== "object" || Object.keys(result[this.rootKey]).length)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user