Skip to content

Commit 1999963

Browse files
committed
minecraft version stuff
1 parent 9a35b23 commit 1999963

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

src/mcver.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** Returns if the string is in the form of a Minecraft version. */
1+
/** Returns whether the string is in the form of a Minecraft version. */
22
export function mcverIsValid(version: string, include_snapshots: boolean = false): boolean {
33
// snapshot testing
44
if (version.split(".").length === 1) {
@@ -11,14 +11,14 @@ export function mcverIsValid(version: string, include_snapshots: boolean = false
1111
return false;
1212
}
1313

14-
/** Returns if the string is in the form of a major Minecraft version, or null if the string is not a valid version. */
14+
/** Returns whether the string is in the form of a major Minecraft version, or null if the string is not a valid version. */
1515
export function mcverIsMajor(version: string): boolean | null {
1616
if (!mcverIsValid(version)) return null;
1717
if (/^1\.[1-9][0-9]?$/.test(version)) return true;
1818
return false;
1919
}
2020

21-
/** Returns if the string is in the form of a minor Minecraft version, or null if the string is not a valid version. */
21+
/** Returns whether the string is in the form of a minor Minecraft version, or null if the string is not a valid version. */
2222
export function mcverIsMinor(version: string): boolean | null {
2323
if (!mcverIsValid(version)) return null;
2424
if (/^1\.[1-9][0-9]?\.[1-9][0-9]?$/.test(version)) return true;
@@ -32,14 +32,14 @@ export function mcverGetMajor(version: string): string | null {
3232
else return /^1\.[1-9][0-9]?(?=\.)/.exec(version)![0];
3333
}
3434

35-
/** Returns if a minor version is of the major version, null if the specified minor version isn't a minor version or the major one isn't a major one. */
35+
/** Returns whether a minor version is of a major version, null if the specified minor version isn't a minor version or the major one isn't a major one. */
3636
export function mcverMinorBelongsToMajor(minor: string, major: string): boolean | null {
3737
if (!mcverIsMinor(minor) || !mcverIsMajor(major)) return null;
3838
if (mcverGetMajor(minor) == major) return true;
3939
else return false;
4040
}
4141

42-
/** Returns if the two versions are of the same major release. */
42+
/** Returns whether the two versions are of the same major release. */
4343
export function mcversSameMajor(version1: string, version2: string): boolean | null {
4444
if (!mcverIsValid(version1) || !mcverIsValid(version2)) return null;
4545
else return mcverGetMajor(version1) == mcverGetMajor(version2);
@@ -56,4 +56,12 @@ export function mcverSanitize(text: string): string | null {
5656
}
5757
if (mcverIsValid(text)) return text;
5858
else return null;
59+
}
60+
61+
export function mcverAsNumber(version: string): number | null {
62+
if (!mcverIsValid(version)) return null;
63+
const major = parseInt(/(?<=^1\.)[1-9][0-9]?(?=\.[1-9][0-9]?)?/.exec(version)![0]) * 100;
64+
let minor = 0;
65+
if (/(?<=[1-9]\.)[1-9][0-9]?$/.test(version)) minor = parseInt(/(?<=[1-9]\.)[1-9][0-9]?$/.exec(version)![0]);
66+
return major + minor;
5967
}

0 commit comments

Comments
 (0)