Make fields readonly

This commit is contained in:
Dolan
2018-01-29 01:55:25 +00:00
parent 3fe0c76d54
commit 079334f71b
11 changed files with 28 additions and 27 deletions

View File

@ -5,10 +5,9 @@ import { Compiler } from "./compiler";
import { IPacker } from "./packer";
export class ExpressPacker implements IPacker {
private res: express.Response;
private packer: Compiler;
private readonly packer: Compiler;
constructor(file: File, res: express.Response) {
constructor(file: File, private readonly res: express.Response) {
this.packer = new Compiler(file);
this.res = res;

View File

@ -9,8 +9,8 @@ import { PdfConvertWrapper } from "./pdf-convert-wrapper";
export class LocalPacker implements IPacker {
private stream: fs.WriteStream;
private pdfConverter: PdfConvertWrapper;
private packer: Compiler;
private readonly pdfConverter: PdfConvertWrapper;
private readonly packer: Compiler;
constructor(file: File) {
this.pdfConverter = new PdfConvertWrapper();

View File

@ -8,7 +8,7 @@ import { SectionPropertiesOptions } from "./body/section-properties/section-prop
import { DocumentAttributes } from "./document-attributes";
export class Document extends XmlComponent {
private body: Body;
private readonly body: Body;
constructor(sectionPropertiesOptions?: SectionPropertiesOptions) {
super("w:document");

View File

@ -2,10 +2,11 @@ import * as fs from "fs";
import * as sizeOf from "image-size";
import * as path from "path";
import { Relationships } from "file/relationships/relationships";
import { IMediaData } from "./data";
export class Media {
private map: Map<string, IMediaData>;
private readonly map: Map<string, IMediaData>;
constructor() {
this.map = new Map<string, IMediaData>();
@ -21,12 +22,12 @@ export class Media {
return data;
}
public addMedia(filePath: string): IMediaData {
public addMedia(filePath: string, relationshipsCount: number): IMediaData {
const key = path.basename(filePath);
const dimensions = sizeOf(filePath);
const imageData = {
referenceId: this.map.size + 3,
referenceId: this.map.size + relationshipsCount,
stream: fs.createReadStream(filePath),
path: filePath,
fileName: key,

View File

@ -61,8 +61,8 @@ class LevelJc extends XmlComponent {
}
export class LevelBase extends XmlComponent {
private paragraphProperties: ParagraphProperties;
private runProperties: RunProperties;
private readonly paragraphProperties: ParagraphProperties;
private readonly runProperties: RunProperties;
constructor(level: number, start?: number, numberFormat?: string, levelText?: string, lvlJc?: string) {
super("w:lvl");

View File

@ -46,16 +46,14 @@ class LevelOverrideAttributes extends XmlAttributeComponent<{ ilvl: number }> {
}
export class LevelOverride extends XmlComponent {
private levelNum: number;
private lvl?: LevelForOverride;
constructor(levelNum: number, start?: number) {
constructor(private readonly levelNum: number, start?: number) {
super("w:lvlOverride");
this.root.push(new LevelOverrideAttributes({ ilvl: levelNum }));
if (start !== undefined) {
this.root.push(new StartOverride(start));
}
this.levelNum = levelNum;
}
get level(): LevelForOverride {

View File

@ -13,6 +13,7 @@ export class Relationships extends XmlComponent {
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(3, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", "header1.xml");
}
public addRelationship(relationship: Relationship): void {
@ -25,4 +26,8 @@ export class Relationships extends XmlComponent {
return relationship;
}
public get RelationshipCount(): number {
return this.root.length - 1;
}
}

View File

@ -3,8 +3,8 @@ import { ParagraphPropertiesDefaults } from "./paragraph-properties";
import { RunPropertiesDefaults } from "./run-properties";
export class DocumentDefaults extends XmlComponent {
private runPropertiesDefaults: RunPropertiesDefaults;
private paragraphPropertiesDefaults: ParagraphPropertiesDefaults;
private readonly runPropertiesDefaults: RunPropertiesDefaults;
private readonly paragraphPropertiesDefaults: ParagraphPropertiesDefaults;
constructor() {
super("w:docDefaults");

View File

@ -4,7 +4,7 @@ import { RunProperties } from "../../paragraph/run/properties";
import { RunFonts } from "../../paragraph/run/run-fonts";
export class RunPropertiesDefaults extends XmlComponent {
private properties: RunProperties;
private readonly properties: RunProperties;
constructor() {
super("w:rPrDefault");

View File

@ -36,8 +36,8 @@ export class Style extends XmlComponent {
}
export class ParagraphStyle extends Style {
private paragraphProperties: paragraph.ParagraphProperties;
private runProperties: RunProperties;
private readonly paragraphProperties: paragraph.ParagraphProperties;
private readonly runProperties: RunProperties;
constructor(styleId: string, name?: string) {
super({ type: "paragraph", styleId: styleId }, name);

View File

@ -5,9 +5,9 @@ import { TableGrid } from "./grid";
import { TableProperties, WidthTypes } from "./properties";
export class Table extends XmlComponent {
private properties: TableProperties;
private rows: TableRow[];
private grid: TableGrid;
private readonly properties: TableProperties;
private readonly rows: TableRow[];
private readonly grid: TableGrid;
constructor(rows: number, cols: number) {
super("w:tbl");
@ -63,14 +63,12 @@ export class Table extends XmlComponent {
}
export class TableRow extends XmlComponent {
private properties: TableRowProperties;
private cells: TableCell[];
private readonly properties: TableRowProperties;
constructor(cells: TableCell[]) {
constructor(private readonly cells: TableCell[]) {
super("w:tr");
this.properties = new TableRowProperties();
this.root.push(this.properties);
this.cells = cells;
cells.forEach((c) => this.root.push(c));
}
@ -86,7 +84,7 @@ export class TableRowProperties extends XmlComponent {
}
export class TableCell extends XmlComponent {
private properties: TableCellProperties;
private readonly properties: TableCellProperties;
constructor() {
super("w:tc");