diff --git a/.cspell.json b/.cspell.json index 11b7757ab0b..c27f9e37349 100644 --- a/.cspell.json +++ b/.cspell.json @@ -17,6 +17,7 @@ "dolan", "execa", "falsey", + "horz", "iife", "Initializable", "iroha", diff --git a/src/export/packer/next-compiler.ts b/src/export/packer/next-compiler.ts index 92869b65cd4..e1ec950af2e 100644 --- a/src/export/packer/next-compiler.ts +++ b/src/export/packer/next-compiler.ts @@ -44,7 +44,7 @@ export class Compiler { this.numberingReplacer = new NumberingReplacer(); } - public compile(file: File, prettifyXml?: PrettifyType): JSZip { + public compile(file: File, prettifyXml?: (typeof PrettifyType)[keyof typeof PrettifyType]): JSZip { const zip = new JSZip(); const xmlifiedFileMapping = this.xmlifyFile(file, prettifyXml); const map = new Map(Object.entries(xmlifiedFileMapping)); @@ -66,7 +66,7 @@ export class Compiler { return zip; } - private xmlifyFile(file: File, prettify?: PrettifyType): IXmlifyedFileMapping { + private xmlifyFile(file: File, prettify?: (typeof PrettifyType)[keyof typeof PrettifyType]): IXmlifyedFileMapping { const documentRelationshipCount = file.Document.Relationships.RelationshipCount + 1; const documentXmlData = xml( diff --git a/src/export/packer/packer.ts b/src/export/packer/packer.ts index fa8fac2b221..4f1bc534583 100644 --- a/src/export/packer/packer.ts +++ b/src/export/packer/packer.ts @@ -6,18 +6,21 @@ import { Compiler } from "./next-compiler"; /** * Use blanks to prettify */ -export enum PrettifyType { - NONE = "", - WITH_2_BLANKS = " ", - WITH_4_BLANKS = " ", - WITH_TAB = "\t", -} +export const PrettifyType = { + NONE: "", + WITH_2_BLANKS: " ", + WITH_4_BLANKS: " ", + // eslint-disable-next-line @typescript-eslint/naming-convention + WITH_TAB: "\t", +} as const; -const convertPrettifyType = (prettify?: boolean | PrettifyType): PrettifyType | undefined => +const convertPrettifyType = ( + prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType], +): (typeof PrettifyType)[keyof typeof PrettifyType] | undefined => prettify === true ? PrettifyType.WITH_2_BLANKS : prettify === false ? undefined : prettify; export class Packer { - public static async toString(file: File, prettify?: boolean | PrettifyType): Promise { + public static async toString(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Promise { const zip = this.compiler.compile(file, convertPrettifyType(prettify)); const zipData = await zip.generateAsync({ type: "string", @@ -28,7 +31,7 @@ export class Packer { return zipData; } - public static async toBuffer(file: File, prettify?: boolean | PrettifyType): Promise { + public static async toBuffer(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Promise { const zip = this.compiler.compile(file, convertPrettifyType(prettify)); const zipData = await zip.generateAsync({ type: "nodebuffer", @@ -39,7 +42,7 @@ export class Packer { return zipData; } - public static async toBase64String(file: File, prettify?: boolean | PrettifyType): Promise { + public static async toBase64String(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Promise { const zip = this.compiler.compile(file, convertPrettifyType(prettify)); const zipData = await zip.generateAsync({ type: "base64", @@ -50,7 +53,7 @@ export class Packer { return zipData; } - public static async toBlob(file: File, prettify?: boolean | PrettifyType): Promise { + public static async toBlob(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Promise { const zip = this.compiler.compile(file, convertPrettifyType(prettify)); const zipData = await zip.generateAsync({ type: "blob", @@ -61,7 +64,7 @@ export class Packer { return zipData; } - public static toStream(file: File, prettify?: boolean | PrettifyType): Stream { + public static toStream(file: File, prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]): Stream { const stream = new Stream(); const zip = this.compiler.compile(file, convertPrettifyType(prettify)); diff --git a/src/file/border/border.ts b/src/file/border/border.ts index 8b3d5e25ec4..5b76390af5b 100644 --- a/src/file/border/border.ts +++ b/src/file/border/border.ts @@ -23,7 +23,7 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components"; import { eighthPointMeasureValue, hexColorValue, pointMeasureValue } from "@util/values"; export interface IBorderOptions { - readonly style: BorderStyle; + readonly style: (typeof BorderStyle)[keyof typeof BorderStyle]; /** Border color, in hex (eg 'FF00AA') */ readonly color?: string; /** Size of the border in 1/8 pt */ @@ -55,32 +55,34 @@ class BordersAttributes extends XmlAttributeComponent { }; } -export enum BorderStyle { - SINGLE = "single", - DASH_DOT_STROKED = "dashDotStroked", - DASHED = "dashed", - DASH_SMALL_GAP = "dashSmallGap", - DOT_DASH = "dotDash", - DOT_DOT_DASH = "dotDotDash", - DOTTED = "dotted", - DOUBLE = "double", - DOUBLE_WAVE = "doubleWave", - INSET = "inset", - NIL = "nil", - NONE = "none", - OUTSET = "outset", - THICK = "thick", - THICK_THIN_LARGE_GAP = "thickThinLargeGap", - THICK_THIN_MEDIUM_GAP = "thickThinMediumGap", - THICK_THIN_SMALL_GAP = "thickThinSmallGap", - THIN_THICK_LARGE_GAP = "thinThickLargeGap", - THIN_THICK_MEDIUM_GAP = "thinThickMediumGap", - THIN_THICK_SMALL_GAP = "thinThickSmallGap", - THIN_THICK_THIN_LARGE_GAP = "thinThickThinLargeGap", - THIN_THICK_THIN_MEDIUM_GAP = "thinThickThinMediumGap", - THIN_THICK_THIN_SMALL_GAP = "thinThickThinSmallGap", - THREE_D_EMBOSS = "threeDEmboss", - THREE_D_ENGRAVE = "threeDEngrave", - TRIPLE = "triple", - WAVE = "wave", -} +/* eslint-disable @typescript-eslint/naming-convention */ +export const BorderStyle = { + SINGLE: "single", + DASH_DOT_STROKED: "dashDotStroked", + DASHED: "dashed", + DASH_SMALL_GAP: "dashSmallGap", + DOT_DASH: "dotDash", + DOT_DOT_DASH: "dotDotDash", + DOTTED: "dotted", + DOUBLE: "double", + DOUBLE_WAVE: "doubleWave", + INSET: "inset", + NIL: "nil", + NONE: "none", + OUTSET: "outset", + THICK: "thick", + THICK_THIN_LARGE_GAP: "thickThinLargeGap", + THICK_THIN_MEDIUM_GAP: "thickThinMediumGap", + THICK_THIN_SMALL_GAP: "thickThinSmallGap", + THIN_THICK_LARGE_GAP: "thinThickLargeGap", + THIN_THICK_MEDIUM_GAP: "thinThickMediumGap", + THIN_THICK_SMALL_GAP: "thinThickSmallGap", + THIN_THICK_THIN_LARGE_GAP: "thinThickThinLargeGap", + THIN_THICK_THIN_MEDIUM_GAP: "thinThickThinMediumGap", + THIN_THICK_THIN_SMALL_GAP: "thinThickThinSmallGap", + THREE_D_EMBOSS: "threeDEmboss", + THREE_D_ENGRAVE: "threeDEngrave", + TRIPLE: "triple", + WAVE: "wave", +} as const; +/* eslint-enable */ diff --git a/src/file/document/body/section-properties/properties/doc-grid.ts b/src/file/document/body/section-properties/properties/doc-grid.ts index 0ce1b2b2db3..e7ddbe6a775 100644 --- a/src/file/document/body/section-properties/properties/doc-grid.ts +++ b/src/file/document/body/section-properties/properties/doc-grid.ts @@ -17,14 +17,17 @@ import { decimalNumber } from "@util/values"; // // -export enum DocumentGridType { - DEFAULT = "default", - LINES = "lines", - LINES_AND_CHARS = "linesAndChars", - SNAP_TO_CHARS = "snapToChars", -} +/* eslint-disable @typescript-eslint/naming-convention */ +export const DocumentGridType = { + DEFAULT: "default", + LINES: "lines", + LINES_AND_CHARS: "linesAndChars", + SNAP_TO_CHARS: "snapToChars", +} as const; + +/* eslint-enable */ export interface IDocGridAttributesProperties { - readonly type?: DocumentGridType; + readonly type?: (typeof DocumentGridType)[keyof typeof DocumentGridType]; readonly linePitch?: number; readonly charSpace?: number; } @@ -38,7 +41,7 @@ export class DocGridAttributes extends XmlAttributeComponent // // -export enum HeaderFooterReferenceType { - DEFAULT = "default", - FIRST = "first", - EVEN = "even", -} +export const HeaderFooterReferenceType = { + DEFAULT: "default", + FIRST: "first", + EVEN: "even", +} as const; // // @@ -33,12 +33,12 @@ export enum HeaderFooterReferenceType { // export interface IHeaderFooterOptions { - readonly type?: HeaderFooterReferenceType; + readonly type?: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType]; readonly id?: number; } class FooterReferenceAttributes extends XmlAttributeComponent<{ - readonly type: HeaderFooterReferenceType; + readonly type: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType]; readonly id: string; }> { protected readonly xmlKeys = { @@ -47,12 +47,13 @@ class FooterReferenceAttributes extends XmlAttributeComponent<{ }; } -export enum HeaderFooterType { - HEADER = "w:headerReference", - FOOTER = "w:footerReference", -} +export const HeaderFooterType = { + HEADER: "w:headerReference", + FOOTER: "w:footerReference", +} as const; + export class HeaderFooterReference extends XmlComponent { - public constructor(type: HeaderFooterType, options: IHeaderFooterOptions) { + public constructor(type: (typeof HeaderFooterType)[keyof typeof HeaderFooterType], options: IHeaderFooterOptions) { super(type); this.root.push( diff --git a/src/file/document/body/section-properties/properties/line-number.ts b/src/file/document/body/section-properties/properties/line-number.ts index 845c7b70e11..380d9df2d57 100644 --- a/src/file/document/body/section-properties/properties/line-number.ts +++ b/src/file/document/body/section-properties/properties/line-number.ts @@ -9,11 +9,14 @@ import { decimalNumber, PositiveUniversalMeasure, twipsMeasureValue } from "@uti // // // -export enum LineNumberRestartFormat { - NEW_PAGE = "newPage", - NEW_SECTION = "newSection", - CONTINUOUS = "continuous", -} + +/* eslint-disable @typescript-eslint/naming-convention */ +export const LineNumberRestartFormat = { + NEW_PAGE: "newPage", + NEW_SECTION: "newSection", + CONTINUOUS: "continuous", +} as const; +/* eslint-enable */ // // @@ -25,7 +28,7 @@ export enum LineNumberRestartFormat { export interface ILineNumberAttributes { readonly countBy?: number; readonly start?: number; - readonly restart?: LineNumberRestartFormat; + readonly restart?: (typeof LineNumberRestartFormat)[keyof typeof LineNumberRestartFormat]; readonly distance?: number | PositiveUniversalMeasure; } @@ -36,13 +39,16 @@ export class LineNumberType extends XmlComponent { new NextAttributeComponent<{ readonly countBy?: number; readonly start?: number; - readonly restart?: LineNumberRestartFormat; + readonly restart?: (typeof LineNumberRestartFormat)[keyof typeof LineNumberRestartFormat]; readonly distance?: number | PositiveUniversalMeasure; }>({ countBy: { key: "w:countBy", value: countBy === undefined ? undefined : decimalNumber(countBy) }, start: { key: "w:start", value: start === undefined ? undefined : decimalNumber(start) }, restart: { key: "w:restart", value: restart }, - distance: { key: "w:distance", value: distance === undefined ? undefined : twipsMeasureValue(distance) }, + distance: { + key: "w:distance", + value: distance === undefined ? undefined : twipsMeasureValue(distance), + }, }), ); } diff --git a/src/file/document/body/section-properties/properties/page-borders.ts b/src/file/document/body/section-properties/properties/page-borders.ts index 894a805316a..e7fe557da57 100644 --- a/src/file/document/body/section-properties/properties/page-borders.ts +++ b/src/file/document/body/section-properties/properties/page-borders.ts @@ -9,11 +9,14 @@ import { IgnoreIfEmptyXmlComponent, XmlAttributeComponent } from "@file/xml-comp // // // -export enum PageBorderDisplay { - ALL_PAGES = "allPages", - FIRST_PAGE = "firstPage", - NOT_FIRST_PAGE = "notFirstPage", -} + +/* eslint-disable @typescript-eslint/naming-convention */ +export const PageBorderDisplay = { + ALL_PAGES: "allPages", + FIRST_PAGE: "firstPage", + NOT_FIRST_PAGE: "notFirstPage", +} as const; +/* eslint-enable */ // // @@ -21,10 +24,10 @@ export enum PageBorderDisplay { // // // -export enum PageBorderOffsetFrom { - PAGE = "page", - TEXT = "text", -} +export const PageBorderOffsetFrom = { + PAGE: "page", + TEXT: "text", +} as const; // // @@ -32,15 +35,15 @@ export enum PageBorderOffsetFrom { // // // -export enum PageBorderZOrder { - BACK = "back", - FRONT = "front", -} +export const PageBorderZOrder = { + BACK: "back", + FRONT: "front", +} as const; export interface IPageBorderAttributes { - readonly display?: PageBorderDisplay; - readonly offsetFrom?: PageBorderOffsetFrom; - readonly zOrder?: PageBorderZOrder; + readonly display?: (typeof PageBorderDisplay)[keyof typeof PageBorderDisplay]; + readonly offsetFrom?: (typeof PageBorderOffsetFrom)[keyof typeof PageBorderOffsetFrom]; + readonly zOrder?: (typeof PageBorderZOrder)[keyof typeof PageBorderZOrder]; } export interface IPageBordersOptions { diff --git a/src/file/document/body/section-properties/properties/page-number.ts b/src/file/document/body/section-properties/properties/page-number.ts index ac4dd138390..cf93ea13552 100644 --- a/src/file/document/body/section-properties/properties/page-number.ts +++ b/src/file/document/body/section-properties/properties/page-number.ts @@ -12,18 +12,22 @@ import { decimalNumber } from "@util/values"; // // // -export enum PageNumberSeparator { - HYPHEN = "hyphen", - PERIOD = "period", - COLON = "colon", - EM_DASH = "emDash", - EN_DASH = "endash", -} + +/* eslint-disable @typescript-eslint/naming-convention */ +export const PageNumberSeparator = { + HYPHEN: "hyphen", + PERIOD: "period", + COLON: "colon", + EM_DASH: "emDash", + EN_DASH: "endash", +} as const; + +/* eslint-enable */ export interface IPageNumberTypeAttributes { readonly start?: number; - readonly formatType?: NumberFormat; - readonly separator?: PageNumberSeparator; + readonly formatType?: (typeof NumberFormat)[keyof typeof NumberFormat]; + readonly separator?: (typeof PageNumberSeparator)[keyof typeof PageNumberSeparator]; } // @@ -40,6 +44,7 @@ export class PageNumberTypeAttributes extends XmlAttributeComponent // // -export enum PageOrientation { - PORTRAIT = "portrait", - LANDSCAPE = "landscape", -} +export const PageOrientation = { + PORTRAIT: "portrait", + LANDSCAPE: "landscape", +} as const; // // @@ -21,11 +21,15 @@ export enum PageOrientation { export type IPageSizeAttributes = { readonly width?: number | PositiveUniversalMeasure; readonly height?: number | PositiveUniversalMeasure; - readonly orientation?: PageOrientation; + readonly orientation?: (typeof PageOrientation)[keyof typeof PageOrientation]; }; export class PageSize extends XmlComponent { - public constructor(width: number | PositiveUniversalMeasure, height: number | PositiveUniversalMeasure, orientation: PageOrientation) { + public constructor( + width: number | PositiveUniversalMeasure, + height: number | PositiveUniversalMeasure, + orientation: (typeof PageOrientation)[keyof typeof PageOrientation], + ) { super("w:pgSz"); const flip = orientation === PageOrientation.LANDSCAPE; diff --git a/src/file/document/body/section-properties/properties/page-text-direction.ts b/src/file/document/body/section-properties/properties/page-text-direction.ts index 022401e97f8..b5b71c03da4 100644 --- a/src/file/document/body/section-properties/properties/page-text-direction.ts +++ b/src/file/document/body/section-properties/properties/page-text-direction.ts @@ -1,16 +1,21 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components"; -export enum PageTextDirectionType { - LEFT_TO_RIGHT_TOP_TO_BOTTOM = "lrTb", - TOP_TO_BOTTOM_RIGHT_TO_LEFT = "tbRl", -} +/* eslint-disable @typescript-eslint/naming-convention */ +export const PageTextDirectionType = { + LEFT_TO_RIGHT_TOP_TO_BOTTOM: "lrTb", + TOP_TO_BOTTOM_RIGHT_TO_LEFT: "tbRl", +} as const; + +/* eslint-enable */ -class PageTextDirectionAttributes extends XmlAttributeComponent<{ readonly val: PageTextDirectionType }> { +class PageTextDirectionAttributes extends XmlAttributeComponent<{ + readonly val: (typeof PageTextDirectionType)[keyof typeof PageTextDirectionType]; +}> { protected readonly xmlKeys = { val: "w:val" }; } export class PageTextDirection extends XmlComponent { - public constructor(value: PageTextDirectionType) { + public constructor(value: (typeof PageTextDirectionType)[keyof typeof PageTextDirectionType]) { super("w:textDirection"); this.root.push( diff --git a/src/file/document/body/section-properties/properties/section-type.ts b/src/file/document/body/section-properties/properties/section-type.ts index a6dd8ddae4d..4b3a5ea6a95 100644 --- a/src/file/document/body/section-properties/properties/section-type.ts +++ b/src/file/document/body/section-properties/properties/section-type.ts @@ -10,19 +10,22 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components"; // // // -export enum SectionType { - NEXT_PAGE = "nextPage", - NEXT_COLUMN = "nextColumn", - CONTINUOUS = "continuous", - EVEN_PAGE = "evenPage", - ODD_PAGE = "oddPage", -} + +/* eslint-disable @typescript-eslint/naming-convention */ +export const SectionType = { + NEXT_PAGE: "nextPage", + NEXT_COLUMN: "nextColumn", + CONTINUOUS: "continuous", + EVEN_PAGE: "evenPage", + ODD_PAGE: "oddPage", +} as const; +/* eslint-enable */ // // // export class SectionTypeAttributes extends XmlAttributeComponent<{ - readonly val: SectionType; + readonly val: (typeof SectionType)[keyof typeof SectionType]; }> { protected readonly xmlKeys = { val: "w:val", @@ -30,7 +33,7 @@ export class SectionTypeAttributes extends XmlAttributeComponent<{ } export class Type extends XmlComponent { - public constructor(value: SectionType) { + public constructor(value: (typeof SectionType)[keyof typeof SectionType]) { super("w:type"); this.root.push(new SectionTypeAttributes({ val: value })); } diff --git a/src/file/document/body/section-properties/section-properties.ts b/src/file/document/body/section-properties/section-properties.ts index c6364dc6095..1f66fbe0253 100644 --- a/src/file/document/body/section-properties/section-properties.ts +++ b/src/file/document/body/section-properties/section-properties.ts @@ -29,16 +29,16 @@ export interface ISectionPropertiesOptions { readonly margin?: IPageMarginAttributes; readonly pageNumbers?: IPageNumberTypeAttributes; readonly borders?: IPageBordersOptions; - readonly textDirection?: PageTextDirectionType; + readonly textDirection?: (typeof PageTextDirectionType)[keyof typeof PageTextDirectionType]; }; readonly grid?: IDocGridAttributesProperties; readonly headerWrapperGroup?: IHeaderFooterGroup; readonly footerWrapperGroup?: IHeaderFooterGroup; readonly lineNumbers?: ILineNumberAttributes; readonly titlePage?: boolean; - readonly verticalAlign?: VerticalAlign; + readonly verticalAlign?: (typeof VerticalAlign)[keyof typeof VerticalAlign]; readonly column?: IColumnsAttributes; - readonly type?: SectionType; + readonly type?: (typeof SectionType)[keyof typeof SectionType]; } // @@ -162,7 +162,7 @@ export class SectionProperties extends XmlComponent { } private addHeaderFooterGroup( - type: HeaderFooterType, + type: (typeof HeaderFooterType)[keyof typeof HeaderFooterType], group: IHeaderFooterGroup | IHeaderFooterGroup, ): void { if (group.default) { diff --git a/src/file/drawing/floating/align.ts b/src/file/drawing/floating/align.ts index a541293f5cd..4a2cf0bcd7d 100644 --- a/src/file/drawing/floating/align.ts +++ b/src/file/drawing/floating/align.ts @@ -3,7 +3,11 @@ import { HorizontalPositionAlign, VerticalPositionAlign } from "@file/shared/ali import { XmlComponent } from "@file/xml-components"; export class Align extends XmlComponent { - public constructor(value: HorizontalPositionAlign | VerticalPositionAlign) { + public constructor( + value: + | (typeof HorizontalPositionAlign)[keyof typeof HorizontalPositionAlign] + | (typeof VerticalPositionAlign)[keyof typeof VerticalPositionAlign], + ) { super("wp:align"); this.root.push(value); } diff --git a/src/file/drawing/floating/floating-position.ts b/src/file/drawing/floating/floating-position.ts index e2c97b601b7..9d3cf27397b 100644 --- a/src/file/drawing/floating/floating-position.ts +++ b/src/file/drawing/floating/floating-position.ts @@ -4,37 +4,39 @@ import { HorizontalPositionAlign, VerticalPositionAlign } from "@file/shared/ali import { ITextWrapping } from "../text-wrap"; -export enum HorizontalPositionRelativeFrom { - CHARACTER = "character", - COLUMN = "column", - INSIDE_MARGIN = "insideMargin", - LEFT_MARGIN = "leftMargin", - MARGIN = "margin", - OUTSIDE_MARGIN = "outsideMargin", - PAGE = "page", - RIGHT_MARGIN = "rightMargin", -} +/* eslint-disable @typescript-eslint/naming-convention */ +export const HorizontalPositionRelativeFrom = { + CHARACTER: "character", + COLUMN: "column", + INSIDE_MARGIN: "insideMargin", + LEFT_MARGIN: "leftMargin", + MARGIN: "margin", + OUTSIDE_MARGIN: "outsideMargin", + PAGE: "page", + RIGHT_MARGIN: "rightMargin", +} as const; -export enum VerticalPositionRelativeFrom { - BOTTOM_MARGIN = "bottomMargin", - INSIDE_MARGIN = "insideMargin", - LINE = "line", - MARGIN = "margin", - OUTSIDE_MARGIN = "outsideMargin", - PAGE = "page", - PARAGRAPH = "paragraph", - TOP_MARGIN = "topMargin", -} +export const VerticalPositionRelativeFrom = { + BOTTOM_MARGIN: "bottomMargin", + INSIDE_MARGIN: "insideMargin", + LINE: "line", + MARGIN: "margin", + OUTSIDE_MARGIN: "outsideMargin", + PAGE: "page", + PARAGRAPH: "paragraph", + TOP_MARGIN: "topMargin", +} as const; +/* eslint-enable */ export interface IHorizontalPositionOptions { - readonly relative?: HorizontalPositionRelativeFrom; - readonly align?: HorizontalPositionAlign; + readonly relative?: (typeof HorizontalPositionRelativeFrom)[keyof typeof HorizontalPositionRelativeFrom]; + readonly align?: (typeof HorizontalPositionAlign)[keyof typeof HorizontalPositionAlign]; readonly offset?: number; } export interface IVerticalPositionOptions { - readonly relative?: VerticalPositionRelativeFrom; - readonly align?: VerticalPositionAlign; + readonly relative?: (typeof VerticalPositionRelativeFrom)[keyof typeof VerticalPositionRelativeFrom]; + readonly align?: (typeof VerticalPositionAlign)[keyof typeof VerticalPositionAlign]; readonly offset?: number; } diff --git a/src/file/drawing/floating/horizontal-position.ts b/src/file/drawing/floating/horizontal-position.ts index eb2ccd3c56f..10b36ba7789 100644 --- a/src/file/drawing/floating/horizontal-position.ts +++ b/src/file/drawing/floating/horizontal-position.ts @@ -5,7 +5,7 @@ import { HorizontalPositionRelativeFrom, IHorizontalPositionOptions } from "./fl import { PositionOffset } from "./position-offset"; class HorizontalPositionAttributes extends XmlAttributeComponent<{ - readonly relativeFrom: HorizontalPositionRelativeFrom; + readonly relativeFrom: (typeof HorizontalPositionRelativeFrom)[keyof typeof HorizontalPositionRelativeFrom]; }> { protected readonly xmlKeys = { relativeFrom: "relativeFrom", diff --git a/src/file/drawing/floating/vertical-position.ts b/src/file/drawing/floating/vertical-position.ts index d8a30729b1b..01e41344533 100644 --- a/src/file/drawing/floating/vertical-position.ts +++ b/src/file/drawing/floating/vertical-position.ts @@ -5,7 +5,7 @@ import { IVerticalPositionOptions, VerticalPositionRelativeFrom } from "./floati import { PositionOffset } from "./position-offset"; class VerticalPositionAttributes extends XmlAttributeComponent<{ - readonly relativeFrom: VerticalPositionRelativeFrom; + readonly relativeFrom: (typeof VerticalPositionRelativeFrom)[keyof typeof VerticalPositionRelativeFrom]; }> { protected readonly xmlKeys = { relativeFrom: "relativeFrom", diff --git a/src/file/drawing/text-wrap/text-wrapping.ts b/src/file/drawing/text-wrap/text-wrapping.ts index 1bc68e7252e..9ea1f200386 100644 --- a/src/file/drawing/text-wrap/text-wrapping.ts +++ b/src/file/drawing/text-wrap/text-wrapping.ts @@ -1,22 +1,25 @@ // http://officeopenxml.com/drwPicFloating-textWrap.php import { IDistance } from "../drawing"; -export enum TextWrappingType { - NONE, - SQUARE, - TIGHT, - TOP_AND_BOTTOM, -} +/* eslint-disable @typescript-eslint/naming-convention */ +export const TextWrappingType = { + NONE: 0, + SQUARE: 1, + TIGHT: 2, + TOP_AND_BOTTOM: 3, +} as const; -export enum TextWrappingSide { - BOTH_SIDES = "bothSides", - LEFT = "left", - RIGHT = "right", - LARGEST = "largest", -} +export const TextWrappingSide = { + BOTH_SIDES: "bothSides", + LEFT: "left", + RIGHT: "right", + LARGEST: "largest", +} as const; + +/* eslint-enable */ export interface ITextWrapping { - readonly type: TextWrappingType; - readonly side?: TextWrappingSide; + readonly type: (typeof TextWrappingType)[keyof typeof TextWrappingType]; + readonly side?: (typeof TextWrappingSide)[keyof typeof TextWrappingSide]; readonly margins?: IDistance; } diff --git a/src/file/drawing/text-wrap/wrap-square.ts b/src/file/drawing/text-wrap/wrap-square.ts index b805ae4d550..3f0b7d3907c 100644 --- a/src/file/drawing/text-wrap/wrap-square.ts +++ b/src/file/drawing/text-wrap/wrap-square.ts @@ -6,7 +6,7 @@ import { IMargins } from "../floating"; import { ITextWrapping, TextWrappingSide } from "./text-wrapping"; interface IWrapSquareAttributes extends IDistance { - readonly wrapText?: TextWrappingSide; + readonly wrapText?: (typeof TextWrappingSide)[keyof typeof TextWrappingSide]; } class WrapSquareAttributes extends XmlAttributeComponent { diff --git a/src/file/file.ts b/src/file/file.ts index c01c7aa82df..136380be9fd 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -154,7 +154,10 @@ export class File { return wrapper; } - private addHeaderToDocument(header: HeaderWrapper, type: HeaderFooterReferenceType = HeaderFooterReferenceType.DEFAULT): void { + private addHeaderToDocument( + header: HeaderWrapper, + type: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType] = HeaderFooterReferenceType.DEFAULT, + ): void { // eslint-disable-next-line functional/immutable-data this.headers.push({ header, type }); this.documentWrapper.Relationships.createRelationship( @@ -165,7 +168,10 @@ export class File { this.contentTypes.addHeader(this.headers.length); } - private addFooterToDocument(footer: FooterWrapper, type: HeaderFooterReferenceType = HeaderFooterReferenceType.DEFAULT): void { + private addFooterToDocument( + footer: FooterWrapper, + type: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType] = HeaderFooterReferenceType.DEFAULT, + ): void { // eslint-disable-next-line functional/immutable-data this.footers.push({ footer, type }); this.documentWrapper.Relationships.createRelationship( diff --git a/src/file/footer-wrapper.ts b/src/file/footer-wrapper.ts index ff026455d45..8b4958ad5f6 100644 --- a/src/file/footer-wrapper.ts +++ b/src/file/footer-wrapper.ts @@ -10,7 +10,7 @@ import { Table } from "./table"; export interface IDocumentFooter { readonly footer: FooterWrapper; - readonly type: HeaderFooterReferenceType; + readonly type: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType]; } export class FooterWrapper implements IViewWrapper { diff --git a/src/file/footnotes/footnote/footnote.ts b/src/file/footnotes/footnote/footnote.ts index a2983e02116..fc87a3013bf 100644 --- a/src/file/footnotes/footnote/footnote.ts +++ b/src/file/footnotes/footnote/footnote.ts @@ -4,14 +4,15 @@ import { XmlComponent } from "@file/xml-components"; import { FootnoteAttributes } from "./footnote-attributes"; import { FootnoteRefRun } from "./run/footnote-ref-run"; -export enum FootnoteType { - SEPERATOR = "separator", - CONTINUATION_SEPERATOR = "continuationSeparator", -} +export const FootnoteType = { + SEPERATOR: "separator", + // eslint-disable-next-line @typescript-eslint/naming-convention + CONTINUATION_SEPERATOR: "continuationSeparator", +} as const; export interface IFootnoteOptions { readonly id: number; - readonly type?: FootnoteType; + readonly type?: (typeof FootnoteType)[keyof typeof FootnoteType]; readonly children: readonly Paragraph[]; } diff --git a/src/file/header-wrapper.ts b/src/file/header-wrapper.ts index 68f08ad0064..fc7d824f0f5 100644 --- a/src/file/header-wrapper.ts +++ b/src/file/header-wrapper.ts @@ -10,7 +10,7 @@ import { Table } from "./table"; export interface IDocumentHeader { readonly header: HeaderWrapper; - readonly type: HeaderFooterReferenceType; + readonly type: (typeof HeaderFooterReferenceType)[keyof typeof HeaderFooterReferenceType]; } export class HeaderWrapper implements IViewWrapper { diff --git a/src/file/numbering/level.ts b/src/file/numbering/level.ts index e053c6c79b2..fb0040f609e 100644 --- a/src/file/numbering/level.ts +++ b/src/file/numbering/level.ts @@ -75,71 +75,75 @@ import { IRunStylePropertiesOptions, RunProperties } from "../paragraph/run/prop // // // -export enum LevelFormat { - DECIMAL = "decimal", - UPPER_ROMAN = "upperRoman", - LOWER_ROMAN = "lowerRoman", - UPPER_LETTER = "upperLetter", - LOWER_LETTER = "lowerLetter", - ORDINAL = "ordinal", - CARDINAL_TEXT = "cardinalText", - ORDINAL_TEXT = "ordinalText", - HEX = "hex", - CHICAGO = "chicago", - IDEOGRAPH__DIGITAL = "ideographDigital", - JAPANESE_COUNTING = "japaneseCounting", - AIUEO = "aiueo", - IROHA = "iroha", - DECIMAL_FULL_WIDTH = "decimalFullWidth", - DECIMAL_HALF_WIDTH = "decimalHalfWidth", - JAPANESE_LEGAL = "japaneseLegal", - JAPANESE_DIGITAL_TEN_THOUSAND = "japaneseDigitalTenThousand", - DECIMAL_ENCLOSED_CIRCLE = "decimalEnclosedCircle", - DECIMAL_FULL_WIDTH2 = "decimalFullWidth2", - AIUEO_FULL_WIDTH = "aiueoFullWidth", - IROHA_FULL_WIDTH = "irohaFullWidth", - DECIMAL_ZERO = "decimalZero", - BULLET = "bullet", - GANADA = "ganada", - CHOSUNG = "chosung", - DECIMAL_ENCLOSED_FULLSTOP = "decimalEnclosedFullstop", - DECIMAL_ENCLOSED_PARENTHESES = "decimalEnclosedParen", - DECIMAL_ENCLOSED_CIRCLE_CHINESE = "decimalEnclosedCircleChinese", - IDEOGRAPH_ENCLOSED_CIRCLE = "ideographEnclosedCircle", - IDEOGRAPH_TRADITIONAL = "ideographTraditional", - IDEOGRAPH_ZODIAC = "ideographZodiac", - IDEOGRAPH_ZODIAC_TRADITIONAL = "ideographZodiacTraditional", - TAIWANESE_COUNTING = "taiwaneseCounting", - IDEOGRAPH_LEGAL_TRADITIONAL = "ideographLegalTraditional", - TAIWANESE_COUNTING_THOUSAND = "taiwaneseCountingThousand", - TAIWANESE_DIGITAL = "taiwaneseDigital", - CHINESE_COUNTING = "chineseCounting", - CHINESE_LEGAL_SIMPLIFIED = "chineseLegalSimplified", - CHINESE_COUNTING_THOUSAND = "chineseCountingThousand", - KOREAN_DIGITAL = "koreanDigital", - KOREAN_COUNTING = "koreanCounting", - KOREAN_LEGAL = "koreanLegal", - KOREAN_DIGITAL2 = "koreanDigital2", - VIETNAMESE_COUNTING = "vietnameseCounting", - RUSSIAN_LOWER = "russianLower", - RUSSIAN_UPPER = "russianUpper", - NONE = "none", - NUMBER_IN_DASH = "numberInDash", - HEBREW1 = "hebrew1", - HEBREW2 = "hebrew2", - ARABIC_ALPHA = "arabicAlpha", - ARABIC_ABJAD = "arabicAbjad", - HINDI_VOWELS = "hindiVowels", - HINDI_CONSONANTS = "hindiConsonants", - HINDI_NUMBERS = "hindiNumbers", - HINDI_COUNTING = "hindiCounting", - THAI_LETTERS = "thaiLetters", - THAI_NUMBERS = "thaiNumbers", - THAI_COUNTING = "thaiCounting", - BAHT_TEXT = "bahtText", - DOLLAR_TEXT = "dollarText", - CUSTOM = "custom", -} + +/* eslint-disable @typescript-eslint/naming-convention */ +export const LevelFormat = { + DECIMAL: "decimal", + UPPER_ROMAN: "upperRoman", + LOWER_ROMAN: "lowerRoman", + UPPER_LETTER: "upperLetter", + LOWER_LETTER: "lowerLetter", + ORDINAL: "ordinal", + CARDINAL_TEXT: "cardinalText", + ORDINAL_TEXT: "ordinalText", + HEX: "hex", + CHICAGO: "chicago", + IDEOGRAPH__DIGITAL: "ideographDigital", + JAPANESE_COUNTING: "japaneseCounting", + AIUEO: "aiueo", + IROHA: "iroha", + DECIMAL_FULL_WIDTH: "decimalFullWidth", + DECIMAL_HALF_WIDTH: "decimalHalfWidth", + JAPANESE_LEGAL: "japaneseLegal", + JAPANESE_DIGITAL_TEN_THOUSAND: "japaneseDigitalTenThousand", + DECIMAL_ENCLOSED_CIRCLE: "decimalEnclosedCircle", + DECIMAL_FULL_WIDTH2: "decimalFullWidth2", + AIUEO_FULL_WIDTH: "aiueoFullWidth", + IROHA_FULL_WIDTH: "irohaFullWidth", + DECIMAL_ZERO: "decimalZero", + BULLET: "bullet", + GANADA: "ganada", + CHOSUNG: "chosung", + DECIMAL_ENCLOSED_FULLSTOP: "decimalEnclosedFullstop", + DECIMAL_ENCLOSED_PARENTHESES: "decimalEnclosedParen", + DECIMAL_ENCLOSED_CIRCLE_CHINESE: "decimalEnclosedCircleChinese", + IDEOGRAPH_ENCLOSED_CIRCLE: "ideographEnclosedCircle", + IDEOGRAPH_TRADITIONAL: "ideographTraditional", + IDEOGRAPH_ZODIAC: "ideographZodiac", + IDEOGRAPH_ZODIAC_TRADITIONAL: "ideographZodiacTraditional", + TAIWANESE_COUNTING: "taiwaneseCounting", + IDEOGRAPH_LEGAL_TRADITIONAL: "ideographLegalTraditional", + TAIWANESE_COUNTING_THOUSAND: "taiwaneseCountingThousand", + TAIWANESE_DIGITAL: "taiwaneseDigital", + CHINESE_COUNTING: "chineseCounting", + CHINESE_LEGAL_SIMPLIFIED: "chineseLegalSimplified", + CHINESE_COUNTING_THOUSAND: "chineseCountingThousand", + KOREAN_DIGITAL: "koreanDigital", + KOREAN_COUNTING: "koreanCounting", + KOREAN_LEGAL: "koreanLegal", + KOREAN_DIGITAL2: "koreanDigital2", + VIETNAMESE_COUNTING: "vietnameseCounting", + RUSSIAN_LOWER: "russianLower", + RUSSIAN_UPPER: "russianUpper", + NONE: "none", + NUMBER_IN_DASH: "numberInDash", + HEBREW1: "hebrew1", + HEBREW2: "hebrew2", + ARABIC_ALPHA: "arabicAlpha", + ARABIC_ABJAD: "arabicAbjad", + HINDI_VOWELS: "hindiVowels", + HINDI_CONSONANTS: "hindiConsonants", + HINDI_NUMBERS: "hindiNumbers", + HINDI_COUNTING: "hindiCounting", + THAI_LETTERS: "thaiLetters", + THAI_NUMBERS: "thaiNumbers", + THAI_COUNTING: "thaiCounting", + BAHT_TEXT: "bahtText", + DOLLAR_TEXT: "dollarText", + CUSTOM: "custom", +} as const; + +/* eslint-enable */ class LevelAttributes extends XmlAttributeComponent<{ readonly ilvl?: number; @@ -182,7 +186,7 @@ class LevelText extends XmlComponent { } class LevelJc extends XmlComponent { - public constructor(value: AlignmentType) { + public constructor(value: (typeof AlignmentType)[keyof typeof AlignmentType]) { super("w:lvlJc"); this.root.push( new Attributes({ @@ -192,19 +196,19 @@ class LevelJc extends XmlComponent { } } -export enum LevelSuffix { - NOTHING = "nothing", - SPACE = "space", - TAB = "tab", -} +export const LevelSuffix = { + NOTHING: "nothing", + SPACE: "space", + TAB: "tab", +} as const; export interface ILevelsOptions { readonly level: number; - readonly format?: LevelFormat; + readonly format?: (typeof LevelFormat)[keyof typeof LevelFormat]; readonly text?: string; - readonly alignment?: AlignmentType; + readonly alignment?: (typeof AlignmentType)[keyof typeof AlignmentType]; readonly start?: number; - readonly suffix?: LevelSuffix; + readonly suffix?: (typeof LevelSuffix)[keyof typeof LevelSuffix]; readonly isLegalNumberingStyle?: boolean; readonly style?: { readonly run?: IRunStylePropertiesOptions; @@ -223,7 +227,7 @@ export interface ILevelsOptions { // // class Suffix extends XmlComponent { - public constructor(value: LevelSuffix) { + public constructor(value: (typeof LevelSuffix)[keyof typeof LevelSuffix]) { super("w:suff"); this.root.push( new Attributes({ diff --git a/src/file/paragraph/formatting/alignment.ts b/src/file/paragraph/formatting/alignment.ts index 05b4f2a6d37..cfd9f8fbaac 100644 --- a/src/file/paragraph/formatting/alignment.ts +++ b/src/file/paragraph/formatting/alignment.ts @@ -19,41 +19,47 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components"; // // // -export enum AlignmentType { + +/* eslint-disable @typescript-eslint/naming-convention */ +export const AlignmentType = { /** Align Start */ - START = "start", + START: "start", /** Align Center */ - CENTER = "center", + CENTER: "center", /** End */ - END = "end", + END: "end", /** Justified */ - BOTH = "both", + BOTH: "both", /** Medium Kashida Length */ - MEDIUM_KASHIDA = "mediumKashida", + MEDIUM_KASHIDA: "mediumKashida", /** Distribute All Characters Equally */ - DISTRIBUTE = "distribute", + DISTRIBUTE: "distribute", /** Align to List Tab */ - NUM_TAB = "numTab", + NUM_TAB: "numTab", /** Widest Kashida Length */ - HIGH_KASHIDA = "highKashida", + HIGH_KASHIDA: "highKashida", /** Low Kashida Length */ - LOW_KASHIDA = "lowKashida", + LOW_KASHIDA: "lowKashida", /** Thai Language Justification */ - THAI_DISTRIBUTE = "thaiDistribute", + THAI_DISTRIBUTE: "thaiDistribute", /** Align Left */ - LEFT = "left", + LEFT: "left", /** Align Right */ - RIGHT = "right", + RIGHT: "right", /** Justified */ - JUSTIFIED = "both", -} + JUSTIFIED: "both", +} as const; + +/* eslint-enable */ -export class AlignmentAttributes extends XmlAttributeComponent<{ readonly val: AlignmentType }> { +export class AlignmentAttributes extends XmlAttributeComponent<{ + readonly val: (typeof AlignmentType)[keyof typeof AlignmentType]; +}> { protected readonly xmlKeys = { val: "w:val" }; } export class Alignment extends XmlComponent { - public constructor(type: AlignmentType) { + public constructor(type: (typeof AlignmentType)[keyof typeof AlignmentType]) { super("w:jc"); this.root.push(new AlignmentAttributes({ val: type })); } diff --git a/src/file/paragraph/formatting/break.ts b/src/file/paragraph/formatting/break.ts index 8319407a6c8..b972ed99708 100644 --- a/src/file/paragraph/formatting/break.ts +++ b/src/file/paragraph/formatting/break.ts @@ -2,14 +2,14 @@ import { Attributes, XmlComponent } from "@file/xml-components"; import { Run } from "../run"; -enum BreakType { - COLUMN = "column", - PAGE = "page", +const BreakType = { + COLUMN: "column", + PAGE: "page", // textWrapping breaks are the default and already exposed via the "Run" class -} +} as const; class Break extends XmlComponent { - public constructor(type: BreakType) { + public constructor(type: (typeof BreakType)[keyof typeof BreakType]) { super("w:br"); this.root.push( new Attributes({ diff --git a/src/file/paragraph/formatting/spacing.ts b/src/file/paragraph/formatting/spacing.ts index 1d9c0f080cd..6404f4e9749 100644 --- a/src/file/paragraph/formatting/spacing.ts +++ b/src/file/paragraph/formatting/spacing.ts @@ -1,17 +1,19 @@ // http://officeopenxml.com/WPspacing.php import { XmlAttributeComponent, XmlComponent } from "@file/xml-components"; -export enum LineRuleType { - AT_LEAST = "atLeast", - EXACTLY = "exactly", - EXACT = "exact", - AUTO = "auto", -} +export const LineRuleType = { + // eslint-disable-next-line @typescript-eslint/naming-convention + AT_LEAST: "atLeast", + EXACTLY: "exactly", + EXACT: "exact", + AUTO: "auto", +} as const; + export interface ISpacingProperties { readonly after?: number; readonly before?: number; readonly line?: number; - readonly lineRule?: LineRuleType; + readonly lineRule?: (typeof LineRuleType)[keyof typeof LineRuleType]; readonly beforeAutoSpacing?: boolean; readonly afterAutoSpacing?: boolean; } diff --git a/src/file/paragraph/formatting/style.ts b/src/file/paragraph/formatting/style.ts index d571ae97293..f182e4a0973 100644 --- a/src/file/paragraph/formatting/style.ts +++ b/src/file/paragraph/formatting/style.ts @@ -1,14 +1,14 @@ import { Attributes, XmlComponent } from "@file/xml-components"; -export enum HeadingLevel { - HEADING_1 = "Heading1", - HEADING_2 = "Heading2", - HEADING_3 = "Heading3", - HEADING_4 = "Heading4", - HEADING_5 = "Heading5", - HEADING_6 = "Heading6", - TITLE = "Title", -} +export const HeadingLevel = { + HEADING_1: "Heading1", + HEADING_2: "Heading2", + HEADING_3: "Heading3", + HEADING_4: "Heading4", + HEADING_5: "Heading5", + HEADING_6: "Heading6", + TITLE: "Title", +} as const; export class Style extends XmlComponent { public constructor(styleId: string) { diff --git a/src/file/paragraph/formatting/tab-stop.ts b/src/file/paragraph/formatting/tab-stop.ts index 3d7b81474fe..20e7ec841c9 100644 --- a/src/file/paragraph/formatting/tab-stop.ts +++ b/src/file/paragraph/formatting/tab-stop.ts @@ -2,9 +2,9 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components"; export interface TabStopDefinition { - readonly type: TabStopType; - readonly position: number | TabStopPosition; - readonly leader?: LeaderType; + readonly type: (typeof TabStopType)[keyof typeof TabStopType]; + readonly position: number | (typeof TabStopPosition)[keyof typeof TabStopPosition]; + readonly leader?: (typeof LeaderType)[keyof typeof LeaderType]; } export class TabStop extends XmlComponent { @@ -17,34 +17,35 @@ export class TabStop extends XmlComponent { } } -export enum TabStopType { - LEFT = "left", - RIGHT = "right", - CENTER = "center", - BAR = "bar", - CLEAR = "clear", - DECIMAL = "decimal", - END = "end", - NUM = "num", - START = "start", -} +export const TabStopType = { + LEFT: "left", + RIGHT: "right", + CENTER: "center", + BAR: "bar", + CLEAR: "clear", + DECIMAL: "decimal", + END: "end", + NUM: "num", + START: "start", +} as const; -export enum LeaderType { - DOT = "dot", - HYPHEN = "hyphen", - MIDDLE_DOT = "middleDot", - NONE = "none", - UNDERSCORE = "underscore", -} +export const LeaderType = { + DOT: "dot", + HYPHEN: "hyphen", + // eslint-disable-next-line @typescript-eslint/naming-convention + MIDDLE_DOT: "middleDot", + NONE: "none", + UNDERSCORE: "underscore", +} as const; -export enum TabStopPosition { - MAX = 9026, -} +export const TabStopPosition = { + MAX: 9026, +} as const; export class TabAttributes extends XmlAttributeComponent<{ - readonly val: TabStopType; + readonly val: (typeof TabStopType)[keyof typeof TabStopType]; readonly pos: string | number; - readonly leader?: LeaderType; + readonly leader?: (typeof LeaderType)[keyof typeof LeaderType]; }> { protected readonly xmlKeys = { val: "w:val", pos: "w:pos", leader: "w:leader" }; } diff --git a/src/file/paragraph/frame/frame-properties.ts b/src/file/paragraph/frame/frame-properties.ts index 76fa712d70d..28ce7c28611 100644 --- a/src/file/paragraph/frame/frame-properties.ts +++ b/src/file/paragraph/frame/frame-properties.ts @@ -3,43 +3,44 @@ import { HorizontalPositionAlign, VerticalPositionAlign } from "@file/shared/ali import { HeightRule } from "@file/table"; import { XmlAttributeComponent, XmlComponent } from "@file/xml-components"; -export enum DropCapType { - NONE = "none", - DROP = "drop", - MARGIN = "margin", -} +export const DropCapType = { + NONE: "none", + DROP: "drop", + MARGIN: "margin", +} as const; -export enum FrameAnchorType { - MARGIN = "margin", - PAGE = "page", - TEXT = "text", -} +export const FrameAnchorType = { + MARGIN: "margin", + PAGE: "page", + TEXT: "text", +} as const; -export enum FrameWrap { - AROUND = "around", - AUTO = "auto", - NONE = "none", - NOT_BESIDE = "notBeside", - THROUGH = "through", - TIGHT = "tight", -} +export const FrameWrap = { + AROUND: "around", + AUTO: "auto", + NONE: "none", + // eslint-disable-next-line @typescript-eslint/naming-convention + NOT_BESIDE: "notBeside", + THROUGH: "through", + TIGHT: "tight", +} as const; interface IBaseFrameOptions { readonly anchorLock?: boolean; - readonly dropCap?: DropCapType; + readonly dropCap?: (typeof DropCapType)[keyof typeof DropCapType]; readonly width: number; readonly height: number; - readonly wrap?: FrameWrap; + readonly wrap?: (typeof FrameWrap)[keyof typeof FrameWrap]; readonly lines?: number; readonly anchor: { - readonly horizontal: FrameAnchorType; - readonly vertical: FrameAnchorType; + readonly horizontal: (typeof FrameAnchorType)[keyof typeof FrameAnchorType]; + readonly vertical: (typeof FrameAnchorType)[keyof typeof FrameAnchorType]; }; readonly space?: { readonly horizontal: number; readonly vertical: number; }; - readonly rule?: HeightRule; + readonly rule?: (typeof HeightRule)[keyof typeof HeightRule]; } export interface IXYFrameOptions extends IBaseFrameOptions { @@ -51,8 +52,8 @@ export interface IXYFrameOptions extends IBaseFrameOptions { export interface IAlignmentFrameOptions extends IBaseFrameOptions { readonly alignment: { - readonly x: HorizontalPositionAlign; - readonly y: VerticalPositionAlign; + readonly x: (typeof HorizontalPositionAlign)[keyof typeof HorizontalPositionAlign]; + readonly y: (typeof VerticalPositionAlign)[keyof typeof VerticalPositionAlign]; }; } @@ -62,20 +63,20 @@ export type IFrameOptions = IXYFrameOptions | IAlignmentFrameOptions; export class FramePropertiesAttributes extends XmlAttributeComponent<{ readonly anchorLock?: boolean; - readonly dropCap?: DropCapType; + readonly dropCap?: (typeof DropCapType)[keyof typeof DropCapType]; readonly width: number; readonly height: number; readonly x?: number; readonly y?: number; - readonly wrap?: FrameWrap; + readonly wrap?: (typeof FrameWrap)[keyof typeof FrameWrap]; readonly lines?: number; - readonly anchorHorizontal?: FrameAnchorType; - readonly anchorVertical?: FrameAnchorType; + readonly anchorHorizontal?: (typeof FrameAnchorType)[keyof typeof FrameAnchorType]; + readonly anchorVertical?: (typeof FrameAnchorType)[keyof typeof FrameAnchorType]; readonly spaceHorizontal?: number; readonly spaceVertical?: number; - readonly rule?: HeightRule; - readonly alignmentX?: HorizontalPositionAlign; - readonly alignmentY?: VerticalPositionAlign; + readonly rule?: (typeof HeightRule)[keyof typeof HeightRule]; + readonly alignmentX?: (typeof HorizontalPositionAlign)[keyof typeof HorizontalPositionAlign]; + readonly alignmentY?: (typeof VerticalPositionAlign)[keyof typeof VerticalPositionAlign]; }> { protected readonly xmlKeys = { anchorLock: "w:anchorLock", diff --git a/src/file/paragraph/links/hyperlink.ts b/src/file/paragraph/links/hyperlink.ts index 18380fb805c..2fda81f12df 100644 --- a/src/file/paragraph/links/hyperlink.ts +++ b/src/file/paragraph/links/hyperlink.ts @@ -5,10 +5,10 @@ import { uniqueId } from "@util/convenience-functions"; import { ParagraphChild } from "../paragraph"; import { HyperlinkAttributes, IHyperlinkAttributesProperties } from "./hyperlink-attributes"; -export enum HyperlinkType { - INTERNAL = "INTERNAL", - EXTERNAL = "EXTERNAL", -} +export const HyperlinkType = { + INTERNAL: "INTERNAL", + EXTERNAL: "EXTERNAL", +} as const; export class ConcreteHyperlink extends XmlComponent { public readonly linkId: string; @@ -39,7 +39,12 @@ export class InternalHyperlink extends ConcreteHyperlink { } export class ExternalHyperlink extends XmlComponent { - public constructor(public readonly options: { readonly children: readonly ParagraphChild[]; readonly link: string }) { + public constructor( + public readonly options: { + readonly children: readonly ParagraphChild[]; + readonly link: string; + }, + ) { super("w:externalHyperlink"); } } diff --git a/src/file/paragraph/properties.ts b/src/file/paragraph/properties.ts index 16e27536f21..87b17faa996 100644 --- a/src/file/paragraph/properties.ts +++ b/src/file/paragraph/properties.ts @@ -18,7 +18,7 @@ import { OutlineLevel } from "./links"; import { IRunOptions, RunProperties } from "."; export interface ILevelParagraphStylePropertiesOptions { - readonly alignment?: AlignmentType; + readonly alignment?: (typeof AlignmentType)[keyof typeof AlignmentType]; readonly thematicBreak?: boolean; readonly contextualSpacing?: boolean; readonly rightTabStop?: number; @@ -47,7 +47,7 @@ export interface IParagraphStylePropertiesOptions extends ILevelParagraphStylePr export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOptions { readonly border?: IBordersOptions; - readonly heading?: HeadingLevel; + readonly heading?: (typeof HeadingLevel)[keyof typeof HeadingLevel]; readonly bidirectional?: boolean; readonly pageBreakBefore?: boolean; readonly tabStops?: readonly TabStopDefinition[]; diff --git a/src/file/paragraph/run/emphasis-mark.ts b/src/file/paragraph/run/emphasis-mark.ts index 3bd1302a59d..6fab5f74fb7 100644 --- a/src/file/paragraph/run/emphasis-mark.ts +++ b/src/file/paragraph/run/emphasis-mark.ts @@ -1,11 +1,11 @@ import { Attributes, XmlComponent } from "@file/xml-components"; -export enum EmphasisMarkType { - DOT = "dot", -} +export const EmphasisMarkType = { + DOT: "dot", +} as const; export abstract class BaseEmphasisMark extends XmlComponent { - protected constructor(emphasisMarkType: EmphasisMarkType) { + protected constructor(emphasisMarkType: (typeof EmphasisMarkType)[keyof typeof EmphasisMarkType]) { super("w:em"); this.root.push( new Attributes({ @@ -16,7 +16,7 @@ export abstract class BaseEmphasisMark extends XmlComponent { } export class EmphasisMark extends BaseEmphasisMark { - public constructor(emphasisMarkType: EmphasisMarkType = EmphasisMarkType.DOT) { + public constructor(emphasisMarkType: (typeof EmphasisMarkType)[keyof typeof EmphasisMarkType] = EmphasisMarkType.DOT) { super(emphasisMarkType); } } diff --git a/src/file/paragraph/run/field.ts b/src/file/paragraph/run/field.ts index 66862c76506..959d5986360 100644 --- a/src/file/paragraph/run/field.ts +++ b/src/file/paragraph/run/field.ts @@ -1,12 +1,15 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components"; -enum FieldCharacterType { - BEGIN = "begin", - END = "end", - SEPARATE = "separate", -} +const FieldCharacterType = { + BEGIN: "begin", + END: "end", + SEPARATE: "separate", +} as const; -class FidCharAttrs extends XmlAttributeComponent<{ readonly type: FieldCharacterType; readonly dirty?: boolean }> { +class FidCharAttrs extends XmlAttributeComponent<{ + readonly type: (typeof FieldCharacterType)[keyof typeof FieldCharacterType]; + readonly dirty?: boolean; +}> { protected readonly xmlKeys = { type: "w:fldCharType", dirty: "w:dirty" }; } diff --git a/src/file/paragraph/run/positional-tab.ts b/src/file/paragraph/run/positional-tab.ts index e3b002ed81d..c9f97ca2dc4 100644 --- a/src/file/paragraph/run/positional-tab.ts +++ b/src/file/paragraph/run/positional-tab.ts @@ -7,11 +7,11 @@ import { NextAttributeComponent, XmlComponent } from "@file/xml-components"; // // // -export enum PositionalTabAlignment { - LEFT = "left", - CENTER = "center", - RIGHT = "right", -} +export const PositionalTabAlignment = { + LEFT: "left", + CENTER: "center", + RIGHT: "right", +} as const; // // @@ -19,10 +19,10 @@ export enum PositionalTabAlignment { // // // -export enum PositionalTabRelativeTo { - MARGIN = "margin", - INDENT = "indent", -} +export const PositionalTabRelativeTo = { + MARGIN: "margin", + INDENT: "indent", +} as const; // // @@ -33,18 +33,19 @@ export enum PositionalTabRelativeTo { // // // -export enum PositionalTabLeader { - NONE = "none", - DOT = "dot", - HYPHEN = "hyphen", - UNDERSCORE = "underscore", - MIDDLE_DOT = "middleDot", -} +export const PositionalTabLeader = { + NONE: "none", + DOT: "dot", + HYPHEN: "hyphen", + UNDERSCORE: "underscore", + // eslint-disable-next-line @typescript-eslint/naming-convention + MIDDLE_DOT: "middleDot", +} as const; export interface PositionalTabOptions { - readonly alignment: PositionalTabAlignment; - readonly relativeTo: PositionalTabRelativeTo; - readonly leader: PositionalTabLeader; + readonly alignment: (typeof PositionalTabAlignment)[keyof typeof PositionalTabAlignment]; + readonly relativeTo: (typeof PositionalTabRelativeTo)[keyof typeof PositionalTabRelativeTo]; + readonly leader: (typeof PositionalTabLeader)[keyof typeof PositionalTabLeader]; } // @@ -58,9 +59,9 @@ export class PositionalTab extends XmlComponent { this.root.push( new NextAttributeComponent<{ - readonly alignment: PositionalTabAlignment; - readonly relativeTo: PositionalTabRelativeTo; - readonly leader: PositionalTabLeader; + readonly alignment: (typeof PositionalTabAlignment)[keyof typeof PositionalTabAlignment]; + readonly relativeTo: (typeof PositionalTabRelativeTo)[keyof typeof PositionalTabRelativeTo]; + readonly leader: (typeof PositionalTabLeader)[keyof typeof PositionalTabLeader]; }>({ alignment: { key: "w:alignment", diff --git a/src/file/paragraph/run/properties.ts b/src/file/paragraph/run/properties.ts index 526025d2edb..9058171f45d 100644 --- a/src/file/paragraph/run/properties.ts +++ b/src/file/paragraph/run/properties.ts @@ -25,15 +25,18 @@ interface IFontOptions { readonly hint?: string; } -export enum TextEffect { - BLINK_BACKGROUND = "blinkBackground", - LIGHTS = "lights", - ANTS_BLACK = "antsBlack", - ANTS_RED = "antsRed", - SHIMMER = "shimmer", - SPARKLE = "sparkle", - NONE = "none", -} +/* eslint-disable @typescript-eslint/naming-convention */ +export const TextEffect = { + BLINK_BACKGROUND: "blinkBackground", + LIGHTS: "lights", + ANTS_BLACK: "antsBlack", + ANTS_RED: "antsRed", + SHIMMER: "shimmer", + SPARKLE: "sparkle", + NONE: "none", +} as const; + +/* eslint-enable */ export interface IRunStylePropertiesOptions { readonly noProof?: boolean; @@ -43,11 +46,11 @@ export interface IRunStylePropertiesOptions { readonly italicsComplexScript?: boolean; readonly underline?: { readonly color?: string; - readonly type?: UnderlineType; + readonly type?: (typeof UnderlineType)[keyof typeof UnderlineType]; }; - readonly effect?: TextEffect; + readonly effect?: (typeof TextEffect)[keyof typeof TextEffect]; readonly emphasisMark?: { - readonly type?: EmphasisMarkType; + readonly type?: (typeof EmphasisMarkType)[keyof typeof EmphasisMarkType]; }; readonly color?: string; readonly kern?: number | PositiveUniversalMeasure; @@ -127,6 +130,8 @@ export interface IRunPropertiesChangeOptions extends IRunPropertiesOptions, ICha // // // +/* eslint-disable functional/immutable-data */ + export class RunProperties extends IgnoreIfEmptyXmlComponent { public constructor(options?: IRunPropertiesOptions) { super("w:rPr"); @@ -294,6 +299,8 @@ export class RunProperties extends IgnoreIfEmptyXmlComponent { } } +/* eslint-enable */ + export class RunPropertiesChange extends XmlComponent { public constructor(options: IRunPropertiesChangeOptions) { super("w:rPrChange"); diff --git a/src/file/paragraph/run/run-components/text.ts b/src/file/paragraph/run/run-components/text.ts index 34b9f2edaa3..d6bc671dbb7 100644 --- a/src/file/paragraph/run/run-components/text.ts +++ b/src/file/paragraph/run/run-components/text.ts @@ -12,7 +12,7 @@ import { TextAttributes } from "../text-attributes"; // interface ITextOptions { - readonly space?: SpaceType; + readonly space?: (typeof SpaceType)[keyof typeof SpaceType]; readonly text?: string; } diff --git a/src/file/paragraph/run/run.ts b/src/file/paragraph/run/run.ts index 023fff404e9..fee7f9720b6 100644 --- a/src/file/paragraph/run/run.ts +++ b/src/file/paragraph/run/run.ts @@ -71,7 +71,7 @@ export interface IRunOptions extends IRunPropertiesOptions { | FieldInstruction | Separate | End - | PageNumber + | (typeof PageNumber)[keyof typeof PageNumber] | FootnoteReferenceRun | Break | AnnotationReference @@ -98,11 +98,14 @@ export interface IRunOptions extends IRunPropertiesOptions { readonly text?: string; } -export enum PageNumber { - CURRENT = "CURRENT", - TOTAL_PAGES = "TOTAL_PAGES", - TOTAL_PAGES_IN_SECTION = "TOTAL_PAGES_IN_SECTION", -} +/* eslint-disable @typescript-eslint/naming-convention */ +export const PageNumber = { + CURRENT: "CURRENT", + TOTAL_PAGES: "TOTAL_PAGES", + TOTAL_PAGES_IN_SECTION: "TOTAL_PAGES_IN_SECTION", +} as const; + +/* eslint-enable */ export class Run extends XmlComponent { protected readonly properties: RunProperties; diff --git a/src/file/paragraph/run/text-attributes.ts b/src/file/paragraph/run/text-attributes.ts index e56d0911262..42b87753f9c 100644 --- a/src/file/paragraph/run/text-attributes.ts +++ b/src/file/paragraph/run/text-attributes.ts @@ -1,6 +1,8 @@ import { SpaceType } from "@file/shared"; import { XmlAttributeComponent } from "@file/xml-components"; -export class TextAttributes extends XmlAttributeComponent<{ readonly space: SpaceType }> { +export class TextAttributes extends XmlAttributeComponent<{ + readonly space: (typeof SpaceType)[keyof typeof SpaceType]; +}> { protected readonly xmlKeys = { space: "xml:space" }; } diff --git a/src/file/paragraph/run/underline.ts b/src/file/paragraph/run/underline.ts index 731e9e52e41..59379bf928e 100644 --- a/src/file/paragraph/run/underline.ts +++ b/src/file/paragraph/run/underline.ts @@ -1,29 +1,29 @@ import { Attributes, XmlComponent } from "@file/xml-components"; import { hexColorValue } from "@util/values"; -export enum UnderlineType { - SINGLE = "single", - WORDS = "words", - DOUBLE = "double", - THICK = "thick", - DOTTED = "dotted", - DOTTEDHEAVY = "dottedHeavy", - DASH = "dash", - DASHEDHEAVY = "dashedHeavy", - DASHLONG = "dashLong", - DASHLONGHEAVY = "dashLongHeavy", - DOTDASH = "dotDash", - DASHDOTHEAVY = "dashDotHeavy", - DOTDOTDASH = "dotDotDash", - DASHDOTDOTHEAVY = "dashDotDotHeavy", - WAVE = "wave", - WAVYHEAVY = "wavyHeavy", - WAVYDOUBLE = "wavyDouble", - NONE = "none", -} +export const UnderlineType = { + SINGLE: "single", + WORDS: "words", + DOUBLE: "double", + THICK: "thick", + DOTTED: "dotted", + DOTTEDHEAVY: "dottedHeavy", + DASH: "dash", + DASHEDHEAVY: "dashedHeavy", + DASHLONG: "dashLong", + DASHLONGHEAVY: "dashLongHeavy", + DOTDASH: "dotDash", + DASHDOTHEAVY: "dashDotHeavy", + DOTDOTDASH: "dotDotDash", + DASHDOTDOTHEAVY: "dashDotDotHeavy", + WAVE: "wave", + WAVYHEAVY: "wavyHeavy", + WAVYDOUBLE: "wavyDouble", + NONE: "none", +} as const; export class Underline extends XmlComponent { - public constructor(underlineType: UnderlineType = UnderlineType.SINGLE, color?: string) { + public constructor(underlineType: (typeof UnderlineType)[keyof typeof UnderlineType] = UnderlineType.SINGLE, color?: string) { super("w:u"); this.root.push( new Attributes({ diff --git a/src/file/relationships/relationship/relationship.ts b/src/file/relationships/relationship/relationship.ts index 96508fa405d..099c7c11f19 100644 --- a/src/file/relationships/relationship/relationship.ts +++ b/src/file/relationships/relationship/relationship.ts @@ -19,12 +19,17 @@ export type RelationshipType = | "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes" | "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"; -export enum TargetModeType { - EXTERNAL = "External", -} +export const TargetModeType = { + EXTERNAL: "External", +} as const; export class Relationship extends XmlComponent { - public constructor(id: string, type: RelationshipType, target: string, targetMode?: TargetModeType) { + public constructor( + id: string, + type: RelationshipType, + target: string, + targetMode?: (typeof TargetModeType)[keyof typeof TargetModeType], + ) { super("Relationship"); this.root.push( diff --git a/src/file/relationships/relationships.ts b/src/file/relationships/relationships.ts index b7b0f89ca6e..f66eea8c19a 100644 --- a/src/file/relationships/relationships.ts +++ b/src/file/relationships/relationships.ts @@ -12,7 +12,12 @@ export class Relationships extends XmlComponent { ); } - public createRelationship(id: number | string, type: RelationshipType, target: string, targetMode?: TargetModeType): Relationship { + public createRelationship( + id: number | string, + type: RelationshipType, + target: string, + targetMode?: (typeof TargetModeType)[keyof typeof TargetModeType], + ): Relationship { const relationship = new Relationship(`rId${id}`, type, target, targetMode); this.root.push(relationship); diff --git a/src/file/shading/shading.ts b/src/file/shading/shading.ts index 249b03c50aa..e2d9369c1d7 100644 --- a/src/file/shading/shading.ts +++ b/src/file/shading/shading.ts @@ -23,7 +23,7 @@ import { hexColorValue } from "@util/values"; export interface IShadingAttributesProperties { readonly fill?: string; readonly color?: string; - readonly type?: ShadingType; + readonly type?: (typeof ShadingType)[keyof typeof ShadingType]; } class ShadingAttributes extends XmlAttributeComponent { @@ -47,42 +47,44 @@ export class Shading extends XmlComponent { } } -export enum ShadingType { - CLEAR = "clear", - DIAGONAL_CROSS = "diagCross", - DIAGONAL_STRIPE = "diagStripe", - HORIZONTAL_CROSS = "horzCross", - HORIZONTAL_STRIPE = "horzStripe", - NIL = "nil", - PERCENT_5 = "pct5", - PERCENT_10 = "pct10", - PERCENT_12 = "pct12", - PERCENT_15 = "pct15", - PERCENT_20 = "pct20", - PERCENT_25 = "pct25", - PERCENT_30 = "pct30", - PERCENT_35 = "pct35", - PERCENT_37 = "pct37", - PERCENT_40 = "pct40", - PERCENT_45 = "pct45", - PERCENT_50 = "pct50", - PERCENT_55 = "pct55", - PERCENT_60 = "pct60", - PERCENT_62 = "pct62", - PERCENT_65 = "pct65", - PERCENT_70 = "pct70", - PERCENT_75 = "pct75", - PERCENT_80 = "pct80", - PERCENT_85 = "pct85", - PERCENT_87 = "pct87", - PERCENT_90 = "pct90", - PERCENT_95 = "pct95", - REVERSE_DIAGONAL_STRIPE = "reverseDiagStripe", - SOLID = "solid", - THIN_DIAGONAL_CROSS = "thinDiagCross", - THIN_DIAGONAL_STRIPE = "thinDiagStripe", - THIN_HORIZONTAL_CROSS = "thinHorzCross", - THIN_REVERSE_DIAGONAL_STRIPE = "thinReverseDiagStripe", - THIN_VERTICAL_STRIPE = "thinVertStripe", - VERTICAL_STRIPE = "vertStripe", -} +/* eslint-disable @typescript-eslint/naming-convention */ +export const ShadingType = { + CLEAR: "clear", + DIAGONAL_CROSS: "diagCross", + DIAGONAL_STRIPE: "diagStripe", + HORIZONTAL_CROSS: "horzCross", + HORIZONTAL_STRIPE: "horzStripe", + NIL: "nil", + PERCENT_5: "pct5", + PERCENT_10: "pct10", + PERCENT_12: "pct12", + PERCENT_15: "pct15", + PERCENT_20: "pct20", + PERCENT_25: "pct25", + PERCENT_30: "pct30", + PERCENT_35: "pct35", + PERCENT_37: "pct37", + PERCENT_40: "pct40", + PERCENT_45: "pct45", + PERCENT_50: "pct50", + PERCENT_55: "pct55", + PERCENT_60: "pct60", + PERCENT_62: "pct62", + PERCENT_65: "pct65", + PERCENT_70: "pct70", + PERCENT_75: "pct75", + PERCENT_80: "pct80", + PERCENT_85: "pct85", + PERCENT_87: "pct87", + PERCENT_90: "pct90", + PERCENT_95: "pct95", + REVERSE_DIAGONAL_STRIPE: "reverseDiagStripe", + SOLID: "solid", + THIN_DIAGONAL_CROSS: "thinDiagCross", + THIN_DIAGONAL_STRIPE: "thinDiagStripe", + THIN_HORIZONTAL_CROSS: "thinHorzCross", + THIN_REVERSE_DIAGONAL_STRIPE: "thinReverseDiagStripe", + THIN_VERTICAL_STRIPE: "thinVertStripe", + VERTICAL_STRIPE: "vertStripe", +} as const; +/* eslint-enable */ diff --git a/src/file/shared/alignment.ts b/src/file/shared/alignment.ts index 5909025891c..238a22a5daa 100644 --- a/src/file/shared/alignment.ts +++ b/src/file/shared/alignment.ts @@ -1,15 +1,15 @@ -export enum HorizontalPositionAlign { - CENTER = "center", - INSIDE = "inside", - LEFT = "left", - OUTSIDE = "outside", - RIGHT = "right", -} +export const HorizontalPositionAlign = { + CENTER: "center", + INSIDE: "inside", + LEFT: "left", + OUTSIDE: "outside", + RIGHT: "right", +} as const; -export enum VerticalPositionAlign { - BOTTOM = "bottom", - CENTER = "center", - INSIDE = "inside", - OUTSIDE = "outside", - TOP = "top", -} +export const VerticalPositionAlign = { + BOTTOM: "bottom", + CENTER: "center", + INSIDE: "inside", + OUTSIDE: "outside", + TOP: "top", +} as const; diff --git a/src/file/shared/number-format.ts b/src/file/shared/number-format.ts index 8ee5ad10fcf..58e37f87c39 100644 --- a/src/file/shared/number-format.ts +++ b/src/file/shared/number-format.ts @@ -66,68 +66,70 @@ // // -export enum NumberFormat { - DECIMAL = "decimal", - UPPER_ROMAN = "upperRoman", - LOWER_ROMAN = "lowerRoman", - UPPER_LETTER = "upperLetter", - LOWER_LETTER = "lowerLetter", - ORDINAL = "ordinal", - CARDINAL_TEXT = "cardinalText", - ORDINAL_TEXT = "ordinalText", - HEX = "hex", - CHICAGO = "chicago", - IDEOGRAPH_DIGITAL = "ideographDigital", - JAPANESE_COUNTING = "japaneseCounting", - AIUEO = "aiueo", - IROHA = "iroha", - DECIMAL_FULL_WIDTH = "decimalFullWidth", - DECIMAL_HALF_WIDTH = "decimalHalfWidth", - JAPANESE_LEGAL = "japaneseLegal", - JAPANESE_DIGITAL_TEN_THOUSAND = "japaneseDigitalTenThousand", - DECIMAL_ENCLOSED_CIRCLE = "decimalEnclosedCircle", - DECIMAL_FULL_WIDTH_2 = "decimalFullWidth2", - AIUEO_FULL_WIDTH = "aiueoFullWidth", - IROHA_FULL_WIDTH = "irohaFullWidth", - DECIMAL_ZERO = "decimalZero", - BULLET = "bullet", - GANADA = "ganada", - CHOSUNG = "chosung", - DECIMAL_ENCLOSED_FULL_STOP = "decimalEnclosedFullstop", - DECIMAL_ENCLOSED_PAREN = "decimalEnclosedParen", - DECIMAL_ENCLOSED_CIRCLE_CHINESE = "decimalEnclosedCircleChinese", - IDEOGRAPH_ENCLOSED_CIRCLE = "ideographEnclosedCircle", - IDEOGRAPH_TRADITIONAL = "ideographTraditional", - IDEOGRAPH_ZODIAC = "ideographZodiac", - IDEOGRAPH_ZODIAC_TRADITIONAL = "ideographZodiacTraditional", - TAIWANESE_COUNTING = "taiwaneseCounting", - IDEOGRAPH_LEGAL_TRADITIONAL = "ideographLegalTraditional", - TAIWANESE_COUNTING_THOUSAND = "taiwaneseCountingThousand", - TAIWANESE_DIGITAL = "taiwaneseDigital", - CHINESE_COUNTING = "chineseCounting", - CHINESE_LEGAL_SIMPLIFIED = "chineseLegalSimplified", - CHINESE_COUNTING_TEN_THOUSAND = "chineseCountingThousand", - KOREAN_DIGITAL = "koreanDigital", - KOREAN_COUNTING = "koreanCounting", - KOREAN_LEGAL = "koreanLegal", - KOREAN_DIGITAL_2 = "koreanDigital2", - VIETNAMESE_COUNTING = "vietnameseCounting", - RUSSIAN_LOWER = "russianLower", - RUSSIAN_UPPER = "russianUpper", - NONE = "none", - NUMBER_IN_DASH = "numberInDash", - HEBREW_1 = "hebrew1", - HEBREW_2 = "hebrew2", - ARABIC_ALPHA = "arabicAlpha", - ARABIC_ABJAD = "arabicAbjad", - HINDI_VOWELS = "hindiVowels", - HINDI_CONSONANTS = "hindiConsonants", - HINDI_NUMBERS = "hindiNumbers", - HINDI_COUNTING = "hindiCounting", - THAI_LETTERS = "thaiLetters", - THAI_NUMBERS = "thaiNumbers", - THAI_COUNTING = "thaiCounting", - BAHT_TEXT = "bahtText", - DOLLAR_TEXT = "dollarText", +/* eslint-disable @typescript-eslint/naming-convention*/ +export const NumberFormat = { + DECIMAL: "decimal", + UPPER_ROMAN: "upperRoman", + LOWER_ROMAN: "lowerRoman", + UPPER_LETTER: "upperLetter", + LOWER_LETTER: "lowerLetter", + ORDINAL: "ordinal", + CARDINAL_TEXT: "cardinalText", + ORDINAL_TEXT: "ordinalText", + HEX: "hex", + CHICAGO: "chicago", + IDEOGRAPH_DIGITAL: "ideographDigital", + JAPANESE_COUNTING: "japaneseCounting", + AIUEO: "aiueo", + IROHA: "iroha", + DECIMAL_FULL_WIDTH: "decimalFullWidth", + DECIMAL_HALF_WIDTH: "decimalHalfWidth", + JAPANESE_LEGAL: "japaneseLegal", + JAPANESE_DIGITAL_TEN_THOUSAND: "japaneseDigitalTenThousand", + DECIMAL_ENCLOSED_CIRCLE: "decimalEnclosedCircle", + DECIMAL_FULL_WIDTH_2: "decimalFullWidth2", + AIUEO_FULL_WIDTH: "aiueoFullWidth", + IROHA_FULL_WIDTH: "irohaFullWidth", + DECIMAL_ZERO: "decimalZero", + BULLET: "bullet", + GANADA: "ganada", + CHOSUNG: "chosung", + DECIMAL_ENCLOSED_FULL_STOP: "decimalEnclosedFullstop", + DECIMAL_ENCLOSED_PAREN: "decimalEnclosedParen", + DECIMAL_ENCLOSED_CIRCLE_CHINESE: "decimalEnclosedCircleChinese", + IDEOGRAPH_ENCLOSED_CIRCLE: "ideographEnclosedCircle", + IDEOGRAPH_TRADITIONAL: "ideographTraditional", + IDEOGRAPH_ZODIAC: "ideographZodiac", + IDEOGRAPH_ZODIAC_TRADITIONAL: "ideographZodiacTraditional", + TAIWANESE_COUNTING: "taiwaneseCounting", + IDEOGRAPH_LEGAL_TRADITIONAL: "ideographLegalTraditional", + TAIWANESE_COUNTING_THOUSAND: "taiwaneseCountingThousand", + TAIWANESE_DIGITAL: "taiwaneseDigital", + CHINESE_COUNTING: "chineseCounting", + CHINESE_LEGAL_SIMPLIFIED: "chineseLegalSimplified", + CHINESE_COUNTING_TEN_THOUSAND: "chineseCountingThousand", + KOREAN_DIGITAL: "koreanDigital", + KOREAN_COUNTING: "koreanCounting", + KOREAN_LEGAL: "koreanLegal", + KOREAN_DIGITAL_2: "koreanDigital2", + VIETNAMESE_COUNTING: "vietnameseCounting", + RUSSIAN_LOWER: "russianLower", + RUSSIAN_UPPER: "russianUpper", + NONE: "none", + NUMBER_IN_DASH: "numberInDash", + HEBREW_1: "hebrew1", + HEBREW_2: "hebrew2", + ARABIC_ALPHA: "arabicAlpha", + ARABIC_ABJAD: "arabicAbjad", + HINDI_VOWELS: "hindiVowels", + HINDI_CONSONANTS: "hindiConsonants", + HINDI_NUMBERS: "hindiNumbers", + HINDI_COUNTING: "hindiCounting", + THAI_LETTERS: "thaiLetters", + THAI_NUMBERS: "thaiNumbers", + THAI_COUNTING: "thaiCounting", + BAHT_TEXT: "bahtText", + DOLLAR_TEXT: "dollarText", // -} +} as const; +/* eslint-enable */ diff --git a/src/file/shared/space-type.ts b/src/file/shared/space-type.ts index f40c2d88fc0..77062e39c8f 100644 --- a/src/file/shared/space-type.ts +++ b/src/file/shared/space-type.ts @@ -1,4 +1,4 @@ -export enum SpaceType { - DEFAULT = "default", - PRESERVE = "preserve", -} +export const SpaceType = { + DEFAULT: "default", + PRESERVE: "preserve", +} as const; diff --git a/src/file/table/table-cell/table-cell-components.ts b/src/file/table/table-cell/table-cell-components.ts index 1327b645c4e..11e9dc711f4 100644 --- a/src/file/table/table-cell/table-cell-components.ts +++ b/src/file/table/table-cell/table-cell-components.ts @@ -80,18 +80,20 @@ export class GridSpan extends XmlComponent { /** * Vertical merge types. */ -export enum VerticalMergeType { +export const VerticalMergeType = { /** * Cell that is merged with upper one. */ - CONTINUE = "continue", + CONTINUE: "continue", /** * Cell that is starting the vertical merge. */ - RESTART = "restart", -} + RESTART: "restart", +} as const; -class VerticalMergeAttributes extends XmlAttributeComponent<{ readonly val: VerticalMergeType }> { +class VerticalMergeAttributes extends XmlAttributeComponent<{ + readonly val: (typeof VerticalMergeType)[keyof typeof VerticalMergeType]; +}> { protected readonly xmlKeys = { val: "w:val" }; } @@ -99,7 +101,7 @@ class VerticalMergeAttributes extends XmlAttributeComponent<{ readonly val: Vert * Vertical merge element. Should be used in a table cell. */ export class VerticalMerge extends XmlComponent { - public constructor(value: VerticalMergeType) { + public constructor(value: (typeof VerticalMergeType)[keyof typeof VerticalMergeType]) { super("w:vMerge"); this.root.push( @@ -110,13 +112,18 @@ export class VerticalMerge extends XmlComponent { } } -export enum TextDirection { - BOTTOM_TO_TOP_LEFT_TO_RIGHT = "btLr", - LEFT_TO_RIGHT_TOP_TO_BOTTOM = "lrTb", - TOP_TO_BOTTOM_RIGHT_TO_LEFT = "tbRl", -} +export const TextDirection = { + // eslint-disable-next-line @typescript-eslint/naming-convention + BOTTOM_TO_TOP_LEFT_TO_RIGHT: "btLr", + // eslint-disable-next-line @typescript-eslint/naming-convention + LEFT_TO_RIGHT_TOP_TO_BOTTOM: "lrTb", + // eslint-disable-next-line @typescript-eslint/naming-convention + TOP_TO_BOTTOM_RIGHT_TO_LEFT: "tbRl", +} as const; -class TDirectionAttributes extends XmlAttributeComponent<{ readonly val: TextDirection }> { +class TDirectionAttributes extends XmlAttributeComponent<{ + readonly val: (typeof TextDirection)[keyof typeof TextDirection]; +}> { protected readonly xmlKeys = { val: "w:val" }; } @@ -124,7 +131,7 @@ class TDirectionAttributes extends XmlAttributeComponent<{ readonly val: TextDir * Text Direction within a table cell */ export class TDirection extends XmlComponent { - public constructor(value: TextDirection) { + public constructor(value: (typeof TextDirection)[keyof typeof TextDirection]) { super("w:textDirection"); this.root.push( diff --git a/src/file/table/table-cell/table-cell-properties.ts b/src/file/table/table-cell/table-cell-properties.ts index 23d9ade1115..21c8c9a4a3f 100644 --- a/src/file/table/table-cell/table-cell-properties.ts +++ b/src/file/table/table-cell/table-cell-properties.ts @@ -17,9 +17,9 @@ import { export interface ITableCellPropertiesOptions { readonly shading?: IShadingAttributesProperties; readonly margins?: ITableCellMarginOptions; - readonly verticalAlign?: VerticalAlign; - readonly textDirection?: TextDirection; - readonly verticalMerge?: VerticalMergeType; + readonly verticalAlign?: (typeof VerticalAlign)[keyof typeof VerticalAlign]; + readonly textDirection?: (typeof TextDirection)[keyof typeof TextDirection]; + readonly verticalMerge?: (typeof VerticalMergeType)[keyof typeof VerticalMergeType]; readonly width?: ITableWidthProperties; readonly columnSpan?: number; readonly rowSpan?: number; diff --git a/src/file/table/table-properties/table-cell-margin.ts b/src/file/table/table-properties/table-cell-margin.ts index 01e29a3770d..e3a76ee34c9 100644 --- a/src/file/table/table-properties/table-cell-margin.ts +++ b/src/file/table/table-properties/table-cell-margin.ts @@ -1,8 +1,8 @@ import { IgnoreIfEmptyXmlComponent } from "@file/xml-components"; -import { TableWidthElement, WidthType } from "../table-width"; +import { TableWidthElement, WidthType } from "@file/table"; export interface ITableCellMarginOptions { - readonly marginUnitType?: WidthType; + readonly marginUnitType?: (typeof WidthType)[keyof typeof WidthType]; readonly top?: number; readonly bottom?: number; readonly left?: number; @@ -33,14 +33,15 @@ export interface ITableCellMarginOptions { // // -export enum TableCellMarginElementType { - TABLE = "w:tblCellMar", - TABLE_CELL = "w:tcMar", -} +export const TableCellMarginElementType = { + TABLE: "w:tblCellMar", + // eslint-disable-next-line @typescript-eslint/naming-convention + TABLE_CELL: "w:tcMar", +} as const; export class TableCellMargin extends IgnoreIfEmptyXmlComponent { public constructor( - type: TableCellMarginElementType, + type: (typeof TableCellMarginElementType)[keyof typeof TableCellMarginElementType], { marginUnitType = WidthType.DXA, top, left, bottom, right }: ITableCellMarginOptions, ) { super(type); diff --git a/src/file/table/table-properties/table-float-properties.ts b/src/file/table/table-properties/table-float-properties.ts index 1cd5e75df3c..3d077fa1b88 100644 --- a/src/file/table/table-properties/table-float-properties.ts +++ b/src/file/table/table-properties/table-float-properties.ts @@ -1,28 +1,28 @@ import { NextAttributeComponent, StringEnumValueElement, XmlComponent } from "@file/xml-components"; import { PositiveUniversalMeasure, signedTwipsMeasureValue, twipsMeasureValue, UniversalMeasure } from "@util/values"; -export enum TableAnchorType { - MARGIN = "margin", - PAGE = "page", - TEXT = "text", -} - -export enum RelativeHorizontalPosition { - CENTER = "center", - INSIDE = "inside", - LEFT = "left", - OUTSIDE = "outside", - RIGHT = "right", -} - -export enum RelativeVerticalPosition { - CENTER = "center", - INSIDE = "inside", - BOTTOM = "bottom", - OUTSIDE = "outside", - INLINE = "inline", - TOP = "top", -} +export const TableAnchorType = { + MARGIN: "margin", + PAGE: "page", + TEXT: "text", +} as const; + +export const RelativeHorizontalPosition = { + CENTER: "center", + INSIDE: "inside", + LEFT: "left", + OUTSIDE: "outside", + RIGHT: "right", +} as const; + +export const RelativeVerticalPosition = { + CENTER: "center", + INSIDE: "inside", + BOTTOM: "bottom", + OUTSIDE: "outside", + INLINE: "inline", + TOP: "top", +} as const; // // @@ -30,10 +30,10 @@ export enum RelativeVerticalPosition { // // // -export enum OverlapType { - NEVER = "never", - OVERLAP = "overlap", -} +export const OverlapType = { + NEVER: "never", + OVERLAP: "overlap", +} as const; export type ITableFloatOptions = { /* cSpell:disable */ @@ -46,7 +46,7 @@ export type ITableFloatOptions = { * If omitted, the value is assumed to be page. */ /* cSpell:enable */ - readonly horizontalAnchor?: TableAnchorType; + readonly horizontalAnchor?: (typeof TableAnchorType)[keyof typeof TableAnchorType]; /** * Specifies an absolute horizontal position for the table, relative to the horizontalAnchor. @@ -67,7 +67,7 @@ export type ITableFloatOptions = { * outside - the table should be outside of the anchor * right - the table should be right aligned with respect to the anchor */ - readonly relativeHorizontalPosition?: RelativeHorizontalPosition; + readonly relativeHorizontalPosition?: (typeof RelativeHorizontalPosition)[keyof typeof RelativeHorizontalPosition]; /** * Specifies the vertical anchor or the base object from which the vertical positioning @@ -77,7 +77,7 @@ export type 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. */ - readonly verticalAnchor?: TableAnchorType; + readonly verticalAnchor?: (typeof TableAnchorType)[keyof typeof TableAnchorType]; /** * Specifies an absolute vertical position for the table, relative to the verticalAnchor anchor. @@ -98,7 +98,7 @@ export type 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 */ - readonly relativeVerticalPosition?: RelativeVerticalPosition; + readonly relativeVerticalPosition?: (typeof RelativeVerticalPosition)[keyof typeof RelativeVerticalPosition]; /** * Specifies the minimum distance to be maintained between the table and the top of text in the paragraph @@ -123,7 +123,7 @@ export type ITableFloatOptions = { * to the right of the table. The value is in twentieths of a point. If omitted, the value is assumed to be zero. */ readonly rightFromText?: number | PositiveUniversalMeasure; - readonly overlap?: OverlapType; + readonly overlap?: (typeof OverlapType)[keyof typeof OverlapType]; }; // @@ -156,12 +156,18 @@ export class TableFloatProperties extends XmlComponent { super("w:tblpPr"); this.root.push( new NextAttributeComponent>({ - leftFromText: { key: "w:leftFromText", value: leftFromText === undefined ? undefined : twipsMeasureValue(leftFromText) }, + leftFromText: { + key: "w:leftFromText", + value: leftFromText === undefined ? undefined : twipsMeasureValue(leftFromText), + }, rightFromText: { key: "w:rightFromText", value: rightFromText === undefined ? undefined : twipsMeasureValue(rightFromText), }, - topFromText: { key: "w:topFromText", value: topFromText === undefined ? undefined : twipsMeasureValue(topFromText) }, + topFromText: { + key: "w:topFromText", + value: topFromText === undefined ? undefined : twipsMeasureValue(topFromText), + }, bottomFromText: { key: "w:bottomFromText", value: bottomFromText === undefined ? undefined : twipsMeasureValue(bottomFromText), @@ -197,7 +203,7 @@ export class TableFloatProperties extends XmlComponent { // // // - this.root.push(new StringEnumValueElement("w:tblOverlap", overlap)); + this.root.push(new StringEnumValueElement<(typeof OverlapType)[keyof typeof OverlapType]>("w:tblOverlap", overlap)); } } } diff --git a/src/file/table/table-properties/table-layout.ts b/src/file/table/table-properties/table-layout.ts index 3c7c215307e..3b32126fdf2 100644 --- a/src/file/table/table-properties/table-layout.ts +++ b/src/file/table/table-properties/table-layout.ts @@ -6,12 +6,14 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components"; // // // -export enum TableLayoutType { - AUTOFIT = "autofit", - FIXED = "fixed", -} +export const TableLayoutType = { + AUTOFIT: "autofit", + FIXED: "fixed", +} as const; -class TableLayoutAttributes extends XmlAttributeComponent<{ readonly type: TableLayoutType }> { +class TableLayoutAttributes extends XmlAttributeComponent<{ + readonly type: (typeof TableLayoutType)[keyof typeof TableLayoutType]; +}> { protected readonly xmlKeys = { type: "w:type" }; } @@ -19,7 +21,7 @@ class TableLayoutAttributes extends XmlAttributeComponent<{ readonly type: Table // // export class TableLayout extends XmlComponent { - public constructor(type: TableLayoutType) { + public constructor(type: (typeof TableLayoutType)[keyof typeof TableLayoutType]) { super("w:tblLayout"); this.root.push(new TableLayoutAttributes({ type })); } diff --git a/src/file/table/table-properties/table-properties.ts b/src/file/table/table-properties/table-properties.ts index d720fdf384e..d731693fac5 100644 --- a/src/file/table/table-properties/table-properties.ts +++ b/src/file/table/table-properties/table-properties.ts @@ -34,12 +34,12 @@ import { TableLayout, TableLayoutType } from "./table-layout"; export interface ITablePropertiesOptions { readonly width?: ITableWidthProperties; readonly indent?: ITableWidthProperties; - readonly layout?: TableLayoutType; + readonly layout?: (typeof TableLayoutType)[keyof typeof TableLayoutType]; readonly borders?: ITableBordersOptions; readonly float?: ITableFloatOptions; readonly shading?: IShadingAttributesProperties; readonly style?: string; - readonly alignment?: AlignmentType; + readonly alignment?: (typeof AlignmentType)[keyof typeof AlignmentType]; readonly cellMargin?: ITableCellMarginOptions; readonly visuallyRightToLeft?: boolean; } diff --git a/src/file/table/table-row/table-row-height.ts b/src/file/table/table-row/table-row-height.ts index 4c6043bb47b..f1ca591cd32 100644 --- a/src/file/table/table-row/table-row-height.ts +++ b/src/file/table/table-row/table-row-height.ts @@ -13,24 +13,24 @@ import { PositiveUniversalMeasure, twipsMeasureValue } from "@util/values"; // // // -export enum HeightRule { +export const HeightRule = { /** Height is determined based on the content, so value is ignored. */ - AUTO = "auto", + AUTO: "auto", /** At least the value specified */ - ATLEAST = "atLeast", + ATLEAST: "atLeast", /** Exactly the value specified */ - EXACT = "exact", -} + EXACT: "exact", +} as const; export class TableRowHeightAttributes extends XmlAttributeComponent<{ readonly value: number | string; - readonly rule: HeightRule; + readonly rule: (typeof HeightRule)[keyof typeof HeightRule]; }> { protected readonly xmlKeys = { value: "w:val", rule: "w:hRule" }; } export class TableRowHeight extends XmlComponent { - public constructor(value: number | PositiveUniversalMeasure, rule: HeightRule) { + public constructor(value: number | PositiveUniversalMeasure, rule: (typeof HeightRule)[keyof typeof HeightRule]) { super("w:trHeight"); this.root.push( diff --git a/src/file/table/table-row/table-row-properties.ts b/src/file/table/table-row/table-row-properties.ts index d388e917ebc..b7d3c7018f2 100644 --- a/src/file/table/table-row/table-row-properties.ts +++ b/src/file/table/table-row/table-row-properties.ts @@ -37,7 +37,7 @@ export interface ITableRowPropertiesOptions { readonly tableHeader?: boolean; readonly height?: { readonly value: number | PositiveUniversalMeasure; - readonly rule: HeightRule; + readonly rule: (typeof HeightRule)[keyof typeof HeightRule]; }; } diff --git a/src/file/table/table-width.ts b/src/file/table/table-width.ts index 1c2e29a0c55..4a950566eba 100644 --- a/src/file/table/table-width.ts +++ b/src/file/table/table-width.ts @@ -10,16 +10,17 @@ import { measurementOrPercentValue, Percentage, UniversalMeasure } from "@util/v // // // -export enum WidthType { + +export const WidthType = { /** Auto. */ - AUTO = "auto", + AUTO: "auto", /** Value is in twentieths of a point */ - DXA = "dxa", + DXA: "dxa", /** No (empty) value. */ - NIL = "nil", + NIL: "nil", /** Value is in percentage. */ - PERCENTAGE = "pct", -} + PERCENTAGE: "pct", +} as const; // // @@ -27,7 +28,7 @@ export enum WidthType { // export type ITableWidthProperties = { readonly size: number | Percentage | UniversalMeasure; - readonly type?: WidthType; + readonly type?: (typeof WidthType)[keyof typeof WidthType]; }; export class TableWidthElement extends XmlComponent { diff --git a/src/file/table/table.ts b/src/file/table/table.ts index 4e5545b1715..91269bc3190 100644 --- a/src/file/table/table.ts +++ b/src/file/table/table.ts @@ -27,10 +27,10 @@ export interface ITableOptions { readonly margins?: ITableCellMarginOptions; readonly indent?: ITableWidthProperties; readonly float?: ITableFloatOptions; - readonly layout?: TableLayoutType; + readonly layout?: (typeof TableLayoutType)[keyof typeof TableLayoutType]; readonly style?: string; readonly borders?: ITableBordersOptions; - readonly alignment?: AlignmentType; + readonly alignment?: (typeof AlignmentType)[keyof typeof AlignmentType]; readonly visuallyRightToLeft?: boolean; } diff --git a/src/file/vertical-align/vertical-align.ts b/src/file/vertical-align/vertical-align.ts index 795dff8c838..7556ae552cc 100644 --- a/src/file/vertical-align/vertical-align.ts +++ b/src/file/vertical-align/vertical-align.ts @@ -11,13 +11,14 @@ import { XmlAttributeComponent, XmlComponent } from "@file/xml-components"; // // // -export enum VerticalAlign { - BOTTOM = "bottom", - CENTER = "center", - TOP = "top", -} +export const VerticalAlign = { + BOTTOM: "bottom", + CENTER: "center", + TOP: "top", +} as const; + export class VerticalAlignAttributes extends XmlAttributeComponent<{ - readonly verticalAlign?: VerticalAlign; + readonly verticalAlign?: (typeof VerticalAlign)[keyof typeof VerticalAlign]; }> { protected readonly xmlKeys = { verticalAlign: "w:val", @@ -25,7 +26,7 @@ export class VerticalAlignAttributes extends XmlAttributeComponent<{ } export class VerticalAlignElement extends XmlComponent { - public constructor(value: VerticalAlign) { + public constructor(value: (typeof VerticalAlign)[keyof typeof VerticalAlign]) { super("w:vAlign"); this.root.push(new VerticalAlignAttributes({ verticalAlign: value })); } diff --git a/src/patcher/from-docx.ts b/src/patcher/from-docx.ts index 7aec7930b72..11c4c9c4ceb 100644 --- a/src/patcher/from-docx.ts +++ b/src/patcher/from-docx.ts @@ -20,18 +20,18 @@ import { appendContentType } from "./content-types-manager"; // eslint-disable-next-line functional/prefer-readonly-type type InputDataType = Buffer | string | number[] | Uint8Array | ArrayBuffer | Blob | NodeJS.ReadableStream; -export enum PatchType { - DOCUMENT = "file", - PARAGRAPH = "paragraph", -} +export const PatchType = { + DOCUMENT: "file", + PARAGRAPH: "paragraph", +} as const; type ParagraphPatch = { - readonly type: PatchType.PARAGRAPH; + readonly type: typeof PatchType.PARAGRAPH; readonly children: readonly ParagraphChild[]; }; type FilePatch = { - readonly type: PatchType.DOCUMENT; + readonly type: typeof PatchType.DOCUMENT; readonly children: readonly FileChild[]; }; @@ -83,7 +83,12 @@ export const patchDocument = async (data: InputDataType, options: PatchDocumentO file, viewWrapper: { Relationships: { - createRelationship: (linkId: string, _: string, target: string, __: TargetModeType) => { + createRelationship: ( + linkId: string, + _: string, + target: string, + __: (typeof TargetModeType)[keyof typeof TargetModeType], + ) => { // eslint-disable-next-line functional/immutable-data hyperlinkRelationshipAdditions.push({ key, diff --git a/src/patcher/paragraph-token-replacer.ts b/src/patcher/paragraph-token-replacer.ts index b961c646b9c..906fcbf79e4 100644 --- a/src/patcher/paragraph-token-replacer.ts +++ b/src/patcher/paragraph-token-replacer.ts @@ -3,11 +3,11 @@ import { Element } from "xml-js"; import { createTextElementContents, patchSpaceAttribute } from "./util"; import { IRenderedParagraphNode } from "./run-renderer"; -enum ReplaceMode { - START, - MIDDLE, - END, -} +const ReplaceMode = { + START: 0, + MIDDLE: 1, + END: 2, +} as const; export const replaceTokenInParagraphElement = ({ paragraphElement, @@ -23,7 +23,7 @@ export const replaceTokenInParagraphElement = ({ const startIndex = renderedParagraph.text.indexOf(originalText); const endIndex = startIndex + originalText.length - 1; - let replaceMode = ReplaceMode.START; + let replaceMode: (typeof ReplaceMode)[keyof typeof ReplaceMode] = ReplaceMode.START; for (const run of renderedParagraph.runs) { for (const { text, index, start, end } of run.parts) { diff --git a/src/patcher/relationship-manager.ts b/src/patcher/relationship-manager.ts index 4f140357035..dbaf734b8a5 100644 --- a/src/patcher/relationship-manager.ts +++ b/src/patcher/relationship-manager.ts @@ -23,7 +23,7 @@ export const appendRelationship = ( id: number | string, type: RelationshipType, target: string, - targetMode?: TargetModeType, + targetMode?: (typeof TargetModeType)[keyof typeof TargetModeType], ): readonly Element[] => { const relationshipElements = getFirstLevelElements(relationships, "Relationships"); // eslint-disable-next-line functional/immutable-data