diff --git a/src/platforms/platform-type.ts b/src/platforms/platform-type.ts new file mode 100644 index 0000000..d7ea53d --- /dev/null +++ b/src/platforms/platform-type.ts @@ -0,0 +1,61 @@ +import { Enum, EnumOptions } from "@/utils/enum"; + +/** + * Represents different platform types for mod distribution. + * + * @partial + */ +enum PlatformTypeValues { + /** + * Represents CurseForge. + */ + CURSEFORGE = "curseforge", + + /** + * Represents Modrinth. + */ + MODRINTH = "modrinth", + + /** + * Represents GitHub. + */ + GITHUB = "github", +} + +/** + * Options for configuring the behavior of the `PlatformType` enum. + * + * @partial + */ +const PlatformTypeOptions: EnumOptions = { + /** + * The case should be ignored while parsing the platform type. + */ + ignoreCase: true, + + /** + * Non-word characters should be ignored while parsing the platform type. + */ + ignoreNonWordCharacters: true, + + /** + * Custom friendly names for keys that don't follow the general naming convention. + */ + names: [ + ["CURSEFORGE", "CurseForge"], + ["GITHUB", "GitHub"], + ], +}; + +/** + * Represents different platform types for mod distribution. + */ +export const PlatformType = Enum.create( + PlatformTypeValues, + PlatformTypeOptions, +); + +/** + * Represents different platform types for mod distribution. + */ +export type PlatformType = Enum; diff --git a/src/publishing/publisher-target.ts b/src/publishing/publisher-target.ts deleted file mode 100644 index 3c5de55..0000000 --- a/src/publishing/publisher-target.ts +++ /dev/null @@ -1,17 +0,0 @@ -enum PublisherTarget { - CurseForge, - Modrinth, - GitHub, -} - -namespace PublisherTarget { - export function getValues(): PublisherTarget[] { - return Object.values(PublisherTarget).filter(x => !isNaN(+x)); - } - - export function toString(target: PublisherTarget): string { - return PublisherTarget[target] || target.toString(); - } -} - -export default PublisherTarget; diff --git a/tests/unit/platforms/platform-type.spec.ts b/tests/unit/platforms/platform-type.spec.ts new file mode 100644 index 0000000..a40818a --- /dev/null +++ b/tests/unit/platforms/platform-type.spec.ts @@ -0,0 +1,29 @@ +import { PlatformType } from "@/platforms/platform-type"; + +describe("PlatformType", () => { + describe("parse", () => { + test("parses all its own formatted values", () => { + for (const value of PlatformType.values()) { + expect(PlatformType.parse(PlatformType.format(value))).toBe(value); + } + }); + + test("parses all friendly names of its own values", () => { + for (const value of PlatformType.values()) { + expect(PlatformType.parse(PlatformType.friendlyNameOf(value))).toBe(value); + } + }); + + test("parses all its own formatted values in lowercase", () => { + for (const value of PlatformType.values()) { + expect(PlatformType.parse(PlatformType.format(value).toLowerCase())).toBe(value); + } + }); + + test("parses all its own formatted values in UPPERCASE", () => { + for (const value of PlatformType.values()) { + expect(PlatformType.parse(PlatformType.format(value).toUpperCase())).toBe(value); + } + }); + }); +});