mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-21 16:00:59 -05:00
Refactored PublisherTarget
(-> PlatformType
)
This commit is contained in:
parent
390914e813
commit
90564b0aa2
3 changed files with 90 additions and 17 deletions
61
src/platforms/platform-type.ts
Normal file
61
src/platforms/platform-type.ts
Normal file
|
@ -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<typeof PlatformTypeValues>;
|
|
@ -1,17 +0,0 @@
|
|||
enum PublisherTarget {
|
||||
CurseForge,
|
||||
Modrinth,
|
||||
GitHub,
|
||||
}
|
||||
|
||||
namespace PublisherTarget {
|
||||
export function getValues(): PublisherTarget[] {
|
||||
return <PublisherTarget[]>Object.values(PublisherTarget).filter(x => !isNaN(+x));
|
||||
}
|
||||
|
||||
export function toString(target: PublisherTarget): string {
|
||||
return PublisherTarget[target] || target.toString();
|
||||
}
|
||||
}
|
||||
|
||||
export default PublisherTarget;
|
29
tests/unit/platforms/platform-type.spec.ts
Normal file
29
tests/unit/platforms/platform-type.spec.ts
Normal file
|
@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue