diff --git a/.nycrc b/.nycrc index 3212deb172..e02a0d16f8 100644 --- a/.nycrc +++ b/.nycrc @@ -1,9 +1,9 @@ { "check-coverage": true, - "lines": 87.39, - "functions": 83.54, - "branches": 71.95, - "statements": 87.17, + "lines": 87.54, + "functions": 83.61, + "branches": 72.57, + "statements": 87.32, "include": [ "src/**/*.ts" ], diff --git a/package.json b/package.json index c111fec200..a4071ce20d 100644 --- a/package.json +++ b/package.json @@ -81,6 +81,7 @@ "sinon": "^5.0.7", "ts-node": "^7.0.1", "tslint": "^5.11.0", + "tslint-immutable": "^4.9.0", "typedoc": "^0.11.1", "typescript": "2.9.2", "webpack": "^3.10.0" diff --git a/src/export/packer/next-compiler.ts b/src/export/packer/next-compiler.ts index f04869cd9e..d311cf310c 100644 --- a/src/export/packer/next-compiler.ts +++ b/src/export/packer/next-compiler.ts @@ -5,25 +5,25 @@ import { File } from "file"; import { Formatter } from "../formatter"; interface IXmlifyedFile { - data: string; - path: string; + readonly data: string; + readonly path: string; } interface IXmlifyedFileMapping { - Document: IXmlifyedFile; - Styles: IXmlifyedFile; - Properties: IXmlifyedFile; - Numbering: IXmlifyedFile; - Relationships: IXmlifyedFile; - FileRelationships: IXmlifyedFile; - Headers: IXmlifyedFile[]; - Footers: IXmlifyedFile[]; - HeaderRelationships: IXmlifyedFile[]; - FooterRelationships: IXmlifyedFile[]; - ContentTypes: IXmlifyedFile; - AppProperties: IXmlifyedFile; - FootNotes: IXmlifyedFile; - Settings: IXmlifyedFile; + readonly Document: IXmlifyedFile; + readonly Styles: IXmlifyedFile; + readonly Properties: IXmlifyedFile; + readonly Numbering: IXmlifyedFile; + readonly Relationships: IXmlifyedFile; + readonly FileRelationships: IXmlifyedFile; + readonly Headers: IXmlifyedFile[]; + readonly Footers: IXmlifyedFile[]; + readonly HeaderRelationships: IXmlifyedFile[]; + readonly FooterRelationships: IXmlifyedFile[]; + readonly ContentTypes: IXmlifyedFile; + readonly AppProperties: IXmlifyedFile; + readonly FootNotes: IXmlifyedFile; + readonly Settings: IXmlifyedFile; } export class Compiler { diff --git a/src/file/app-properties/app-properties-attributes.ts b/src/file/app-properties/app-properties-attributes.ts index 280f4d77b3..fa36937ebf 100644 --- a/src/file/app-properties/app-properties-attributes.ts +++ b/src/file/app-properties/app-properties-attributes.ts @@ -1,12 +1,12 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IAppPropertiesAttributes { - xmlns: string; - vt: string; + readonly xmlns: string; + readonly vt: string; } export class AppPropertiesAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { xmlns: "xmlns", vt: "xmlns:vt", }; diff --git a/src/file/content-types/content-types-attributes.ts b/src/file/content-types/content-types-attributes.ts index 932d00a67d..1d940bdda1 100644 --- a/src/file/content-types/content-types-attributes.ts +++ b/src/file/content-types/content-types-attributes.ts @@ -1,11 +1,11 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IContentTypeAttributes { - xmlns?: string; + readonly xmlns?: string; } export class ContentTypeAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { xmlns: "xmlns", }; } diff --git a/src/file/content-types/default/default-attributes.ts b/src/file/content-types/default/default-attributes.ts index bbc6438c05..727cb80c6f 100644 --- a/src/file/content-types/default/default-attributes.ts +++ b/src/file/content-types/default/default-attributes.ts @@ -1,12 +1,12 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IDefaultAttributes { - contentType: string; - extension?: string; + readonly contentType: string; + readonly extension?: string; } export class DefaultAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { contentType: "ContentType", extension: "Extension", }; diff --git a/src/file/content-types/override/override-attributes.ts b/src/file/content-types/override/override-attributes.ts index ba84190750..7370aabfd5 100644 --- a/src/file/content-types/override/override-attributes.ts +++ b/src/file/content-types/override/override-attributes.ts @@ -1,12 +1,12 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IOverrideAttributes { - contentType: string; - partName?: string; + readonly contentType: string; + readonly partName?: string; } export class OverrideAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { contentType: "ContentType", partName: "PartName", }; diff --git a/src/file/core-properties/properties.ts b/src/file/core-properties/properties.ts index aa9d3aec51..d271299d9c 100644 --- a/src/file/core-properties/properties.ts +++ b/src/file/core-properties/properties.ts @@ -3,14 +3,14 @@ import { DocumentAttributes } from "../document/document-attributes"; import { Created, Creator, Description, Keywords, LastModifiedBy, Modified, Revision, Subject, Title } from "./components"; export interface IPropertiesOptions { - title?: string; - subject?: string; - creator?: string; - keywords?: string; - description?: string; - lastModifiedBy?: string; - revision?: string; - externalStyles?: string; + readonly title?: string; + readonly subject?: string; + readonly creator?: string; + readonly keywords?: string; + readonly description?: string; + readonly lastModifiedBy?: string; + readonly revision?: string; + readonly externalStyles?: string; } export class CoreProperties extends XmlComponent { diff --git a/src/file/document/body/section-properties/columns/columns-attributes.ts b/src/file/document/body/section-properties/columns/columns-attributes.ts index 6a711abf93..b5cf098c5a 100644 --- a/src/file/document/body/section-properties/columns/columns-attributes.ts +++ b/src/file/document/body/section-properties/columns/columns-attributes.ts @@ -1,11 +1,11 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IColumnsAttributes { - space?: number; + readonly space?: number; } export class ColumnsAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { space: "w:space", }; } diff --git a/src/file/document/body/section-properties/doc-grid/doc-grid-attributes.ts b/src/file/document/body/section-properties/doc-grid/doc-grid-attributes.ts index 23f9c3efb4..3fb2a5030f 100644 --- a/src/file/document/body/section-properties/doc-grid/doc-grid-attributes.ts +++ b/src/file/document/body/section-properties/doc-grid/doc-grid-attributes.ts @@ -1,11 +1,11 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IDocGridAttributesProperties { - linePitch?: number; + readonly linePitch?: number; } export class DocGridAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { linePitch: "w:linePitch", }; } diff --git a/src/file/document/body/section-properties/footer-reference/footer-reference-attributes.ts b/src/file/document/body/section-properties/footer-reference/footer-reference-attributes.ts index 763053e36a..9f725e01e0 100644 --- a/src/file/document/body/section-properties/footer-reference/footer-reference-attributes.ts +++ b/src/file/document/body/section-properties/footer-reference/footer-reference-attributes.ts @@ -7,12 +7,12 @@ export enum FooterReferenceType { } export interface IFooterReferenceAttributes { - type: string; - id: string; + readonly type: string; + readonly id: string; } export class FooterReferenceAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { type: "w:type", id: "r:id", }; diff --git a/src/file/document/body/section-properties/footer-reference/footer-reference.ts b/src/file/document/body/section-properties/footer-reference/footer-reference.ts index 6c2786432d..d23e99aba1 100644 --- a/src/file/document/body/section-properties/footer-reference/footer-reference.ts +++ b/src/file/document/body/section-properties/footer-reference/footer-reference.ts @@ -2,8 +2,8 @@ import { XmlComponent } from "file/xml-components"; import { FooterReferenceAttributes, FooterReferenceType } from "./footer-reference-attributes"; export interface IFooterOptions { - footerType?: FooterReferenceType; - footerId?: number; + readonly footerType?: FooterReferenceType; + readonly footerId?: number; } export class FooterReference extends XmlComponent { diff --git a/src/file/document/body/section-properties/header-reference/header-reference-attributes.ts b/src/file/document/body/section-properties/header-reference/header-reference-attributes.ts index 5569fa76b9..3b0e0bff07 100644 --- a/src/file/document/body/section-properties/header-reference/header-reference-attributes.ts +++ b/src/file/document/body/section-properties/header-reference/header-reference-attributes.ts @@ -7,12 +7,12 @@ export enum HeaderReferenceType { } export interface IHeaderReferenceAttributes { - type: string; - id: string; + readonly type: string; + readonly id: string; } export class HeaderReferenceAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { type: "w:type", id: "r:id", }; diff --git a/src/file/document/body/section-properties/header-reference/header-reference.ts b/src/file/document/body/section-properties/header-reference/header-reference.ts index 8464a33a92..8f89ea09b3 100644 --- a/src/file/document/body/section-properties/header-reference/header-reference.ts +++ b/src/file/document/body/section-properties/header-reference/header-reference.ts @@ -2,8 +2,8 @@ import { XmlComponent } from "file/xml-components"; import { HeaderReferenceAttributes, HeaderReferenceType } from "./header-reference-attributes"; export interface IHeaderOptions { - headerType?: HeaderReferenceType; - headerId?: number; + readonly headerType?: HeaderReferenceType; + readonly headerId?: number; } export class HeaderReference extends XmlComponent { diff --git a/src/file/document/body/section-properties/page-border/page-borders.ts b/src/file/document/body/section-properties/page-border/page-borders.ts index 07aa4eabf1..6abfa6f68b 100644 --- a/src/file/document/body/section-properties/page-border/page-borders.ts +++ b/src/file/document/body/section-properties/page-border/page-borders.ts @@ -19,28 +19,28 @@ export enum PageBorderZOrder { } export interface IPageBorderAttributes { - display?: PageBorderDisplay; - offsetFrom?: PageBorderOffsetFrom; - zOrder?: PageBorderZOrder; + readonly display?: PageBorderDisplay; + readonly offsetFrom?: PageBorderOffsetFrom; + readonly zOrder?: PageBorderZOrder; } export interface IPageBorderConfiguration { - style?: BorderStyle; - size?: number; - color?: string; - space?: number; + readonly style?: BorderStyle; + readonly size?: number; + readonly color?: string; + readonly space?: number; } export interface IPageBordersOptions { - pageBorders?: IPageBorderAttributes; - pageBorderTop?: IPageBorderConfiguration; - pageBorderRight?: IPageBorderConfiguration; - pageBorderBottom?: IPageBorderConfiguration; - pageBorderLeft?: IPageBorderConfiguration; + readonly pageBorders?: IPageBorderAttributes; + readonly pageBorderTop?: IPageBorderConfiguration; + readonly pageBorderRight?: IPageBorderConfiguration; + readonly pageBorderBottom?: IPageBorderConfiguration; + readonly pageBorderLeft?: IPageBorderConfiguration; } class PageBordeAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { style: "w:val", size: "w:size", color: "w:color", @@ -57,7 +57,7 @@ class PageBorder extends XmlComponent { } class PageBordersAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { display: "w:display", offsetFrom: "w:offsetFrom", zOrder: "w:zOrder", diff --git a/src/file/document/body/section-properties/page-margin/page-margin-attributes.ts b/src/file/document/body/section-properties/page-margin/page-margin-attributes.ts index e486ae5c72..73677ab4aa 100644 --- a/src/file/document/body/section-properties/page-margin/page-margin-attributes.ts +++ b/src/file/document/body/section-properties/page-margin/page-margin-attributes.ts @@ -1,18 +1,18 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IPageMarginAttributes { - top?: number; - right?: number; - bottom?: number; - left?: number; - header?: number; - footer?: number; - gutter?: number; - mirror?: boolean; + readonly top?: number; + readonly right?: number; + readonly bottom?: number; + readonly left?: number; + readonly header?: number; + readonly footer?: number; + readonly gutter?: number; + readonly mirror?: boolean; } export class PageMarginAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { top: "w:top", right: "w:right", bottom: "w:bottom", diff --git a/src/file/document/body/section-properties/page-number/page-number.ts b/src/file/document/body/section-properties/page-number/page-number.ts index d6239d3be4..d876c265af 100644 --- a/src/file/document/body/section-properties/page-number/page-number.ts +++ b/src/file/document/body/section-properties/page-number/page-number.ts @@ -17,12 +17,12 @@ export enum PageNumberFormat { } export interface IPageNumberTypeAttributes { - pageNumberStart?: number; - pageNumberFormatType?: PageNumberFormat; + readonly pageNumberStart?: number; + readonly pageNumberFormatType?: PageNumberFormat; } export class PageNumberTypeAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { pageNumberStart: "w:start", pageNumberFormatType: "w:fmt", }; diff --git a/src/file/document/body/section-properties/page-size/page-size-attributes.ts b/src/file/document/body/section-properties/page-size/page-size-attributes.ts index 4af206ac2d..9406de635a 100644 --- a/src/file/document/body/section-properties/page-size/page-size-attributes.ts +++ b/src/file/document/body/section-properties/page-size/page-size-attributes.ts @@ -6,13 +6,13 @@ export enum PageOrientation { } export interface IPageSizeAttributes { - width?: number; - height?: number; - orientation?: PageOrientation; + readonly width?: number; + readonly height?: number; + readonly orientation?: PageOrientation; } export class PageSizeAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { width: "w:w", height: "w:h", orientation: "w:orient", diff --git a/src/file/document/body/section-properties/section-properties.ts b/src/file/document/body/section-properties/section-properties.ts index 4a5fed5231..4056570de2 100644 --- a/src/file/document/body/section-properties/section-properties.ts +++ b/src/file/document/body/section-properties/section-properties.ts @@ -20,21 +20,21 @@ import { IPageSizeAttributes, PageOrientation } from "./page-size/page-size-attr import { TitlePage } from "./title-page/title-page"; export interface IHeaderFooterGroup { - default?: T; - first?: T; - even?: T; + readonly default?: T; + readonly first?: T; + readonly even?: T; } interface IHeadersOptions { - headers?: IHeaderFooterGroup; + readonly headers?: IHeaderFooterGroup; } interface IFootersOptions { - footers?: IHeaderFooterGroup; + readonly footers?: IHeaderFooterGroup; } interface ITitlePageOptions { - titlePage?: boolean; + readonly titlePage?: boolean; } export type SectionPropertiesOptions = IPageSizeAttributes & diff --git a/src/file/document/body/section-properties/title-page/title-page-attributes.ts b/src/file/document/body/section-properties/title-page/title-page-attributes.ts index 9022cccf3d..00da3f7c58 100644 --- a/src/file/document/body/section-properties/title-page/title-page-attributes.ts +++ b/src/file/document/body/section-properties/title-page/title-page-attributes.ts @@ -1,11 +1,11 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IHeaderReferenceAttributes { - value: string; + readonly value: string; } export class TitlePageAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { value: "w:val", }; } diff --git a/src/file/document/document-attributes.ts b/src/file/document/document-attributes.ts index 68df58ca61..a61b37eba0 100644 --- a/src/file/document/document-attributes.ts +++ b/src/file/document/document-attributes.ts @@ -1,33 +1,33 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IDocumentAttributesProperties { - wpc?: string; - mc?: string; - o?: string; - r?: string; - m?: string; - v?: string; - wp14?: string; - wp?: string; - w10?: string; - w?: string; - w14?: string; - w15?: string; - wpg?: string; - wpi?: string; - wne?: string; - wps?: string; - Ignorable?: string; - cp?: string; - dc?: string; - dcterms?: string; - dcmitype?: string; - xsi?: string; - type?: string; + readonly wpc?: string; + readonly mc?: string; + readonly o?: string; + readonly r?: string; + readonly m?: string; + readonly v?: string; + readonly wp14?: string; + readonly wp?: string; + readonly w10?: string; + readonly w?: string; + readonly w14?: string; + readonly w15?: string; + readonly wpg?: string; + readonly wpi?: string; + readonly wne?: string; + readonly wps?: string; + readonly Ignorable?: string; + readonly cp?: string; + readonly dc?: string; + readonly dcterms?: string; + readonly dcmitype?: string; + readonly xsi?: string; + readonly type?: string; } export class DocumentAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { wpc: "xmlns:wpc", mc: "xmlns:mc", o: "xmlns:o", diff --git a/src/file/drawing/anchor/anchor-attributes.ts b/src/file/drawing/anchor/anchor-attributes.ts index cfd8ad3144..31d6574a8e 100644 --- a/src/file/drawing/anchor/anchor-attributes.ts +++ b/src/file/drawing/anchor/anchor-attributes.ts @@ -2,16 +2,16 @@ import { XmlAttributeComponent } from "file/xml-components"; import { IDistance } from "../drawing"; export interface IAnchorAttributes extends IDistance { - allowOverlap?: "0" | "1"; - behindDoc?: "0" | "1"; - layoutInCell?: "0" | "1"; - locked?: "0" | "1"; - relativeHeight?: number; - simplePos?: "0" | "1"; + readonly allowOverlap?: "0" | "1"; + readonly behindDoc?: "0" | "1"; + readonly layoutInCell?: "0" | "1"; + readonly locked?: "0" | "1"; + readonly relativeHeight?: number; + readonly simplePos?: "0" | "1"; } export class AnchorAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { distT: "distT", distB: "distB", distL: "distL", diff --git a/src/file/drawing/doc-properties/doc-properties-attributes.ts b/src/file/drawing/doc-properties/doc-properties-attributes.ts index ae75d35096..9e80e65935 100644 --- a/src/file/drawing/doc-properties/doc-properties-attributes.ts +++ b/src/file/drawing/doc-properties/doc-properties-attributes.ts @@ -1,13 +1,13 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IDocPropertiesAttributes { - id?: number; - name?: string; - descr?: string; + readonly id?: number; + readonly name?: string; + readonly descr?: string; } export class DocPropertiesAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { id: "id", name: "name", descr: "descr", diff --git a/src/file/drawing/drawing.ts b/src/file/drawing/drawing.ts index d45a6ad3bb..d1087462fb 100644 --- a/src/file/drawing/drawing.ts +++ b/src/file/drawing/drawing.ts @@ -11,16 +11,16 @@ export enum PlacementPosition { } export interface IDistance { - distT?: number; - distB?: number; - distL?: number; - distR?: number; + readonly distT?: number; + readonly distB?: number; + readonly distL?: number; + readonly distR?: number; } export interface IDrawingOptions { - position?: PlacementPosition; - textWrapping?: ITextWrapping; - floating?: IFloating; + readonly position?: PlacementPosition; + readonly textWrapping?: ITextWrapping; + readonly floating?: IFloating; } const defaultDrawingOptions: IDrawingOptions = { diff --git a/src/file/drawing/effect-extent/effect-extent-attributes.ts b/src/file/drawing/effect-extent/effect-extent-attributes.ts index c97f4b123d..eccd38daf3 100644 --- a/src/file/drawing/effect-extent/effect-extent-attributes.ts +++ b/src/file/drawing/effect-extent/effect-extent-attributes.ts @@ -1,14 +1,14 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IEffectExtentAttributes { - b?: number; - l?: number; - r?: number; - t?: number; + readonly b?: number; + readonly l?: number; + readonly r?: number; + readonly t?: number; } export class EffectExtentAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { b: "b", l: "l", r: "r", diff --git a/src/file/drawing/extent/extent-attributes.ts b/src/file/drawing/extent/extent-attributes.ts index 89a02167f6..cae1324285 100644 --- a/src/file/drawing/extent/extent-attributes.ts +++ b/src/file/drawing/extent/extent-attributes.ts @@ -1,12 +1,12 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IExtentAttributes { - cx?: number; - cy?: number; + readonly cx?: number; + readonly cy?: number; } export class ExtentAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { cx: "cx", cy: "cy", }; diff --git a/src/file/drawing/floating/floating-position.ts b/src/file/drawing/floating/floating-position.ts index 7039846bc7..041bb94828 100644 --- a/src/file/drawing/floating/floating-position.ts +++ b/src/file/drawing/floating/floating-position.ts @@ -39,22 +39,22 @@ export enum VerticalPositionAlign { } export interface IHorizontalPositionOptions { - relative: HorizontalPositionRelativeFrom; - align?: HorizontalPositionAlign; - offset?: number; + readonly relative: HorizontalPositionRelativeFrom; + readonly align?: HorizontalPositionAlign; + readonly offset?: number; } export interface IVerticalPositionOptions { - relative: VerticalPositionRelativeFrom; - align?: VerticalPositionAlign; - offset?: number; + readonly relative: VerticalPositionRelativeFrom; + readonly align?: VerticalPositionAlign; + readonly offset?: number; } export interface IFloating { - horizontalPosition: IHorizontalPositionOptions; - verticalPosition: IVerticalPositionOptions; - allowOverlap?: boolean; - lockAnchor?: boolean; - behindDocument?: boolean; - layoutInCell?: boolean; + readonly horizontalPosition: IHorizontalPositionOptions; + readonly verticalPosition: IVerticalPositionOptions; + readonly allowOverlap?: boolean; + readonly lockAnchor?: boolean; + readonly behindDocument?: boolean; + readonly layoutInCell?: boolean; } diff --git a/src/file/drawing/floating/horizontal-position.ts b/src/file/drawing/floating/horizontal-position.ts index f0725aa857..a2d9f865f7 100644 --- a/src/file/drawing/floating/horizontal-position.ts +++ b/src/file/drawing/floating/horizontal-position.ts @@ -5,11 +5,11 @@ import { HorizontalPositionRelativeFrom, IHorizontalPositionOptions } from "./fl import { PositionOffset } from "./position-offset"; interface IHorizontalPositionAttributes { - relativeFrom: HorizontalPositionRelativeFrom; + readonly relativeFrom: HorizontalPositionRelativeFrom; } class HorizontalPositionAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { relativeFrom: "relativeFrom", }; } diff --git a/src/file/drawing/floating/simple-pos.ts b/src/file/drawing/floating/simple-pos.ts index 6330f6660a..0e0fedcdc6 100644 --- a/src/file/drawing/floating/simple-pos.ts +++ b/src/file/drawing/floating/simple-pos.ts @@ -2,12 +2,12 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; interface ISimplePosAttributes { - x: number; - y: number; + readonly x: number; + readonly y: number; } class SimplePosAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { x: "x", y: "y", }; diff --git a/src/file/drawing/floating/vertical-position.ts b/src/file/drawing/floating/vertical-position.ts index 10b6d6028f..a030234109 100644 --- a/src/file/drawing/floating/vertical-position.ts +++ b/src/file/drawing/floating/vertical-position.ts @@ -5,11 +5,11 @@ import { IVerticalPositionOptions, VerticalPositionRelativeFrom } from "./floati import { PositionOffset } from "./position-offset"; interface IVerticalPositionAttributes { - relativeFrom: VerticalPositionRelativeFrom; + readonly relativeFrom: VerticalPositionRelativeFrom; } class VerticalPositionAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { relativeFrom: "relativeFrom", }; } diff --git a/src/file/drawing/graphic-frame/graphic-frame-locks/graphic-frame-lock-attributes.ts b/src/file/drawing/graphic-frame/graphic-frame-locks/graphic-frame-lock-attributes.ts index dad7841ed1..5ba96eabec 100644 --- a/src/file/drawing/graphic-frame/graphic-frame-locks/graphic-frame-lock-attributes.ts +++ b/src/file/drawing/graphic-frame/graphic-frame-locks/graphic-frame-lock-attributes.ts @@ -1,12 +1,12 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IGraphicFrameLockAttributes { - xmlns?: string; - noChangeAspect?: number; + readonly xmlns?: string; + readonly noChangeAspect?: number; } export class GraphicFrameLockAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { xmlns: "xmlns:a", noChangeAspect: "noChangeAspect", }; diff --git a/src/file/drawing/inline/graphic/graphic-data/graphic-data-attribute.ts b/src/file/drawing/inline/graphic/graphic-data/graphic-data-attribute.ts index a248ecabf0..9293950537 100644 --- a/src/file/drawing/inline/graphic/graphic-data/graphic-data-attribute.ts +++ b/src/file/drawing/inline/graphic/graphic-data/graphic-data-attribute.ts @@ -1,11 +1,11 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IGraphicDataAttributes { - uri?: string; + readonly uri?: string; } export class GraphicDataAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { uri: "uri", }; } diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/blip/blip.ts b/src/file/drawing/inline/graphic/graphic-data/pic/blip/blip.ts index 3f8c737bec..bd279b2fae 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/blip/blip.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/blip/blip.ts @@ -1,12 +1,12 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; interface IBlipProperties { - embed: string; - cstate: string; + readonly embed: string; + readonly cstate: string; } class BlipAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { embed: "r:embed", cstate: "cstate", }; diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/child-non-visual-pic-properties/pic-locks/pic-locks-attributes.ts b/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/child-non-visual-pic-properties/pic-locks/pic-locks-attributes.ts index b5fe12fc48..e8902814af 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/child-non-visual-pic-properties/pic-locks/pic-locks-attributes.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/child-non-visual-pic-properties/pic-locks/pic-locks-attributes.ts @@ -1,12 +1,12 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IPicLocksAttributes { - noChangeAspect?: number; - noChangeArrowheads?: number; + readonly noChangeAspect?: number; + readonly noChangeArrowheads?: number; } export class PicLocksAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { noChangeAspect: "noChangeAspect", noChangeArrowheads: "noChangeArrowheads", }; diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-properties/non-visual-properties-attributes.ts b/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-properties/non-visual-properties-attributes.ts index 1f4abe7204..86845c5825 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-properties/non-visual-properties-attributes.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/non-visual-pic-properties/non-visual-properties/non-visual-properties-attributes.ts @@ -1,13 +1,13 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface INonVisualPropertiesAttributes { - id?: number; - name?: string; - descr?: string; + readonly id?: number; + readonly name?: string; + readonly descr?: string; } export class NonVisualPropertiesAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { id: "id", name: "name", descr: "desc", diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/pic-attributes.ts b/src/file/drawing/inline/graphic/graphic-data/pic/pic-attributes.ts index b73c6c8cd0..9aec0c1d57 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/pic-attributes.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/pic-attributes.ts @@ -1,11 +1,11 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IPicAttributes { - xmlns?: string; + readonly xmlns?: string; } export class PicAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { xmlns: "xmlns:pic", }; } diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/extents/extents-attributes.ts b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/extents/extents-attributes.ts index c502231dc7..6f3eecfde3 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/extents/extents-attributes.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/extents/extents-attributes.ts @@ -1,12 +1,12 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IExtentsAttributes { - cx?: number; - cy?: number; + readonly cx?: number; + readonly cy?: number; } export class ExtentsAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { cx: "cx", cy: "cy", }; diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/offset/off-attributes.ts b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/offset/off-attributes.ts index 9f72211ff9..03123b86c1 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/offset/off-attributes.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/form/offset/off-attributes.ts @@ -1,12 +1,12 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IOffsetAttributes { - x?: number; - y?: number; + readonly x?: number; + readonly y?: number; } export class OffsetAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { x: "x", y: "y", }; diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/preset-geometry/preset-geometry-attributes.ts b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/preset-geometry/preset-geometry-attributes.ts index bd1c70feaa..912619e569 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/preset-geometry/preset-geometry-attributes.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/preset-geometry/preset-geometry-attributes.ts @@ -1,11 +1,11 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IPresetGeometryAttributes { - prst?: string; + readonly prst?: string; } export class PresetGeometryAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { prst: "prst", }; } diff --git a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/shape-properties-attributes.ts b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/shape-properties-attributes.ts index 4e4761bcde..c063881f1d 100644 --- a/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/shape-properties-attributes.ts +++ b/src/file/drawing/inline/graphic/graphic-data/pic/shape-properties/shape-properties-attributes.ts @@ -1,11 +1,11 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IShapePropertiesAttributes { - bwMode?: string; + readonly bwMode?: string; } export class ShapePropertiesAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { bwMode: "bwMode", }; } diff --git a/src/file/drawing/inline/graphic/graphic.ts b/src/file/drawing/inline/graphic/graphic.ts index dba653d2ca..0228b78dfb 100644 --- a/src/file/drawing/inline/graphic/graphic.ts +++ b/src/file/drawing/inline/graphic/graphic.ts @@ -2,11 +2,11 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { GraphicData } from "./graphic-data"; interface IGraphicProperties { - a: string; + readonly a: string; } class GraphicAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { a: "xmlns:a", }; } diff --git a/src/file/drawing/inline/inline-attributes.ts b/src/file/drawing/inline/inline-attributes.ts index 5f7489188c..b39f9444d3 100644 --- a/src/file/drawing/inline/inline-attributes.ts +++ b/src/file/drawing/inline/inline-attributes.ts @@ -5,7 +5,7 @@ import { IDistance } from "../drawing"; export interface IInlineAttributes extends IDistance {} export class InlineAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { distT: "distT", distB: "distB", distL: "distL", diff --git a/src/file/drawing/text-wrap/text-wrapping.ts b/src/file/drawing/text-wrap/text-wrapping.ts index 7fc14a52fd..2441004a25 100644 --- a/src/file/drawing/text-wrap/text-wrapping.ts +++ b/src/file/drawing/text-wrap/text-wrapping.ts @@ -16,7 +16,7 @@ export enum WrapTextOption { } export interface ITextWrapping { - textWrapStyle: TextWrapStyle; - wrapTextOption?: WrapTextOption; - distanceFromText?: IDistance; + readonly textWrapStyle: TextWrapStyle; + readonly wrapTextOption?: WrapTextOption; + readonly distanceFromText?: IDistance; } diff --git a/src/file/drawing/text-wrap/wrap-square.ts b/src/file/drawing/text-wrap/wrap-square.ts index 08ed108209..5baab40b6c 100644 --- a/src/file/drawing/text-wrap/wrap-square.ts +++ b/src/file/drawing/text-wrap/wrap-square.ts @@ -4,11 +4,11 @@ import { ITextWrapping, WrapTextOption } from "."; import { IDistance } from "../drawing"; interface IWrapSquareAttributes extends IDistance { - wrapText?: WrapTextOption; + readonly wrapText?: WrapTextOption; } class WrapSquareAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { distT: "distT", distB: "distB", distL: "distL", diff --git a/src/file/drawing/text-wrap/wrap-tight.ts b/src/file/drawing/text-wrap/wrap-tight.ts index cda9a20194..c612d86667 100644 --- a/src/file/drawing/text-wrap/wrap-tight.ts +++ b/src/file/drawing/text-wrap/wrap-tight.ts @@ -3,25 +3,25 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { IDistance } from "../drawing"; interface IWrapTightAttributes { - distT?: number; - distB?: number; + readonly distT?: number; + readonly distB?: number; } class WrapTightAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { distT: "distT", distB: "distB", }; } export class WrapTight extends XmlComponent { - constructor(distanceFromText?: IDistance) { - super("wp:wrapTight"); - - distanceFromText = distanceFromText || { + constructor( + distanceFromText: IDistance = { distT: 0, distB: 0, - }; + }, + ) { + super("wp:wrapTight"); this.root.push( new WrapTightAttributes({ diff --git a/src/file/drawing/text-wrap/wrap-top-and-bottom.ts b/src/file/drawing/text-wrap/wrap-top-and-bottom.ts index bf6a5c3cae..54ae7fcdd3 100644 --- a/src/file/drawing/text-wrap/wrap-top-and-bottom.ts +++ b/src/file/drawing/text-wrap/wrap-top-and-bottom.ts @@ -3,25 +3,25 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { IDistance } from "../drawing"; interface IWrapTopAndBottomAttributes { - distT?: number; - distB?: number; + readonly distT?: number; + readonly distB?: number; } class WrapTopAndBottomAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { distT: "distT", distB: "distB", }; } export class WrapTopAndBottom extends XmlComponent { - constructor(distanceFromText?: IDistance) { - super("wp:wrapTopAndBottom"); - - distanceFromText = distanceFromText || { + constructor( + distanceFromText: IDistance = { distT: 0, distB: 0, - }; + }, + ) { + super("wp:wrapTopAndBottom"); this.root.push( new WrapTopAndBottomAttributes({ diff --git a/src/file/file-properties.ts b/src/file/file-properties.ts index 3ccf8a5176..4273be8798 100644 --- a/src/file/file-properties.ts +++ b/src/file/file-properties.ts @@ -1,7 +1,7 @@ import { IDocumentTemplate } from "../import-dotx"; export interface IFileProperties { - template?: IDocumentTemplate; + readonly template?: IDocumentTemplate; } // Needed because of: https://github.com/s-panferov/awesome-typescript-loader/issues/432 diff --git a/src/file/file.ts b/src/file/file.ts index e18b536490..8958c4ccd3 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -25,6 +25,7 @@ import { Table } from "./table"; import { TableOfContents } from "./table-of-contents"; export class File { + // tslint:disable-next-line:readonly-keyword private currentRelationshipId: number = 1; private readonly document: Document; @@ -39,6 +40,7 @@ export class File { private readonly settings: Settings; private readonly contentTypes: ContentTypes; private readonly appProperties: AppProperties; + // tslint:disable-next-line:readonly-keyword private styles: Styles; constructor( @@ -95,13 +97,13 @@ export class File { this.createFooter(); } - sectionPropertiesOptions = { + const newSectionPropertiesOptions = { ...sectionPropertiesOptions, headers: this.groupHeaders(this.headers, sectionPropertiesOptions.headers), footers: this.groupFooters(this.footers, sectionPropertiesOptions.footers), }; - this.document = new Document(sectionPropertiesOptions); + this.document = new Document(newSectionPropertiesOptions); this.settings = new Settings(); } @@ -139,8 +141,8 @@ export class File { } public createHyperlink(link: string, text?: string): Hyperlink { - text = text === undefined ? link : text; - const hyperlink = new Hyperlink(text, this.docRelationships.RelationshipCount); + const newText = text === undefined ? link : text; + const hyperlink = new Hyperlink(newText, this.docRelationships.RelationshipCount); this.docRelationships.createRelationship( hyperlink.linkId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", @@ -151,16 +153,16 @@ export class File { } public createInternalHyperLink(anchor: string, text?: string): Hyperlink { - text = text === undefined ? anchor : text; - const hyperlink = new Hyperlink(text, this.docRelationships.RelationshipCount, anchor); + const newText = text === undefined ? anchor : text; + const hyperlink = new Hyperlink(newText, this.docRelationships.RelationshipCount, anchor); // NOTE: unlike File#createHyperlink(), since the link is to an internal bookmark // we don't need to create a new relationship. return hyperlink; } public createBookmark(name: string, text?: string): Bookmark { - text = text === undefined ? name : text; - const bookmark = new Bookmark(name, text, this.docRelationships.RelationshipCount); + const newText = text === undefined ? name : text; + const bookmark = new Bookmark(name, newText, this.docRelationships.RelationshipCount); return bookmark; } diff --git a/src/file/footer-wrapper.ts b/src/file/footer-wrapper.ts index 2c51cf5072..f9fecf6a50 100644 --- a/src/file/footer-wrapper.ts +++ b/src/file/footer-wrapper.ts @@ -8,8 +8,8 @@ import { Relationships } from "./relationships"; import { Table } from "./table"; export interface IDocumentFooter { - footer: FooterWrapper; - type: FooterReferenceType; + readonly footer: FooterWrapper; + readonly type: FooterReferenceType; } export class FooterWrapper { diff --git a/src/file/footer/footer-attributes.ts b/src/file/footer/footer-attributes.ts index 86f821f5f4..68df02b4eb 100644 --- a/src/file/footer/footer-attributes.ts +++ b/src/file/footer/footer-attributes.ts @@ -1,32 +1,32 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IFooterAttributesProperties { - wpc?: string; - mc?: string; - o?: string; - r?: string; - m?: string; - v?: string; - wp14?: string; - wp?: string; - w10?: string; - w?: string; - w14?: string; - w15?: string; - wpg?: string; - wpi?: string; - wne?: string; - wps?: string; - cp?: string; - dc?: string; - dcterms?: string; - dcmitype?: string; - xsi?: string; - type?: string; + readonly wpc?: string; + readonly mc?: string; + readonly o?: string; + readonly r?: string; + readonly m?: string; + readonly v?: string; + readonly wp14?: string; + readonly wp?: string; + readonly w10?: string; + readonly w?: string; + readonly w14?: string; + readonly w15?: string; + readonly wpg?: string; + readonly wpi?: string; + readonly wne?: string; + readonly wps?: string; + readonly cp?: string; + readonly dc?: string; + readonly dcterms?: string; + readonly dcmitype?: string; + readonly xsi?: string; + readonly type?: string; } export class FooterAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { wpc: "xmlns:wpc", mc: "xmlns:mc", o: "xmlns:o", diff --git a/src/file/footnotes/footnote/footnote-attributes.ts b/src/file/footnotes/footnote/footnote-attributes.ts index b6d96f89d8..ee978d0ef2 100644 --- a/src/file/footnotes/footnote/footnote-attributes.ts +++ b/src/file/footnotes/footnote/footnote-attributes.ts @@ -1,12 +1,12 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IFootnoteAttributesProperties { - type?: string; - id: number; + readonly type?: string; + readonly id: number; } export class FootnoteAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { type: "w:type", id: "w:id", }; diff --git a/src/file/footnotes/footnote/run/reference-run.ts b/src/file/footnotes/footnote/run/reference-run.ts index ef40d37608..278120ed70 100644 --- a/src/file/footnotes/footnote/run/reference-run.ts +++ b/src/file/footnotes/footnote/run/reference-run.ts @@ -3,11 +3,11 @@ import { Style } from "file/paragraph/run/style"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; export interface IFootNoteReferenceRunAttributesProperties { - id: number; + readonly id: number; } export class FootNoteReferenceRunAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { id: "w:id", }; } diff --git a/src/file/footnotes/footnotes-attributes.ts b/src/file/footnotes/footnotes-attributes.ts index f09216c9ac..fbd946afc2 100644 --- a/src/file/footnotes/footnotes-attributes.ts +++ b/src/file/footnotes/footnotes-attributes.ts @@ -1,27 +1,27 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IFootnotesAttributesProperties { - wpc?: string; - mc?: string; - o?: string; - r?: string; - m?: string; - v?: string; - wp14?: string; - wp?: string; - w10?: string; - w?: string; - w14?: string; - w15?: string; - wpg?: string; - wpi?: string; - wne?: string; - wps?: string; - Ignorable?: string; + readonly wpc?: string; + readonly mc?: string; + readonly o?: string; + readonly r?: string; + readonly m?: string; + readonly v?: string; + readonly wp14?: string; + readonly wp?: string; + readonly w10?: string; + readonly w?: string; + readonly w14?: string; + readonly w15?: string; + readonly wpg?: string; + readonly wpi?: string; + readonly wne?: string; + readonly wps?: string; + readonly Ignorable?: string; } export class FootnotesAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { wpc: "xmlns:wpc", mc: "xmlns:mc", o: "xmlns:o", diff --git a/src/file/footnotes/footnotes.ts b/src/file/footnotes/footnotes.ts index bb6ac388c5..7877eea9a0 100644 --- a/src/file/footnotes/footnotes.ts +++ b/src/file/footnotes/footnotes.ts @@ -6,12 +6,13 @@ import { SeperatorRun } from "./footnote/run/seperator-run"; import { FootnotesAttributes } from "./footnotes-attributes"; export class FootNotes extends XmlComponent { - private counter: number; + // tslint:disable-next-line:readonly-keyword + private currentId: number; constructor() { super("w:footnotes"); - this.counter = 1; + this.currentId = 1; this.root.push( new FootnotesAttributes({ @@ -61,10 +62,10 @@ export class FootNotes extends XmlComponent { } public createFootNote(paragraph: Paragraph): void { - const footnote = new Footnote(this.counter); + const footnote = new Footnote(this.currentId); footnote.addParagraph(paragraph); this.root.push(footnote); - this.counter++; + this.currentId++; } } diff --git a/src/file/header-wrapper.ts b/src/file/header-wrapper.ts index f4a403ce27..5730b5eaa6 100644 --- a/src/file/header-wrapper.ts +++ b/src/file/header-wrapper.ts @@ -8,8 +8,8 @@ import { Relationships } from "./relationships"; import { Table } from "./table"; export interface IDocumentHeader { - header: HeaderWrapper; - type: HeaderReferenceType; + readonly header: HeaderWrapper; + readonly type: HeaderReferenceType; } export class HeaderWrapper { diff --git a/src/file/header/header-attributes.ts b/src/file/header/header-attributes.ts index 3e46b4ca94..a34e9c8a0a 100644 --- a/src/file/header/header-attributes.ts +++ b/src/file/header/header-attributes.ts @@ -1,43 +1,43 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IHeaderAttributesProperties { - wpc?: string; - mc?: string; - o?: string; - r?: string; - m?: string; - v?: string; - wp14?: string; - wp?: string; - w10?: string; - w?: string; - w14?: string; - w15?: string; - wpg?: string; - wpi?: string; - wne?: string; - wps?: string; - cp?: string; - dc?: string; - dcterms?: string; - dcmitype?: string; - xsi?: string; - type?: string; - cx?: string; - cx1?: string; - cx2?: string; - cx3?: string; - cx4?: string; - cx5?: string; - cx6?: string; - cx7?: string; - cx8?: string; - w16cid: string; - w16se: string; + readonly wpc?: string; + readonly mc?: string; + readonly o?: string; + readonly r?: string; + readonly m?: string; + readonly v?: string; + readonly wp14?: string; + readonly wp?: string; + readonly w10?: string; + readonly w?: string; + readonly w14?: string; + readonly w15?: string; + readonly wpg?: string; + readonly wpi?: string; + readonly wne?: string; + readonly wps?: string; + readonly cp?: string; + readonly dc?: string; + readonly dcterms?: string; + readonly dcmitype?: string; + readonly xsi?: string; + readonly type?: string; + readonly cx?: string; + readonly cx1?: string; + readonly cx2?: string; + readonly cx3?: string; + readonly cx4?: string; + readonly cx5?: string; + readonly cx6?: string; + readonly cx7?: string; + readonly cx8?: string; + readonly w16cid: string; + readonly w16se: string; } export class HeaderAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { wpc: "xmlns:wpc", mc: "xmlns:mc", o: "xmlns:o", diff --git a/src/file/media/data.ts b/src/file/media/data.ts index 42e5874f99..ce8af83919 100644 --- a/src/file/media/data.ts +++ b/src/file/media/data.ts @@ -1,20 +1,20 @@ export interface IMediaDataDimensions { - pixels: { - x: number; - y: number; + readonly pixels: { + readonly x: number; + readonly y: number; }; - emus: { - x: number; - y: number; + readonly emus: { + readonly x: number; + readonly y: number; }; } export interface IMediaData { - referenceId: number; - stream: Buffer | Uint8Array | ArrayBuffer; - path?: string; - fileName: string; - dimensions: IMediaDataDimensions; + readonly referenceId: number; + readonly stream: Buffer | Uint8Array | ArrayBuffer; + readonly path?: string; + readonly fileName: string; + readonly dimensions: IMediaDataDimensions; } // Needed because of: https://github.com/s-panferov/awesome-typescript-loader/issues/432 diff --git a/src/file/media/media.ts b/src/file/media/media.ts index fdeb21b931..c1f67b3023 100644 --- a/src/file/media/media.ts +++ b/src/file/media/media.ts @@ -5,6 +5,7 @@ import { IMediaData } from "./data"; import { Image } from "./image"; interface IHackedFile { + // tslint:disable-next-line:readonly-keyword currentRelationshipId: number; } @@ -78,17 +79,15 @@ export class Media { private createMedia( key: string, relationshipsCount: number, - dimensions: { width: number; height: number }, + dimensions: { readonly width: number; readonly height: number }, data: Buffer | string | Uint8Array | ArrayBuffer, filePath?: string, ): IMediaData { - if (typeof data === "string") { - data = this.convertDataURIToBinary(data); - } + const newData = typeof data === "string" ? this.convertDataURIToBinary(data) : data; - const imageData = { + const imageData: IMediaData = { referenceId: relationshipsCount, - stream: data, + stream: newData, path: filePath, fileName: key, dimensions: { diff --git a/src/file/numbering/abstract-numbering.ts b/src/file/numbering/abstract-numbering.ts index 39239c548a..e42e2e4fc8 100644 --- a/src/file/numbering/abstract-numbering.ts +++ b/src/file/numbering/abstract-numbering.ts @@ -3,19 +3,19 @@ import { Level } from "./level"; import { MultiLevelType } from "./multi-level-type"; interface IAbstractNumberingAttributesProperties { - abstractNumId?: number; - restartNumberingAfterBreak?: number; + readonly abstractNumId?: number; + readonly restartNumberingAfterBreak?: number; } class AbstractNumberingAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { abstractNumId: "w:abstractNumId", restartNumberingAfterBreak: "w15:restartNumberingAfterBreak", }; } export class AbstractNumbering extends XmlComponent { - public id: number; + public readonly id: number; constructor(id: number) { super("w:abstractNum"); diff --git a/src/file/numbering/level.ts b/src/file/numbering/level.ts index 8bdc7ff8d7..716f313104 100644 --- a/src/file/numbering/level.ts +++ b/src/file/numbering/level.ts @@ -1,16 +1,27 @@ import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-components"; -import * as paragraph from "../paragraph/formatting"; +import { + Alignment, + AlignmentOptions, + Indent, + ISpacingProperties, + KeepLines, + KeepNext, + LeftTabStop, + MaxRightTabStop, + Spacing, + ThematicBreak, +} from "../paragraph/formatting"; import { ParagraphProperties } from "../paragraph/properties"; import * as formatting from "../paragraph/run/formatting"; import { RunProperties } from "../paragraph/run/properties"; interface ILevelAttributesProperties { - ilvl?: number; - tentative?: number; + readonly ilvl?: number; + readonly tentative?: number; } class LevelAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { ilvl: "w:ilvl", tentative: "w15:tentative", }; @@ -190,57 +201,57 @@ export class LevelBase extends XmlComponent { // --------------------- Paragraph formatting ------------------------ // public center(): Level { - this.addParagraphProperty(new paragraph.Alignment("center")); + this.addParagraphProperty(new Alignment(AlignmentOptions.CENTER)); return this; } public left(): Level { - this.addParagraphProperty(new paragraph.Alignment("left")); + this.addParagraphProperty(new Alignment(AlignmentOptions.LEFT)); return this; } public right(): Level { - this.addParagraphProperty(new paragraph.Alignment("right")); + this.addParagraphProperty(new Alignment(AlignmentOptions.RIGHT)); return this; } public justified(): Level { - this.addParagraphProperty(new paragraph.Alignment("both")); + this.addParagraphProperty(new Alignment(AlignmentOptions.BOTH)); return this; } public thematicBreak(): Level { - this.addParagraphProperty(new paragraph.ThematicBreak()); + this.addParagraphProperty(new ThematicBreak()); return this; } public maxRightTabStop(): Level { - this.addParagraphProperty(new paragraph.MaxRightTabStop()); + this.addParagraphProperty(new MaxRightTabStop()); return this; } public leftTabStop(position: number): Level { - this.addParagraphProperty(new paragraph.LeftTabStop(position)); + this.addParagraphProperty(new LeftTabStop(position)); return this; } public indent(attrs: object): Level { - this.addParagraphProperty(new paragraph.Indent(attrs)); + this.addParagraphProperty(new Indent(attrs)); return this; } - public spacing(params: paragraph.ISpacingProperties): Level { - this.addParagraphProperty(new paragraph.Spacing(params)); + public spacing(params: ISpacingProperties): Level { + this.addParagraphProperty(new Spacing(params)); return this; } public keepNext(): Level { - this.addParagraphProperty(new paragraph.KeepNext()); + this.addParagraphProperty(new KeepNext()); return this; } public keepLines(): Level { - this.addParagraphProperty(new paragraph.KeepLines()); + this.addParagraphProperty(new KeepLines()); return this; } } diff --git a/src/file/numbering/num.ts b/src/file/numbering/num.ts index e4600339cf..bf552593aa 100644 --- a/src/file/numbering/num.ts +++ b/src/file/numbering/num.ts @@ -13,15 +13,15 @@ class AbstractNumId extends XmlComponent { } interface INumAttributesProperties { - numId: number; + readonly numId: number; } class NumAttributes extends XmlAttributeComponent { - protected xmlKeys = { numId: "w:numId" }; + protected readonly xmlKeys = { numId: "w:numId" }; } export class Num extends XmlComponent { - public id: number; + public readonly id: number; constructor(numId: number, abstractNumId: number) { super("w:num"); @@ -41,12 +41,12 @@ export class Num extends XmlComponent { } } -class LevelOverrideAttributes extends XmlAttributeComponent<{ ilvl: number }> { - protected xmlKeys = { ilvl: "w:ilvl" }; +class LevelOverrideAttributes extends XmlAttributeComponent<{ readonly ilvl: number }> { + protected readonly xmlKeys = { ilvl: "w:ilvl" }; } export class LevelOverride extends XmlComponent { - private lvl?: LevelForOverride; + private readonly lvl: LevelForOverride; constructor(private readonly levelNum: number, start?: number) { super("w:lvlOverride"); @@ -54,23 +54,18 @@ export class LevelOverride extends XmlComponent { if (start !== undefined) { this.root.push(new StartOverride(start)); } + + this.lvl = new LevelForOverride(this.levelNum); + this.root.push(this.lvl); } public get Level(): LevelForOverride { - let lvl: LevelForOverride; - if (!this.lvl) { - lvl = new LevelForOverride(this.levelNum); - this.root.push(lvl); - this.lvl = lvl; - } else { - lvl = this.lvl; - } - return lvl; + return this.lvl; } } -class StartOverrideAttributes extends XmlAttributeComponent<{ val: number }> { - protected xmlKeys = { val: "w:val" }; +class StartOverrideAttributes extends XmlAttributeComponent<{ readonly val: number }> { + protected readonly xmlKeys = { val: "w:val" }; } class StartOverride extends XmlComponent { diff --git a/src/file/numbering/numbering.spec.ts b/src/file/numbering/numbering.spec.ts index d27665a96e..50643b1e07 100644 --- a/src/file/numbering/numbering.spec.ts +++ b/src/file/numbering/numbering.spec.ts @@ -378,14 +378,69 @@ describe("concrete numbering", () => { it("sets a new override level for the given level number", () => { concreteNumbering.overrideLevel(3); const tree = new Formatter().format(concreteNumbering); - expect(tree["w:num"]).to.include({ "w:lvlOverride": [{ _attr: { "w:ilvl": 3 } }] }); + expect(tree["w:num"]).to.include({ + "w:lvlOverride": [ + { + _attr: { + "w:ilvl": 3, + }, + }, + { + "w:lvl": [ + { + _attr: { + "w:ilvl": 3, + "w15:tentative": 1, + }, + }, + { + "w:pPr": [], + }, + { + "w:rPr": [], + }, + ], + }, + ], + }); }); it("sets the startOverride element if start is given", () => { concreteNumbering.overrideLevel(1, 9); const tree = new Formatter().format(concreteNumbering); expect(tree["w:num"]).to.include({ - "w:lvlOverride": [{ _attr: { "w:ilvl": 1 } }, { "w:startOverride": [{ _attr: { "w:val": 9 } }] }], + "w:lvlOverride": [ + { + _attr: { + "w:ilvl": 1, + }, + }, + { + "w:startOverride": [ + { + _attr: { + "w:val": 9, + }, + }, + ], + }, + { + "w:lvl": [ + { + _attr: { + "w:ilvl": 1, + "w15:tentative": 1, + }, + }, + { + "w:pPr": [], + }, + { + "w:rPr": [], + }, + ], + }, + ], }); }); diff --git a/src/file/numbering/numbering.ts b/src/file/numbering/numbering.ts index a925f4afec..0080b6b349 100644 --- a/src/file/numbering/numbering.ts +++ b/src/file/numbering/numbering.ts @@ -5,6 +5,7 @@ import { AbstractNumbering } from "./abstract-numbering"; import { Num } from "./num"; export class Numbering extends XmlComponent { + // tslint:disable-next-line:readonly-keyword private nextId: number; private readonly abstractNumbering: XmlComponent[] = []; diff --git a/src/file/paragraph/formatting/alignment.ts b/src/file/paragraph/formatting/alignment.ts index b1fa0ca2af..838c1dc700 100644 --- a/src/file/paragraph/formatting/alignment.ts +++ b/src/file/paragraph/formatting/alignment.ts @@ -1,10 +1,18 @@ // http://officeopenxml.com/WPalignment.php import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; -export type AlignmentOptions = "start" | "end" | "center" | "both" | "distribute" | "left" | "right"; +export enum AlignmentOptions { + START = "start", + END = "end", + CENTER = "center", + BOTH = "both", + DISTRIBUTE = "distribute", + LEFT = "left", + RIGHT = "right", +} -export class AlignmentAttributes extends XmlAttributeComponent<{ val: AlignmentOptions }> { - protected xmlKeys = { val: "w:val" }; +export class AlignmentAttributes extends XmlAttributeComponent<{ readonly val: AlignmentOptions }> { + protected readonly xmlKeys = { val: "w:val" }; } export class Alignment extends XmlComponent { diff --git a/src/file/paragraph/formatting/indent.ts b/src/file/paragraph/formatting/indent.ts index cd7528d2b8..035571b690 100644 --- a/src/file/paragraph/formatting/indent.ts +++ b/src/file/paragraph/formatting/indent.ts @@ -2,15 +2,15 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; export interface IIndentAttributesProperties { - left?: number; - hanging?: number; - firstLine?: number; - start?: number; - end?: number; + readonly left?: number; + readonly hanging?: number; + readonly firstLine?: number; + readonly start?: number; + readonly end?: number; } class IndentAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { left: "w:left", hanging: "w:hanging", firstLine: "w:firstLine", diff --git a/src/file/paragraph/formatting/spacing.ts b/src/file/paragraph/formatting/spacing.ts index 608a3fe1ab..a40391c761 100644 --- a/src/file/paragraph/formatting/spacing.ts +++ b/src/file/paragraph/formatting/spacing.ts @@ -2,14 +2,14 @@ import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-components"; export interface ISpacingProperties { - after?: number; - before?: number; - line?: number; - lineRule?: string; + readonly after?: number; + readonly before?: number; + readonly line?: number; + readonly lineRule?: string; } class SpacingAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { after: "w:after", before: "w:before", line: "w:line", diff --git a/src/file/paragraph/formatting/tab-stop.spec.ts b/src/file/paragraph/formatting/tab-stop.spec.ts index 0b048bef98..ac5e563fa5 100644 --- a/src/file/paragraph/formatting/tab-stop.spec.ts +++ b/src/file/paragraph/formatting/tab-stop.spec.ts @@ -2,7 +2,7 @@ import { assert } from "chai"; import { Utility } from "tests/utility"; -import { LeftTabStop, MaxRightTabStop, RightTabStop } from "./tab-stop"; +import { LeaderType, LeftTabStop, MaxRightTabStop, RightTabStop } from "./tab-stop"; describe("LeftTabStop", () => { let tabStop: LeftTabStop; @@ -32,7 +32,7 @@ describe("RightTabStop", () => { let tabStop: RightTabStop; beforeEach(() => { - tabStop = new RightTabStop(100, "dot"); + tabStop = new RightTabStop(100, LeaderType.DOT); }); describe("#constructor()", () => { diff --git a/src/file/paragraph/formatting/tab-stop.ts b/src/file/paragraph/formatting/tab-stop.ts index 5dc4f68e4f..2706c6f43d 100644 --- a/src/file/paragraph/formatting/tab-stop.ts +++ b/src/file/paragraph/formatting/tab-stop.ts @@ -8,11 +8,32 @@ export class TabStop extends XmlComponent { } } -export type TabValue = "left" | "right" | "center" | "bar" | "clear" | "decimal" | "end" | "num" | "start"; -export type LeaderType = "dot" | "hyphen" | "middleDot" | "none" | "underscore"; +export enum TabValue { + LEFT = "left", + RIGHT = "right", + CENTER = "center", + BAR = "bar", + CLEAR = "clear", + DECIMAL = "decimal", + END = "end", + NUM = "num", + START = "start", +} -export class TabAttributes extends XmlAttributeComponent<{ val: TabValue; pos: string | number; leader?: LeaderType }> { - protected xmlKeys = { val: "w:val", pos: "w:pos", leader: "w:leader" }; +export enum LeaderType { + DOT = "dot", + HYPHEN = "hyphen", + MIDDLE_DOT = "middleDot", + NONE = "none", + UNDERSCORE = "underscore", +} + +export class TabAttributes extends XmlAttributeComponent<{ + readonly val: TabValue; + readonly pos: string | number; + readonly leader?: LeaderType; +}> { + protected readonly xmlKeys = { val: "w:val", pos: "w:pos", leader: "w:leader" }; } export class TabStopItem extends XmlComponent { @@ -30,24 +51,24 @@ export class TabStopItem extends XmlComponent { export class MaxRightTabStop extends TabStop { constructor(leader?: LeaderType) { - super(new TabStopItem("right", 9026, leader)); + super(new TabStopItem(TabValue.RIGHT, 9026, leader)); } } export class LeftTabStop extends TabStop { constructor(position: number, leader?: LeaderType) { - super(new TabStopItem("left", position, leader)); + super(new TabStopItem(TabValue.LEFT, position, leader)); } } export class RightTabStop extends TabStop { constructor(position: number, leader?: LeaderType) { - super(new TabStopItem("right", position, leader)); + super(new TabStopItem(TabValue.RIGHT, position, leader)); } } export class CenterTabStop extends TabStop { constructor(position: number, leader?: LeaderType) { - super(new TabStopItem("center", position, leader)); + super(new TabStopItem(TabValue.CENTER, position, leader)); } } diff --git a/src/file/paragraph/links/bookmark-attributes.ts b/src/file/paragraph/links/bookmark-attributes.ts index 670c462306..3858b5c464 100644 --- a/src/file/paragraph/links/bookmark-attributes.ts +++ b/src/file/paragraph/links/bookmark-attributes.ts @@ -1,23 +1,23 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IBookmarkStartAttributesProperties { - id: string; - name: string; + readonly id: string; + readonly name: string; } export class BookmarkStartAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { id: "w:id", name: "w:name", }; } export interface IBookmarkEndAttributesProperties { - id: string; + readonly id: string; } export class BookmarkEndAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { id: "w:id", }; } diff --git a/src/file/paragraph/links/bookmark.ts b/src/file/paragraph/links/bookmark.ts index de4fabdaa2..c8c339e578 100644 --- a/src/file/paragraph/links/bookmark.ts +++ b/src/file/paragraph/links/bookmark.ts @@ -1,16 +1,12 @@ // http://officeopenxml.com/WPbookmark.php - import { XmlComponent } from "file/xml-components"; import { TextRun } from "../run"; import { BookmarkEndAttributes, BookmarkStartAttributes } from "./bookmark-attributes"; export class Bookmark { - public linkId: number; - + public readonly linkId: number; public readonly start: BookmarkStart; - public readonly text: TextRun; - public readonly end: BookmarkEnd; constructor(name: string, text: string, relationshipsCount: number) { @@ -23,7 +19,7 @@ export class Bookmark { } export class BookmarkStart extends XmlComponent { - public linkId: number; + public readonly linkId: number; constructor(name: string, relationshipsCount: number) { super("w:bookmarkStart"); @@ -39,7 +35,7 @@ export class BookmarkStart extends XmlComponent { } export class BookmarkEnd extends XmlComponent { - public linkId: number; + public readonly linkId: number; constructor(relationshipsCount: number) { super("w:bookmarkEnd"); diff --git a/src/file/paragraph/links/hyperlink-attributes.ts b/src/file/paragraph/links/hyperlink-attributes.ts index 6d68e265b4..983331154a 100644 --- a/src/file/paragraph/links/hyperlink-attributes.ts +++ b/src/file/paragraph/links/hyperlink-attributes.ts @@ -1,13 +1,13 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IHyperlinkAttributesProperties { - id?: string; - anchor?: string; - history: number; + readonly id?: string; + readonly anchor?: string; + readonly history: number; } export class HyperlinkAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { id: "r:id", history: "w:history", anchor: "w:anchor", diff --git a/src/file/paragraph/links/hyperlink.ts b/src/file/paragraph/links/hyperlink.ts index b6fe1b221b..ecdfafe803 100644 --- a/src/file/paragraph/links/hyperlink.ts +++ b/src/file/paragraph/links/hyperlink.ts @@ -1,11 +1,10 @@ // http://officeopenxml.com/WPhyperlink.php - import { XmlComponent } from "file/xml-components"; import { TextRun } from "../run"; import { HyperlinkAttributes, IHyperlinkAttributesProperties } from "./hyperlink-attributes"; export class Hyperlink extends XmlComponent { - public linkId: number; + public readonly linkId: number; constructor(text: string, relationshipsCount: number, anchor?: string) { super("w:hyperlink"); @@ -14,14 +13,10 @@ export class Hyperlink extends XmlComponent { const props: IHyperlinkAttributesProperties = { history: 1, + anchor: anchor ? anchor : undefined, + id: !anchor ? `rId${this.linkId}` : undefined, }; - if (anchor) { - props.anchor = anchor; - } else { - props.id = `rId${this.linkId}`; - } - const attributes = new HyperlinkAttributes(props); this.root.push(attributes); this.root.push(new TextRun(text).style("Hyperlink")); diff --git a/src/file/paragraph/paragraph.ts b/src/file/paragraph/paragraph.ts index 263064d2fa..fc6c46d50b 100644 --- a/src/file/paragraph/paragraph.ts +++ b/src/file/paragraph/paragraph.ts @@ -4,7 +4,7 @@ import { Image } from "file/media"; import { Num } from "file/numbering/num"; import { XmlComponent } from "file/xml-components"; -import { Alignment } from "./formatting/alignment"; +import { Alignment, AlignmentOptions } from "./formatting/alignment"; import { Bidirectional } from "./formatting/bidirectional"; import { Border, ThematicBreak } from "./formatting/border"; import { IIndentAttributesProperties, Indent } from "./formatting/indent"; @@ -110,37 +110,37 @@ export class Paragraph extends XmlComponent { } public center(): Paragraph { - this.properties.push(new Alignment("center")); + this.properties.push(new Alignment(AlignmentOptions.CENTER)); return this; } public left(): Paragraph { - this.properties.push(new Alignment("left")); + this.properties.push(new Alignment(AlignmentOptions.LEFT)); return this; } public right(): Paragraph { - this.properties.push(new Alignment("right")); + this.properties.push(new Alignment(AlignmentOptions.RIGHT)); return this; } public start(): Paragraph { - this.properties.push(new Alignment("start")); + this.properties.push(new Alignment(AlignmentOptions.START)); return this; } public end(): Paragraph { - this.properties.push(new Alignment("end")); + this.properties.push(new Alignment(AlignmentOptions.END)); return this; } public distribute(): Paragraph { - this.properties.push(new Alignment("distribute")); + this.properties.push(new Alignment(AlignmentOptions.DISTRIBUTE)); return this; } public justified(): Paragraph { - this.properties.push(new Alignment("both")); + this.properties.push(new Alignment(AlignmentOptions.BOTH)); return this; } diff --git a/src/file/paragraph/properties.ts b/src/file/paragraph/properties.ts index 5f0c651246..4388e2b111 100644 --- a/src/file/paragraph/properties.ts +++ b/src/file/paragraph/properties.ts @@ -3,7 +3,7 @@ import { XmlComponent } from "file/xml-components"; import { Border } from "./formatting/border"; export class ParagraphProperties extends XmlComponent { - public paragraphBorder: Border; + public readonly paragraphBorder: Border; constructor() { super("w:pPr"); diff --git a/src/file/paragraph/run/field.ts b/src/file/paragraph/run/field.ts index 0e72c1d624..462c961cdc 100644 --- a/src/file/paragraph/run/field.ts +++ b/src/file/paragraph/run/field.ts @@ -1,26 +1,32 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; -class FidCharAttrs extends XmlAttributeComponent<{ type: "begin" | "end" | "separate"; dirty?: boolean }> { - protected xmlKeys = { type: "w:fldCharType", dirty: "w:dirty" }; +enum FieldCharacterType { + BEGIN = "begin", + END = "end", + SEPARATE = "separate", +} + +class FidCharAttrs extends XmlAttributeComponent<{ readonly type: FieldCharacterType; readonly dirty?: boolean }> { + protected readonly xmlKeys = { type: "w:fldCharType", dirty: "w:dirty" }; } export class Begin extends XmlComponent { constructor(dirty?: boolean) { super("w:fldChar"); - this.root.push(new FidCharAttrs({ type: "begin", dirty })); + this.root.push(new FidCharAttrs({ type: FieldCharacterType.BEGIN, dirty })); } } export class Separate extends XmlComponent { constructor(dirty?: boolean) { super("w:fldChar"); - this.root.push(new FidCharAttrs({ type: "separate", dirty })); + this.root.push(new FidCharAttrs({ type: FieldCharacterType.SEPARATE, dirty })); } } export class End extends XmlComponent { constructor(dirty?: boolean) { super("w:fldChar"); - this.root.push(new FidCharAttrs({ type: "end", dirty })); + this.root.push(new FidCharAttrs({ type: FieldCharacterType.END, dirty })); } } diff --git a/src/file/paragraph/run/page-number.ts b/src/file/paragraph/run/page-number.ts index ab3592fd18..4ae0eaafd7 100644 --- a/src/file/paragraph/run/page-number.ts +++ b/src/file/paragraph/run/page-number.ts @@ -1,13 +1,14 @@ +import { SpaceType } from "file/space-type"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; -class TextAttributes extends XmlAttributeComponent<{ space: "default" | "preserve" }> { - protected xmlKeys = { space: "xml:space" }; +class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> { + protected readonly xmlKeys = { space: "xml:space" }; } export class Page extends XmlComponent { constructor() { super("w:instrText"); - this.root.push(new TextAttributes({ space: "preserve" })); + this.root.push(new TextAttributes({ space: SpaceType.PRESERVE })); this.root.push("PAGE"); } } diff --git a/src/file/paragraph/run/picture-run.ts b/src/file/paragraph/run/picture-run.ts index d51d0fc8f9..15da74eb56 100644 --- a/src/file/paragraph/run/picture-run.ts +++ b/src/file/paragraph/run/picture-run.ts @@ -18,15 +18,7 @@ export class PictureRun extends Run { this.root.push(this.drawing); } - public scale(factorX: number, factorY?: number): void { - if (!factorX) { - factorX = 1; - } - - if (!factorY) { - factorY = factorX; - } - + public scale(factorX: number = 1, factorY: number = factorX): void { this.drawing.scale(factorX, factorY); } } diff --git a/src/file/paragraph/run/run-components/text.ts b/src/file/paragraph/run/run-components/text.ts index 894afad170..5cac4500b4 100644 --- a/src/file/paragraph/run/run-components/text.ts +++ b/src/file/paragraph/run/run-components/text.ts @@ -1,13 +1,14 @@ +import { SpaceType } from "file/space-type"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; -class TextAttributes extends XmlAttributeComponent<{ space: "default" | "preserve" }> { - protected xmlKeys = { space: "xml:space" }; +class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> { + protected readonly xmlKeys = { space: "xml:space" }; } export class Text extends XmlComponent { constructor(text: string) { super("w:t"); - this.root.push(new TextAttributes({ space: "preserve" })); + this.root.push(new TextAttributes({ space: SpaceType.PRESERVE })); if (text) { this.root.push(text); } diff --git a/src/file/paragraph/run/run-fonts.ts b/src/file/paragraph/run/run-fonts.ts index bf667f6b19..10a441626c 100644 --- a/src/file/paragraph/run/run-fonts.ts +++ b/src/file/paragraph/run/run-fonts.ts @@ -1,15 +1,15 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; interface IRunFontAttributesProperties { - ascii: string; - cs: string; - eastAsia: string; - hAnsi: string; - hint?: string; + readonly ascii: string; + readonly cs: string; + readonly eastAsia: string; + readonly hAnsi: string; + readonly hint?: string; } class RunFontAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { ascii: "w:ascii", cs: "w:cs", eastAsia: "w:eastAsia", diff --git a/src/file/paragraph/run/run.ts b/src/file/paragraph/run/run.ts index b7722e1e44..74e011b402 100644 --- a/src/file/paragraph/run/run.ts +++ b/src/file/paragraph/run/run.ts @@ -25,7 +25,7 @@ import { Underline } from "./underline"; import { XmlComponent } from "file/xml-components"; export class Run extends XmlComponent { - protected properties: RunProperties; + protected readonly properties: RunProperties; constructor() { super("w:r"); diff --git a/src/file/paragraph/run/sequential-identifier-instruction.ts b/src/file/paragraph/run/sequential-identifier-instruction.ts index 6f48738db7..aad320cbdb 100644 --- a/src/file/paragraph/run/sequential-identifier-instruction.ts +++ b/src/file/paragraph/run/sequential-identifier-instruction.ts @@ -1,13 +1,9 @@ // http://officeopenxml.com/WPfieldInstructions.php +import { SpaceType } from "file/space-type"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; -enum SpaceType { - DEFAULT = "default", - PRESERVE = "preserve", -} - -class TextAttributes extends XmlAttributeComponent<{ space: SpaceType }> { - protected xmlKeys = { space: "xml:space" }; +class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> { + protected readonly xmlKeys = { space: "xml:space" }; } export class SequentialIdentifierInstruction extends XmlComponent { diff --git a/src/file/paragraph/run/style.ts b/src/file/paragraph/run/style.ts index 7e67205990..2472c1d406 100644 --- a/src/file/paragraph/run/style.ts +++ b/src/file/paragraph/run/style.ts @@ -1,7 +1,7 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; -class StyleAttributes extends XmlAttributeComponent<{ val: string }> { - protected xmlKeys = { val: "w:val" }; +class StyleAttributes extends XmlAttributeComponent<{ readonly val: string }> { + protected readonly xmlKeys = { val: "w:val" }; } export class Style extends XmlComponent { diff --git a/src/file/relationships/attributes.ts b/src/file/relationships/attributes.ts index 54cbd62472..c0e6ead4a1 100644 --- a/src/file/relationships/attributes.ts +++ b/src/file/relationships/attributes.ts @@ -1,11 +1,11 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IRelationshipsAttributesProperties { - xmlns: string; + readonly xmlns: string; } export class RelationshipsAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { xmlns: "xmlns", }; } diff --git a/src/file/relationships/relationship/relationship-attributes.ts b/src/file/relationships/relationship/relationship-attributes.ts index 1cb3e116c0..98cbacbdae 100644 --- a/src/file/relationships/relationship/relationship-attributes.ts +++ b/src/file/relationships/relationship/relationship-attributes.ts @@ -1,14 +1,14 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IRelationshipAttributesProperties { - id: string; - type: string; - target: string; - targetMode?: string; + readonly id: string; + readonly type: string; + readonly target: string; + readonly targetMode?: string; } export class RelationshipAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { id: "Id", type: "Type", target: "Target", diff --git a/src/file/settings/settings.ts b/src/file/settings/settings.ts index d955de0177..49bad8d23c 100644 --- a/src/file/settings/settings.ts +++ b/src/file/settings/settings.ts @@ -1,26 +1,26 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { UpdateFields } from "./update-fields"; export interface ISettingsAttributesProperties { - wpc?: string; - mc?: string; - o?: string; - r?: string; - m?: string; - v?: string; - wp14?: string; - wp?: string; - w10?: string; - w?: string; - w14?: string; - w15?: string; - wpg?: string; - wpi?: string; - wne?: string; - wps?: string; - Ignorable?: string; + readonly wpc?: string; + readonly mc?: string; + readonly o?: string; + readonly r?: string; + readonly m?: string; + readonly v?: string; + readonly wp14?: string; + readonly wp?: string; + readonly w10?: string; + readonly w?: string; + readonly w14?: string; + readonly w15?: string; + readonly wpg?: string; + readonly wpi?: string; + readonly wne?: string; + readonly wps?: string; + readonly Ignorable?: string; } export class SettingsAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { wpc: "xmlns:wpc", mc: "xmlns:mc", o: "xmlns:o", diff --git a/src/file/settings/update-fields.ts b/src/file/settings/update-fields.ts index 782aa13264..8cb013ce0d 100644 --- a/src/file/settings/update-fields.ts +++ b/src/file/settings/update-fields.ts @@ -1,9 +1,9 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; export interface IUpdateFieldsAttributesProperties { - enabled: boolean; + readonly enabled: boolean; } export class UpdateFieldsAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { enabled: "w:val", }; } diff --git a/src/file/space-type.ts b/src/file/space-type.ts new file mode 100644 index 0000000000..f40c2d88fc --- /dev/null +++ b/src/file/space-type.ts @@ -0,0 +1,4 @@ +export enum SpaceType { + DEFAULT = "default", + PRESERVE = "preserve", +} diff --git a/src/file/styles/latent-styles/exceptions.ts b/src/file/styles/latent-styles/exceptions.ts index 4695df55a0..3ae340b922 100644 --- a/src/file/styles/latent-styles/exceptions.ts +++ b/src/file/styles/latent-styles/exceptions.ts @@ -1,15 +1,15 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; export interface ILatentStyleExceptionAttributesProperties { - name?: string; - uiPriority?: string; - qFormat?: string; - semiHidden?: string; - unhideWhenUsed?: string; + readonly name?: string; + readonly uiPriority?: string; + readonly qFormat?: string; + readonly semiHidden?: string; + readonly unhideWhenUsed?: string; } export class LatentStyleExceptionAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { name: "w:name", uiPriority: "w:uiPriority", qFormat: "w:qFormat", diff --git a/src/file/styles/style/components.ts b/src/file/styles/style/components.ts index 5535036ac9..019b50624b 100644 --- a/src/file/styles/style/components.ts +++ b/src/file/styles/style/components.ts @@ -1,11 +1,11 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; interface IComponentAttributes { - val: string; + readonly val: string; } class ComponentAttributes extends XmlAttributeComponent { - protected xmlKeys = { val: "w:val" }; + protected readonly xmlKeys = { val: "w:val" }; } export class Name extends XmlComponent { diff --git a/src/file/styles/style/index.ts b/src/file/styles/style/index.ts index f262a473fb..cf14ae6c5e 100644 --- a/src/file/styles/style/index.ts +++ b/src/file/styles/style/index.ts @@ -1,4 +1,16 @@ -import * as paragraph from "file/paragraph"; +import { + Alignment, + AlignmentOptions, + Indent, + ISpacingProperties, + KeepLines, + KeepNext, + LeftTabStop, + MaxRightTabStop, + ParagraphProperties, + Spacing, + ThematicBreak, +} from "file/paragraph"; import * as formatting from "file/paragraph/run/formatting"; import { RunProperties } from "file/paragraph/run/properties"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; @@ -6,14 +18,14 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { BasedOn, Link, Name, Next, QuickFormat, SemiHidden, UiPriority, UnhideWhenUsed } from "./components"; export interface IStyleAttributes { - type?: string; - styleId?: string; - default?: boolean; - customStyle?: string; + readonly type?: string; + readonly styleId?: string; + readonly default?: boolean; + readonly customStyle?: string; } class StyleAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { type: "w:type", styleId: "w:styleId", default: "w:default", @@ -36,12 +48,12 @@ export class Style extends XmlComponent { } export class ParagraphStyle extends Style { - private readonly paragraphProperties: paragraph.ParagraphProperties; + private readonly paragraphProperties: ParagraphProperties; private readonly runProperties: RunProperties; constructor(styleId: string, name?: string) { super({ type: "paragraph", styleId: styleId }, name); - this.paragraphProperties = new paragraph.ParagraphProperties(); + this.paragraphProperties = new ParagraphProperties(); this.runProperties = new RunProperties(); this.root.push(this.paragraphProperties); this.root.push(this.runProperties); @@ -129,47 +141,47 @@ export class ParagraphStyle extends Style { // --------------------- Paragraph formatting ------------------------ // public center(): ParagraphStyle { - return this.addParagraphProperty(new paragraph.Alignment("center")); + return this.addParagraphProperty(new Alignment(AlignmentOptions.CENTER)); } public left(): ParagraphStyle { - return this.addParagraphProperty(new paragraph.Alignment("left")); + return this.addParagraphProperty(new Alignment(AlignmentOptions.LEFT)); } public right(): ParagraphStyle { - return this.addParagraphProperty(new paragraph.Alignment("right")); + return this.addParagraphProperty(new Alignment(AlignmentOptions.RIGHT)); } public justified(): ParagraphStyle { - return this.addParagraphProperty(new paragraph.Alignment("both")); + return this.addParagraphProperty(new Alignment(AlignmentOptions.BOTH)); } public thematicBreak(): ParagraphStyle { - return this.addParagraphProperty(new paragraph.ThematicBreak()); + return this.addParagraphProperty(new ThematicBreak()); } public maxRightTabStop(): ParagraphStyle { - return this.addParagraphProperty(new paragraph.MaxRightTabStop()); + return this.addParagraphProperty(new MaxRightTabStop()); } public leftTabStop(position: number): ParagraphStyle { - return this.addParagraphProperty(new paragraph.LeftTabStop(position)); + return this.addParagraphProperty(new LeftTabStop(position)); } public indent(attrs: object): ParagraphStyle { - return this.addParagraphProperty(new paragraph.Indent(attrs)); + return this.addParagraphProperty(new Indent(attrs)); } - public spacing(params: paragraph.ISpacingProperties): ParagraphStyle { - return this.addParagraphProperty(new paragraph.Spacing(params)); + public spacing(params: ISpacingProperties): ParagraphStyle { + return this.addParagraphProperty(new Spacing(params)); } public keepNext(): ParagraphStyle { - return this.addParagraphProperty(new paragraph.KeepNext()); + return this.addParagraphProperty(new KeepNext()); } public keepLines(): ParagraphStyle { - return this.addParagraphProperty(new paragraph.KeepLines()); + return this.addParagraphProperty(new KeepLines()); } } diff --git a/src/file/table-of-contents/alias.ts b/src/file/table-of-contents/alias.ts index d3a3235391..4cc9f82440 100644 --- a/src/file/table-of-contents/alias.ts +++ b/src/file/table-of-contents/alias.ts @@ -1,7 +1,7 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; -class AliasAttributes extends XmlAttributeComponent<{ alias: string }> { - protected xmlKeys = { alias: "w:val" }; +class AliasAttributes extends XmlAttributeComponent<{ readonly alias: string }> { + protected readonly xmlKeys = { alias: "w:val" }; } export class Alias extends XmlComponent { diff --git a/src/file/table-of-contents/field-instruction.ts b/src/file/table-of-contents/field-instruction.ts index 09f5129613..f8da8f97ba 100644 --- a/src/file/table-of-contents/field-instruction.ts +++ b/src/file/table-of-contents/field-instruction.ts @@ -1,14 +1,10 @@ // http://officeopenxml.com/WPfieldInstructions.php +import { SpaceType } from "file/space-type"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { ITableOfContentsOptions } from "./table-of-contents-properties"; -enum SpaceType { - DEFAULT = "default", - PRESERVE = "preserve", -} - -class TextAttributes extends XmlAttributeComponent<{ space: SpaceType }> { - protected xmlKeys = { space: "xml:space" }; +class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> { + protected readonly xmlKeys = { space: "xml:space" }; } export class FieldInstruction extends XmlComponent { diff --git a/src/file/table-of-contents/table-of-contents-properties.ts b/src/file/table-of-contents/table-of-contents-properties.ts index bc312429af..2ae650d419 100644 --- a/src/file/table-of-contents/table-of-contents-properties.ts +++ b/src/file/table-of-contents/table-of-contents-properties.ts @@ -1,6 +1,6 @@ export class StyleLevel { - public styleName: string; - public level: number; + public readonly styleName: string; + public readonly level: number; constructor(styleName: string, level: number) { this.styleName = styleName; @@ -22,13 +22,13 @@ export interface ITableOfContentsOptions { * The identifier designated by text in this switch's field-argument corresponds to the caption label. * Use captionLabelIncludingNumbers (\c) to build a table of captions with labels and numbers. */ - captionLabel?: string; + readonly captionLabel?: string; /** * \b option - Includes entries only from the portion of the document marked by * the bookmark named by text in this switch's field-argument. */ - entriesFromBookmark?: string; + readonly entriesFromBookmark?: string; /** * \c option - Includes figures, tables, charts, and other items that are numbered @@ -36,24 +36,24 @@ export interface ITableOfContentsOptions { * field-argument, which corresponds to the caption label, shall match the identifier in the * corresponding SEQ field. */ - captionLabelIncludingNumbers?: string; + readonly captionLabelIncludingNumbers?: string; /** * \d option - When used with \s, the text in this switch's field-argument defines * the separator between sequence and page numbers. The default separator is a hyphen (-). */ - sequenceAndPageNumbersSeparator?: string; + readonly sequenceAndPageNumbersSeparator?: string; /** * \f option - Includes only those TC fields whose identifier exactly matches the * text in this switch's field-argument (which is typically a letter). */ - tcFieldIdentifier?: string; + readonly tcFieldIdentifier?: string; /** * \h option - Makes the table of contents entries hyperlinks. */ - hyperlink?: boolean; + readonly hyperlink?: boolean; /** * \l option - Includes TC fields that assign entries to one of the levels specified @@ -61,14 +61,14 @@ export interface ITableOfContentsOptions { * where startLevel and endLevel are integers, and startLevel has a value equal-to or less-than endLevel. * TC fields that assign entries to lower levels are skipped. */ - tcFieldLevelRange?: string; + readonly tcFieldLevelRange?: string; /** * \n option - Without field-argument, omits page numbers from the table of contents. * Page numbers are omitted from all levels unless a range of entry levels is specified by * text in this switch's field-argument. A range is specified as for \l. */ - pageNumbersEntryLevelsRange?: string; + readonly pageNumbersEntryLevelsRange?: string; /** * \o option - Uses paragraphs formatted with all or the specified range of builtin @@ -77,20 +77,20 @@ export interface ITableOfContentsOptions { * to the style with a style ID of HeadingX (e.g. 1 corresponds to Heading1). * If no heading range is specified, all heading levels used in the document are listed. */ - headingStyleRange?: string; + readonly headingStyleRange?: string; /** * \p option - Text in this switch's field-argument specifies a sequence of characters * that separate an entry and its page number. The default is a tab with leader dots. */ - entryAndPageNumberSeparator?: string; + readonly entryAndPageNumberSeparator?: string; /** * \s option - For entries numbered with a SEQ field (§17.16.5.56), adds a prefix to the page number. * The prefix depends on the type of entry. text in this switch's field-argument shall match the * identifier in the SEQ field. */ - seqFieldIdentifierForPrefix?: string; + readonly seqFieldIdentifierForPrefix?: string; /** * \t field-argument Uses paragraphs formatted with styles other than the built-in heading styles. @@ -98,25 +98,25 @@ 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. */ - stylesWithLevels?: StyleLevel[]; + readonly stylesWithLevels?: StyleLevel[]; /** * \u Uses the applied paragraph outline level. */ - useAppliedParagraphOutlineLevel?: boolean; + readonly useAppliedParagraphOutlineLevel?: boolean; /** * \w Preserves tab entries within table entries. */ - preserveTabInEntries?: boolean; + readonly preserveTabInEntries?: boolean; /** * \x Preserves newline characters within table entries. */ - preserveNewLineInEntries?: boolean; + readonly preserveNewLineInEntries?: boolean; /** * \z Hides tab leader and page numbers in web page view (§17.18.102). */ - hideTabAndPageNumbersInWebView?: boolean; + readonly hideTabAndPageNumbersInWebView?: boolean; } diff --git a/src/file/table-of-contents/table-of-contents.spec.ts b/src/file/table-of-contents/table-of-contents.spec.ts index 02a4c9c877..ce5312ac63 100644 --- a/src/file/table-of-contents/table-of-contents.spec.ts +++ b/src/file/table-of-contents/table-of-contents.spec.ts @@ -3,7 +3,7 @@ import { expect } from "chai"; import { Formatter } from "export/formatter"; import { TableOfContents } from "./table-of-contents"; -import { ITableOfContentsOptions, StyleLevel } from "./table-of-contents-properties"; +import { StyleLevel } from "./table-of-contents-properties"; describe("Table of Contents", () => { describe("#constructor", () => { @@ -14,28 +14,28 @@ describe("Table of Contents", () => { }); it("should construct a TOC with all the options and alias", () => { - const props: ITableOfContentsOptions = {}; - - props.captionLabel = "A"; - props.entriesFromBookmark = "B"; - props.captionLabelIncludingNumbers = "C"; - props.sequenceAndPageNumbersSeparator = "D"; - props.tcFieldIdentifier = "F"; - props.hyperlink = true; - props.tcFieldLevelRange = "L"; - props.pageNumbersEntryLevelsRange = "N"; - props.headingStyleRange = "O"; - props.entryAndPageNumberSeparator = "P"; - props.seqFieldIdentifierForPrefix = "S"; - const styles = new Array(); styles.push(new StyleLevel("SL", 1)); styles.push(new StyleLevel("SL", 2)); - props.stylesWithLevels = styles; - props.useAppliedParagraphOutlineLevel = true; - props.preserveTabInEntries = true; - props.preserveNewLineInEntries = true; - props.hideTabAndPageNumbersInWebView = true; + + const props = { + captionLabel: "A", + entriesFromBookmark: "B", + captionLabelIncludingNumbers: "C", + sequenceAndPageNumbersSeparator: "D", + tcFieldIdentifier: "F", + hyperlink: true, + tcFieldLevelRange: "L", + pageNumbersEntryLevelsRange: "N", + headingStyleRange: "O", + entryAndPageNumberSeparator: "P", + seqFieldIdentifierForPrefix: "S", + stylesWithLevels: styles, + useAppliedParagraphOutlineLevel: true, + preserveTabInEntries: true, + preserveNewLineInEntries: true, + hideTabAndPageNumbersInWebView: true, + }; const toc = new TableOfContents("Summary", props); const tree = new Formatter().format(toc); diff --git a/src/file/table/grid.ts b/src/file/table/grid.ts index 0e477df946..b91f6ac9d4 100644 --- a/src/file/table/grid.ts +++ b/src/file/table/grid.ts @@ -8,8 +8,8 @@ export class TableGrid extends XmlComponent { } } -class GridColAttributes extends XmlAttributeComponent<{ w: number }> { - protected xmlKeys = { w: "w:w" }; +class GridColAttributes extends XmlAttributeComponent<{ readonly w: number }> { + protected readonly xmlKeys = { w: "w:w" }; } export class GridCol extends XmlComponent { diff --git a/src/file/table/table-cell/table-cell-components.ts b/src/file/table/table-cell/table-cell-components.ts index 7072654680..7099fea33a 100644 --- a/src/file/table/table-cell/table-cell-components.ts +++ b/src/file/table/table-cell/table-cell-components.ts @@ -2,13 +2,13 @@ import { BorderStyle } from "file/styles"; import { IXmlableObject, XmlAttributeComponent, XmlComponent } from "file/xml-components"; interface ICellBorder { - style: BorderStyle; - size: number; - color: string; + readonly style: BorderStyle; + readonly size: number; + readonly color: string; } class CellBorderAttributes extends XmlAttributeComponent { - protected xmlKeys = { style: "w:val", size: "w:sz", color: "w:color" }; + protected readonly xmlKeys = { style: "w:val", size: "w:sz", color: "w:color" }; } class BaseTableCellBorder extends XmlComponent { @@ -71,8 +71,8 @@ export class TableCellBorders extends XmlComponent { /** * Attributes fot the GridSpan element. */ -class GridSpanAttributes extends XmlAttributeComponent<{ val: number }> { - protected xmlKeys = { val: "w:val" }; +class GridSpanAttributes extends XmlAttributeComponent<{ readonly val: number }> { + protected readonly xmlKeys = { val: "w:val" }; } /** @@ -104,8 +104,8 @@ export enum VMergeType { RESTART = "restart", } -class VMergeAttributes extends XmlAttributeComponent<{ val: VMergeType }> { - protected xmlKeys = { val: "w:val" }; +class VMergeAttributes extends XmlAttributeComponent<{ readonly val: VMergeType }> { + protected readonly xmlKeys = { val: "w:val" }; } /** @@ -129,8 +129,8 @@ export enum VerticalAlign { TOP = "top", } -class VAlignAttributes extends XmlAttributeComponent<{ val: VerticalAlign }> { - protected xmlKeys = { val: "w:val" }; +class VAlignAttributes extends XmlAttributeComponent<{ readonly val: VerticalAlign }> { + protected readonly xmlKeys = { val: "w:val" }; } /** @@ -159,8 +159,8 @@ export enum WidthType { PERCENTAGE = "pct", } -class TableCellWidthAttributes extends XmlAttributeComponent<{ type: WidthType; width: string | number }> { - protected xmlKeys = { width: "w:w", type: "w:type" }; +class TableCellWidthAttributes extends XmlAttributeComponent<{ readonly type: WidthType; readonly width: string | number }> { + protected readonly xmlKeys = { width: "w:w", type: "w:type" }; } /** @@ -180,13 +180,13 @@ export class TableCellWidth extends XmlComponent { } export interface ITableCellShadingAttributesProperties { - fill?: string; - color?: string; - val?: string; + readonly fill?: string; + readonly color?: string; + readonly val?: string; } class TableCellShadingAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { fill: "w:fill", color: "w:color", val: "w:val", diff --git a/src/file/table/table-properties/table-borders.ts b/src/file/table/table-properties/table-borders.ts index c27155ecd0..204bccf496 100644 --- a/src/file/table/table-properties/table-borders.ts +++ b/src/file/table/table-properties/table-borders.ts @@ -26,8 +26,13 @@ class TableBordersElement extends XmlComponent { } } -class TableBordersAttributes extends XmlAttributeComponent<{ value: string; size: number; space: number; color: string }> { - protected xmlKeys = { +class TableBordersAttributes extends XmlAttributeComponent<{ + readonly value: string; + readonly size: number; + readonly space: number; + readonly color: string; +}> { + protected readonly xmlKeys = { value: "w:val", size: "w:sz", space: "w:space", diff --git a/src/file/table/table-properties/table-cell-margin.ts b/src/file/table/table-properties/table-cell-margin.ts index 2cd14682fc..7d5a2cfe02 100644 --- a/src/file/table/table-properties/table-cell-margin.ts +++ b/src/file/table/table-properties/table-cell-margin.ts @@ -2,8 +2,8 @@ import { IXmlableObject, XmlAttributeComponent, XmlComponent } from "file/xml-co import { WidthType } from "../table-cell"; -class TableCellMarginAttributes extends XmlAttributeComponent<{ type: WidthType; value: number }> { - protected xmlKeys = { value: "w:w", type: "w:sz" }; +class TableCellMarginAttributes extends XmlAttributeComponent<{ readonly type: WidthType; readonly value: number }> { + protected readonly xmlKeys = { value: "w:w", type: "w:sz" }; } class BaseTableCellMargin extends XmlComponent { diff --git a/src/file/table/table-properties/table-float-properties.ts b/src/file/table/table-properties/table-float-properties.ts index ae68df2b28..a1053c4ab2 100644 --- a/src/file/table/table-properties/table-float-properties.ts +++ b/src/file/table/table-properties/table-float-properties.ts @@ -32,7 +32,7 @@ export interface ITableFloatOptions { * text - relative to the vertical edge of the text margin for the column in which the anchor paragraph is located * If omitted, the value is assumed to be page. */ - horizontalAnchor?: TableAnchorType; + readonly horizontalAnchor?: TableAnchorType; /** * Specifies an absolute horizontal position for the table, relative to the horizontalAnchor. @@ -41,7 +41,7 @@ export interface ITableFloatOptions { * If relativeHorizontalPosition is also specified, then the absoluteHorizontalPosition attribute is ignored. * If the attribute is omitted, the value is assumed to be zero. */ - absoluteHorizontalPosition?: number; + readonly absoluteHorizontalPosition?: number; /** * Specifies a relative horizontal position for the table, relative to the horizontalAnchor attribute. @@ -53,7 +53,7 @@ export interface ITableFloatOptions { * outside - the table should be outside of the anchor * right - the table should be right aligned with respect to the anchor */ - relativeHorizontalPosition?: RelativeHorizontalPosition; + readonly relativeHorizontalPosition?: RelativeHorizontalPosition; /** * Specifies the vertical anchor or the base object from which the vertical positioning @@ -63,7 +63,7 @@ export interface ITableFloatOptions { * text - relative to the horizontal edge of the text margin for the column in which the anchor paragraph is located * If omitted, the value is assumed to be page. */ - verticalAnchor?: TableAnchorType; + readonly verticalAnchor?: TableAnchorType; /** * Specifies an absolute vertical position for the table, relative to the verticalAnchor anchor. @@ -72,7 +72,7 @@ export interface ITableFloatOptions { * If relativeVerticalPosition is also specified, then the absoluteVerticalPosition attribute is ignored. * If the attribute is omitted, the value is assumed to be zero. */ - absoluteVerticalPosition?: number; + readonly absoluteVerticalPosition?: number; /** * Specifies a relative vertical position for the table, relative to the verticalAnchor attribute. @@ -84,35 +84,35 @@ export interface ITableFloatOptions { * inline - the table should be vertically aligned in line with the surrounding text (so as to not allow any text wrapping around it) * top - the table should be vertically aligned to the top edge of the anchor */ - relativeVerticalPosition?: RelativeVerticalPosition; + readonly relativeVerticalPosition?: RelativeVerticalPosition; /** * Specifies the minimun distance to be maintained between the table and the top of text in the paragraph * below the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero. */ - bottomFromText?: number; + readonly bottomFromText?: number; /** * Specifies the minimun distance to be maintained between the table and the bottom edge of text in the paragraph * above the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero. */ - topFromText?: number; + readonly topFromText?: number; /** * Specifies the minimun distance to be maintained between the table and the edge of text in the paragraph * to the left of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero. */ - leftFromText?: number; + readonly leftFromText?: number; /** * Specifies the minimun distance to be maintained between the table and the edge of text in the paragraph * to the right of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero. */ - rightFromText?: number; + readonly rightFromText?: number; } export class TableFloatOptionsAttributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { horizontalAnchor: "w:horzAnchor", verticalAnchor: "w:vertAnchor", absoluteHorizontalPosition: "w:tblpX", diff --git a/src/file/table/table-properties/table-layout.ts b/src/file/table/table-properties/table-layout.ts index 85334181e0..58fc14f4ec 100644 --- a/src/file/table/table-properties/table-layout.ts +++ b/src/file/table/table-properties/table-layout.ts @@ -5,8 +5,8 @@ export enum TableLayoutType { FIXED = "fixed", } -class TableLayoutAttributes extends XmlAttributeComponent<{ type: TableLayoutType }> { - protected xmlKeys = { type: "w:type" }; +class TableLayoutAttributes extends XmlAttributeComponent<{ readonly type: TableLayoutType }> { + protected readonly xmlKeys = { type: "w:type" }; } export class TableLayout extends XmlComponent { diff --git a/src/file/table/table-properties/table-width.ts b/src/file/table/table-properties/table-width.ts index 27caa5c819..1c76f82c6b 100644 --- a/src/file/table/table-properties/table-width.ts +++ b/src/file/table/table-properties/table-width.ts @@ -3,12 +3,12 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { WidthType } from "../table-cell"; interface ITableWidth { - type: WidthType; - w: number | string; + readonly type: WidthType; + readonly w: number | string; } class TableWidthAttributes extends XmlAttributeComponent { - protected xmlKeys = { type: "w:type", w: "w:w" }; + protected readonly xmlKeys = { type: "w:type", w: "w:w" }; } export class PreferredTableWidth extends XmlComponent { diff --git a/src/file/xml-components/attributes.ts b/src/file/xml-components/attributes.ts index b7813cb11a..02ed46b434 100644 --- a/src/file/xml-components/attributes.ts +++ b/src/file/xml-components/attributes.ts @@ -1,29 +1,29 @@ import { XmlAttributeComponent } from "./default-attributes"; export interface IAttributesProperties { - val?: string | number | boolean; - color?: string; - space?: string; - sz?: string; - type?: string; - rsidR?: string; - rsidRPr?: string; - rsidSect?: string; - w?: string; - h?: string; - top?: string; - right?: string; - bottom?: string; - left?: string; - header?: string; - footer?: string; - gutter?: string; - linePitch?: string; - pos?: string | number; // Little strange. Perhaps it is normal. Need to clarify in the spec. + readonly val?: string | number | boolean; + readonly color?: string; + readonly space?: string; + readonly sz?: string; + readonly type?: string; + readonly rsidR?: string; + readonly rsidRPr?: string; + readonly rsidSect?: string; + readonly w?: string; + readonly h?: string; + readonly top?: string; + readonly right?: string; + readonly bottom?: string; + readonly left?: string; + readonly header?: string; + readonly footer?: string; + readonly gutter?: string; + readonly linePitch?: string; + readonly pos?: string | number; // Little strange. Perhaps it is normal. Need to clarify in the spec. } export class Attributes extends XmlAttributeComponent { - protected xmlKeys = { + protected readonly xmlKeys = { val: "w:val", color: "w:color", space: "w:space", diff --git a/src/file/xml-components/base.ts b/src/file/xml-components/base.ts index d65e5c6f3c..cfc4ec47b3 100644 --- a/src/file/xml-components/base.ts +++ b/src/file/xml-components/base.ts @@ -1,7 +1,8 @@ import { IXmlableObject } from "./xmlable-object"; export abstract class BaseXmlComponent { - protected rootKey: string; + protected readonly rootKey: string; + // tslint:disable-next-line:readonly-keyword protected deleted: boolean = false; constructor(rootKey: string) { diff --git a/src/file/xml-components/default-attributes.ts b/src/file/xml-components/default-attributes.ts index 482546b59d..0bfe444f5f 100644 --- a/src/file/xml-components/default-attributes.ts +++ b/src/file/xml-components/default-attributes.ts @@ -4,8 +4,9 @@ import { IXmlableObject } from "./xmlable-object"; export type AttributeMap = { [P in keyof T]: string }; export abstract class XmlAttributeComponent extends BaseXmlComponent { + // tslint:disable-next-line:readonly-keyword protected root: T; - protected xmlKeys: AttributeMap; + protected readonly xmlKeys: AttributeMap; constructor(properties: T) { super("_attr"); diff --git a/src/file/xml-components/xml-component.ts b/src/file/xml-components/xml-component.ts index acbe51cb04..b386c52c42 100644 --- a/src/file/xml-components/xml-component.ts +++ b/src/file/xml-components/xml-component.ts @@ -3,6 +3,7 @@ import { IXmlableObject } from "./xmlable-object"; export { BaseXmlComponent }; export abstract class XmlComponent extends BaseXmlComponent { + // tslint:disable-next-line:readonly-keyword protected root: Array; constructor(rootKey: string) { diff --git a/src/file/xml-components/xmlable-object.ts b/src/file/xml-components/xmlable-object.ts index 33d41e2af1..3db8da55af 100644 --- a/src/file/xml-components/xmlable-object.ts +++ b/src/file/xml-components/xmlable-object.ts @@ -1,8 +1,8 @@ export interface IXmlAttribute { - [key: string]: string | number | boolean; + readonly [key: string]: string | number | boolean; } export interface IXmlableObject extends Object { - _attr?: IXmlAttribute; + readonly _attr?: IXmlAttribute; } // Needed because of: https://github.com/s-panferov/awesome-typescript-loader/issues/432 diff --git a/src/import-dotx/import-dotx.ts b/src/import-dotx/import-dotx.ts index 0b3ce692e2..9ece4db3f1 100644 --- a/src/import-dotx/import-dotx.ts +++ b/src/import-dotx/import-dotx.ts @@ -19,27 +19,28 @@ const schemeToType = { }; interface IDocumentRefs { - headers: Array<{ id: number; type: HeaderReferenceType }>; - footers: Array<{ id: number; type: FooterReferenceType }>; + readonly headers: Array<{ readonly id: number; readonly type: HeaderReferenceType }>; + readonly footers: Array<{ readonly id: number; readonly type: FooterReferenceType }>; } interface IRelationshipFileInfo { - id: number; - target: string; - type: "header" | "footer" | "image" | "hyperlink"; + readonly id: number; + readonly target: string; + readonly type: "header" | "footer" | "image" | "hyperlink"; } // Document Template // https://fileinfo.com/extension/dotx export interface IDocumentTemplate { - currentRelationshipId: number; - headers: IDocumentHeader[]; - footers: IDocumentFooter[]; - styles: Styles; - titlePageIsDefined: boolean; + readonly currentRelationshipId: number; + readonly headers: IDocumentHeader[]; + readonly footers: IDocumentFooter[]; + readonly styles: Styles; + readonly titlePageIsDefined: boolean; } export class ImportDotx { + // tslint:disable-next-line:readonly-keyword private currentRelationshipId: number; constructor() { diff --git a/tslint.json b/tslint.json index 497035eccc..c06144bfe1 100644 --- a/tslint.json +++ b/tslint.json @@ -1,41 +1,29 @@ { - "extends": "tslint:latest", + "extends": ["tslint:latest", "tslint-immutable"], "rules": { "curly": true, - "one-variable-per-declaration": [ - true - ], + "one-variable-per-declaration": [true], "no-any": true, - "no-consecutive-blank-lines": [ - true - ], + "no-consecutive-blank-lines": [true], "no-require-imports": true, - "member-access": [ - true, - "check-accessor" - ], - "indent": [ - true, - "spaces" - ], + "member-access": [true, "check-accessor"], + "indent": [true, "spaces"], "object-literal-sort-keys": false, "object-literal-shorthand": false, - "typedef": [ - true, - "call-signature", - "parameter", - "property-declaration" - ], - "max-line-length": [ - false - ], - "max-classes-per-file": [ - false - ], + "typedef": [true, "call-signature", "parameter", "property-declaration"], + "max-line-length": [false], + "max-classes-per-file": [false], "no-implicit-dependencies": false, "no-submodule-imports": false, "no-null-keyword": true, "return-undefined": true, - "prefer-readonly": true + "prefer-readonly": true, + // Functional Programming Rules + "no-parameter-reassignment": true, + "readonly-keyword": true, + "no-delete": true, + "no-method-signature": true, + "no-mixed-interface": true + // "no-expression-statement": [true, { "ignore-prefix": ["console.", "describe", "it", "super", "expect"] }] } }