refactor: move all the format constants to Format.ts

This commit is contained in:
kotaindah55 2025-03-04 16:51:23 +02:00
parent 48fa008223
commit 0da3126283
5 changed files with 49 additions and 38 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -1,4 +1,3 @@
export * from "./FormatRules";
export * from "./NonHighlightFormats";
export * from "./SpaceAllowedFormats";
export * from "./SpaceRestrictedFormats";
export * from "./InlineRules";
export * from "./BlockRules";
export * from "./Formats";