From 0da3126283d18faee536ba5b2969f43e448478ed Mon Sep 17 00:00:00 2001 From: kotaindah55 Date: Tue, 4 Mar 2025 16:51:23 +0200 Subject: [PATCH] refactor: move all the format constants to Format.ts --- src/shared-configs/Formats.ts | 46 ++++++++++++++++++++ src/shared-configs/NonHighlightFormats.ts | 12 ----- src/shared-configs/SpaceAllowedFormats.ts | 11 ----- src/shared-configs/SpaceRestrictedFormats.ts | 11 ----- src/shared-configs/index.ts | 7 ++- 5 files changed, 49 insertions(+), 38 deletions(-) create mode 100644 src/shared-configs/Formats.ts delete mode 100644 src/shared-configs/NonHighlightFormats.ts delete mode 100644 src/shared-configs/SpaceAllowedFormats.ts delete mode 100644 src/shared-configs/SpaceRestrictedFormats.ts diff --git a/src/shared-configs/Formats.ts b/src/shared-configs/Formats.ts new file mode 100644 index 0000000..4a0cd00 --- /dev/null +++ b/src/shared-configs/Formats.ts @@ -0,0 +1,46 @@ +import { Format } from "src/enums"; +import { BlockRules, InlineRules } from "src/shared-configs"; +import { BlockFormat, InlineFormat } from "src/types"; + +export const Formats = { + ALL: (() => { + let formats: Format[] = []; + for (let format in InlineRules) { formats.push(parseInt(format)) } + for (let format in BlockRules) { formats.push(parseInt(format)) } + return formats; + })(), + ALL_BLOCK: (() => { + let formats: BlockFormat[] = []; + for (let format in BlockRules) { formats.push(parseInt(format)) } + return formats; + })(), + ALL_INLINE: (() => { + let formats: InlineFormat[] = []; + for (let format in InlineRules) { formats.push(parseInt(format)) } + return formats; + })(), + SPACE_RESTRICTED_INLINE: (() => { + let formats: InlineFormat[] = []; + for (let format in InlineRules) { + let type = Number.parseInt(format) as InlineFormat; + if (!InlineRules[type].allowSpace) { formats.push(type) } + } + return formats; + })(), + SPACE_ALLOWED_INLINE: (() => { + let formats: InlineFormat[] = []; + for (let format in InlineRules) { + let type = Number.parseInt(format) as InlineFormat; + if (InlineRules[type].allowSpace) { formats.push(type) } + } + return formats; + })(), + NON_BUILTIN_INLINE: (() => { + let formats: InlineFormat[] = []; + for (let format in InlineRules) { + let type = Number.parseInt(format) as InlineFormat; + if (!InlineRules[type].builtin) { formats.push(type) } + } + return formats; + })() +} \ No newline at end of file diff --git a/src/shared-configs/NonHighlightFormats.ts b/src/shared-configs/NonHighlightFormats.ts deleted file mode 100644 index 5267f1d..0000000 --- a/src/shared-configs/NonHighlightFormats.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { MainFormat } from "src/types"; -import { FormatRules } from "src/shared-configs"; -import { Format } from "src/enums"; - -export const NonHighlightFormats = (() => { - let formats: MainFormat[] = []; - for (let format in FormatRules) { - let type = Number.parseInt(format) as MainFormat; - if (type != Format.HIGHLIGHT) { formats.push(type) } - } - return formats; -})(); \ No newline at end of file diff --git a/src/shared-configs/SpaceAllowedFormats.ts b/src/shared-configs/SpaceAllowedFormats.ts deleted file mode 100644 index 21dcf42..0000000 --- a/src/shared-configs/SpaceAllowedFormats.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { MainFormat } from "src/types"; -import { FormatRules } from "src/shared-configs"; - -export const SpaceAllowedFormats = (() => { - let formats: MainFormat[] = []; - for (let format in FormatRules) { - let type = Number.parseInt(format) as MainFormat; - if (FormatRules[type].allowSpace) { formats.push(type) } - } - return formats; -})(); \ No newline at end of file diff --git a/src/shared-configs/SpaceRestrictedFormats.ts b/src/shared-configs/SpaceRestrictedFormats.ts deleted file mode 100644 index 61b247a..0000000 --- a/src/shared-configs/SpaceRestrictedFormats.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { MainFormat } from "src/types"; -import { FormatRules } from "src/shared-configs"; - -export const SpaceRestrictedFormats = (() => { - let formats: MainFormat[] = []; - for (let format in FormatRules) { - let type = Number.parseInt(format) as MainFormat; - if (!FormatRules[type].allowSpace) { formats.push(type) } - } - return formats; -})(); \ No newline at end of file diff --git a/src/shared-configs/index.ts b/src/shared-configs/index.ts index c3ba1b2..8110930 100644 --- a/src/shared-configs/index.ts +++ b/src/shared-configs/index.ts @@ -1,4 +1,3 @@ -export * from "./FormatRules"; -export * from "./NonHighlightFormats"; -export * from "./SpaceAllowedFormats"; -export * from "./SpaceRestrictedFormats"; \ No newline at end of file +export * from "./InlineRules"; +export * from "./BlockRules"; +export * from "./Formats"; \ No newline at end of file