aboutsummaryrefslogtreecommitdiff
path: root/src/app/js/misc.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2023-01-29 00:30:13 +0100
committer0neGal <mail@0negal.com>2023-01-29 00:30:13 +0100
commitb4615926e88562461aad1a94520919a48de934e9 (patch)
treef3ecd4b10c4828834f4379f4d410d7ae25919307 /src/app/js/misc.js
parent542186aad67a59d54c973c8fad625ac4f7285016 (diff)
downloadViper-b4615926e88562461aad1a94520919a48de934e9.tar.gz
Viper-b4615926e88562461aad1a94520919a48de934e9.zip
simplify and fix checking package versions
Previously some outdated packages would just say "Re-Install" and not "Update", now that's fixed, along with making the logic easier for use in the mod list.
Diffstat (limited to 'src/app/js/misc.js')
-rw-r--r--src/app/js/misc.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/app/js/misc.js b/src/app/js/misc.js
new file mode 100644
index 0000000..b35f239
--- /dev/null
+++ b/src/app/js/misc.js
@@ -0,0 +1,44 @@
+version = {
+ is_newer: (version1, version2) => {
+ version1 = version.format(version1, true).split(".");
+ version2 = version.format(version2, true).split(".");
+
+ for (let i = 0; i < version1.length; i++) {
+
+
+ let nums = [
+ parseInt(version1[i]) || 0,
+ parseInt(version2[i]) || 0
+ ];
+ if (nums[0] > nums[1]) {
+ return true;
+ } else if (nums[0] < nums[1]) {
+ return false;
+ }
+ }
+
+ return false;
+ },
+ format: (version_number, no_leading_v) => {
+ version_number = version_number.trim();
+
+ if (no_leading_v) {
+ if (version_number[0] == "v") {
+ return version_number.slice(1, version_number.length);
+ }
+
+ return version_number;
+ if (no_leading_v) {
+ return version_number
+ }
+
+ return "v" + version_number;
+ } else {
+ if (version_number[0] != "v") {
+ return "v" + version_number;
+ }
+ }
+
+ return version_number;
+ }
+}