Change all project enums to objects with as const (#2445)

* feat: change all enums to as const objects

* Add word to dictionary

---------

Co-authored-by: Dolan Miu <dolan_miu@hotmail.com>
This commit is contained in:
Stepan Svechnikov
2023-12-22 10:25:00 +09:00
committed by GitHub
parent fd1ea5b4dc
commit a756a7697c
60 changed files with 790 additions and 666 deletions

View File

@ -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);
}
}

View File

@ -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" };
}

View File

@ -7,11 +7,11 @@ import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
// <xsd:enumeration value="right" />
// </xsd:restriction>
// </xsd:simpleType>
export enum PositionalTabAlignment {
LEFT = "left",
CENTER = "center",
RIGHT = "right",
}
export const PositionalTabAlignment = {
LEFT: "left",
CENTER: "center",
RIGHT: "right",
} as const;
// <xsd:simpleType name="ST_PTabRelativeTo">
// <xsd:restriction base="xsd:string">
@ -19,10 +19,10 @@ export enum PositionalTabAlignment {
// <xsd:enumeration value="indent" />
// </xsd:restriction>
// </xsd:simpleType>
export enum PositionalTabRelativeTo {
MARGIN = "margin",
INDENT = "indent",
}
export const PositionalTabRelativeTo = {
MARGIN: "margin",
INDENT: "indent",
} as const;
// <xsd:simpleType name="ST_PTabLeader">
// <xsd:restriction base="xsd:string">
@ -33,18 +33,19 @@ export enum PositionalTabRelativeTo {
// <xsd:enumeration value="middleDot" />
// </xsd:restriction>
// </xsd:simpleType>
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];
}
// <xsd:complexType name="CT_PTab">
@ -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",

View File

@ -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
// <xsd:element name="oMath" type="CT_OnOff"/>
// </xsd:choice>
// </xsd:group>
/* 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");

View File

@ -12,7 +12,7 @@ import { TextAttributes } from "../text-attributes";
// </xsd:complexType>
interface ITextOptions {
readonly space?: SpaceType;
readonly space?: (typeof SpaceType)[keyof typeof SpaceType];
readonly text?: string;
}

View File

@ -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;

View File

@ -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" };
}

View File

@ -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({