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

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

View File

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

View File

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