Make fields readonly
This commit is contained in:
@ -5,10 +5,9 @@ import { Compiler } from "./compiler";
|
|||||||
import { IPacker } from "./packer";
|
import { IPacker } from "./packer";
|
||||||
|
|
||||||
export class ExpressPacker implements IPacker {
|
export class ExpressPacker implements IPacker {
|
||||||
private res: express.Response;
|
private readonly packer: Compiler;
|
||||||
private packer: Compiler;
|
|
||||||
|
|
||||||
constructor(file: File, res: express.Response) {
|
constructor(file: File, private readonly res: express.Response) {
|
||||||
this.packer = new Compiler(file);
|
this.packer = new Compiler(file);
|
||||||
|
|
||||||
this.res = res;
|
this.res = res;
|
||||||
|
@ -9,8 +9,8 @@ import { PdfConvertWrapper } from "./pdf-convert-wrapper";
|
|||||||
|
|
||||||
export class LocalPacker implements IPacker {
|
export class LocalPacker implements IPacker {
|
||||||
private stream: fs.WriteStream;
|
private stream: fs.WriteStream;
|
||||||
private pdfConverter: PdfConvertWrapper;
|
private readonly pdfConverter: PdfConvertWrapper;
|
||||||
private packer: Compiler;
|
private readonly packer: Compiler;
|
||||||
|
|
||||||
constructor(file: File) {
|
constructor(file: File) {
|
||||||
this.pdfConverter = new PdfConvertWrapper();
|
this.pdfConverter = new PdfConvertWrapper();
|
||||||
|
@ -8,7 +8,7 @@ import { SectionPropertiesOptions } from "./body/section-properties/section-prop
|
|||||||
import { DocumentAttributes } from "./document-attributes";
|
import { DocumentAttributes } from "./document-attributes";
|
||||||
|
|
||||||
export class Document extends XmlComponent {
|
export class Document extends XmlComponent {
|
||||||
private body: Body;
|
private readonly body: Body;
|
||||||
|
|
||||||
constructor(sectionPropertiesOptions?: SectionPropertiesOptions) {
|
constructor(sectionPropertiesOptions?: SectionPropertiesOptions) {
|
||||||
super("w:document");
|
super("w:document");
|
||||||
|
@ -2,10 +2,11 @@ import * as fs from "fs";
|
|||||||
import * as sizeOf from "image-size";
|
import * as sizeOf from "image-size";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
|
|
||||||
|
import { Relationships } from "file/relationships/relationships";
|
||||||
import { IMediaData } from "./data";
|
import { IMediaData } from "./data";
|
||||||
|
|
||||||
export class Media {
|
export class Media {
|
||||||
private map: Map<string, IMediaData>;
|
private readonly map: Map<string, IMediaData>;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.map = new Map<string, IMediaData>();
|
this.map = new Map<string, IMediaData>();
|
||||||
@ -21,12 +22,12 @@ export class Media {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public addMedia(filePath: string): IMediaData {
|
public addMedia(filePath: string, relationshipsCount: number): IMediaData {
|
||||||
const key = path.basename(filePath);
|
const key = path.basename(filePath);
|
||||||
const dimensions = sizeOf(filePath);
|
const dimensions = sizeOf(filePath);
|
||||||
|
|
||||||
const imageData = {
|
const imageData = {
|
||||||
referenceId: this.map.size + 3,
|
referenceId: this.map.size + relationshipsCount,
|
||||||
stream: fs.createReadStream(filePath),
|
stream: fs.createReadStream(filePath),
|
||||||
path: filePath,
|
path: filePath,
|
||||||
fileName: key,
|
fileName: key,
|
||||||
|
@ -61,8 +61,8 @@ class LevelJc extends XmlComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class LevelBase extends XmlComponent {
|
export class LevelBase extends XmlComponent {
|
||||||
private paragraphProperties: ParagraphProperties;
|
private readonly paragraphProperties: ParagraphProperties;
|
||||||
private runProperties: RunProperties;
|
private readonly runProperties: RunProperties;
|
||||||
|
|
||||||
constructor(level: number, start?: number, numberFormat?: string, levelText?: string, lvlJc?: string) {
|
constructor(level: number, start?: number, numberFormat?: string, levelText?: string, lvlJc?: string) {
|
||||||
super("w:lvl");
|
super("w:lvl");
|
||||||
|
@ -46,16 +46,14 @@ class LevelOverrideAttributes extends XmlAttributeComponent<{ ilvl: number }> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class LevelOverride extends XmlComponent {
|
export class LevelOverride extends XmlComponent {
|
||||||
private levelNum: number;
|
|
||||||
private lvl?: LevelForOverride;
|
private lvl?: LevelForOverride;
|
||||||
|
|
||||||
constructor(levelNum: number, start?: number) {
|
constructor(private readonly levelNum: number, start?: number) {
|
||||||
super("w:lvlOverride");
|
super("w:lvlOverride");
|
||||||
this.root.push(new LevelOverrideAttributes({ ilvl: levelNum }));
|
this.root.push(new LevelOverrideAttributes({ ilvl: levelNum }));
|
||||||
if (start !== undefined) {
|
if (start !== undefined) {
|
||||||
this.root.push(new StartOverride(start));
|
this.root.push(new StartOverride(start));
|
||||||
}
|
}
|
||||||
this.levelNum = levelNum;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get level(): LevelForOverride {
|
get level(): LevelForOverride {
|
||||||
|
@ -13,6 +13,7 @@ export class Relationships extends XmlComponent {
|
|||||||
|
|
||||||
this.createRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml");
|
this.createRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml");
|
||||||
this.createRelationship(2, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", "numbering.xml");
|
this.createRelationship(2, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", "numbering.xml");
|
||||||
|
this.createRelationship(3, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", "header1.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
public addRelationship(relationship: Relationship): void {
|
public addRelationship(relationship: Relationship): void {
|
||||||
@ -25,4 +26,8 @@ export class Relationships extends XmlComponent {
|
|||||||
|
|
||||||
return relationship;
|
return relationship;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get RelationshipCount(): number {
|
||||||
|
return this.root.length - 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@ import { ParagraphPropertiesDefaults } from "./paragraph-properties";
|
|||||||
import { RunPropertiesDefaults } from "./run-properties";
|
import { RunPropertiesDefaults } from "./run-properties";
|
||||||
|
|
||||||
export class DocumentDefaults extends XmlComponent {
|
export class DocumentDefaults extends XmlComponent {
|
||||||
private runPropertiesDefaults: RunPropertiesDefaults;
|
private readonly runPropertiesDefaults: RunPropertiesDefaults;
|
||||||
private paragraphPropertiesDefaults: ParagraphPropertiesDefaults;
|
private readonly paragraphPropertiesDefaults: ParagraphPropertiesDefaults;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super("w:docDefaults");
|
super("w:docDefaults");
|
||||||
|
@ -4,7 +4,7 @@ import { RunProperties } from "../../paragraph/run/properties";
|
|||||||
import { RunFonts } from "../../paragraph/run/run-fonts";
|
import { RunFonts } from "../../paragraph/run/run-fonts";
|
||||||
|
|
||||||
export class RunPropertiesDefaults extends XmlComponent {
|
export class RunPropertiesDefaults extends XmlComponent {
|
||||||
private properties: RunProperties;
|
private readonly properties: RunProperties;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super("w:rPrDefault");
|
super("w:rPrDefault");
|
||||||
|
@ -36,8 +36,8 @@ export class Style extends XmlComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ParagraphStyle extends Style {
|
export class ParagraphStyle extends Style {
|
||||||
private paragraphProperties: paragraph.ParagraphProperties;
|
private readonly paragraphProperties: paragraph.ParagraphProperties;
|
||||||
private runProperties: RunProperties;
|
private readonly runProperties: RunProperties;
|
||||||
|
|
||||||
constructor(styleId: string, name?: string) {
|
constructor(styleId: string, name?: string) {
|
||||||
super({ type: "paragraph", styleId: styleId }, name);
|
super({ type: "paragraph", styleId: styleId }, name);
|
||||||
|
@ -5,9 +5,9 @@ import { TableGrid } from "./grid";
|
|||||||
import { TableProperties, WidthTypes } from "./properties";
|
import { TableProperties, WidthTypes } from "./properties";
|
||||||
|
|
||||||
export class Table extends XmlComponent {
|
export class Table extends XmlComponent {
|
||||||
private properties: TableProperties;
|
private readonly properties: TableProperties;
|
||||||
private rows: TableRow[];
|
private readonly rows: TableRow[];
|
||||||
private grid: TableGrid;
|
private readonly grid: TableGrid;
|
||||||
|
|
||||||
constructor(rows: number, cols: number) {
|
constructor(rows: number, cols: number) {
|
||||||
super("w:tbl");
|
super("w:tbl");
|
||||||
@ -63,14 +63,12 @@ export class Table extends XmlComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class TableRow extends XmlComponent {
|
export class TableRow extends XmlComponent {
|
||||||
private properties: TableRowProperties;
|
private readonly properties: TableRowProperties;
|
||||||
private cells: TableCell[];
|
|
||||||
|
|
||||||
constructor(cells: TableCell[]) {
|
constructor(private readonly cells: TableCell[]) {
|
||||||
super("w:tr");
|
super("w:tr");
|
||||||
this.properties = new TableRowProperties();
|
this.properties = new TableRowProperties();
|
||||||
this.root.push(this.properties);
|
this.root.push(this.properties);
|
||||||
this.cells = cells;
|
|
||||||
cells.forEach((c) => this.root.push(c));
|
cells.forEach((c) => this.root.push(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +84,7 @@ export class TableRowProperties extends XmlComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class TableCell extends XmlComponent {
|
export class TableCell extends XmlComponent {
|
||||||
private properties: TableCellProperties;
|
private readonly properties: TableCellProperties;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super("w:tc");
|
super("w:tc");
|
||||||
|
Reference in New Issue
Block a user