Published source
Download source ZIP
CH-J Server Manager
Browse directories and files for a specific application release.
Source is provided under the CH-J Proprietary Software License 1.14. Its availability does not change the license terms or grant additional rights.
1
"use strict";3
const VERSION_PATTERN = /^v?(\d+)\.(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;5
function parseVersion(input) {6
const raw = String(input || "").trim();7
const match = VERSION_PATTERN.exec(raw);8
if (!match) {9
throw new Error(`Invalid version: ${raw || "<empty>"}`);10
}12
return {13
raw: raw.replace(/^v/i, ""),14
numbers: [match[1], match[2], match[3] || "0", match[4] || "0"].map(Number),15
prerelease: match[5] ? match[5].split(".") : []16
};17
}19
function comparePrerelease(left, right) {20
if (left.length === 0 && right.length === 0) return 0;21
if (left.length === 0) return 1;22
if (right.length === 0) return -1;24
const length = Math.max(left.length, right.length);25
for (let index = 0; index < length; index += 1) {26
if (left[index] === undefined) return -1;27
if (right[index] === undefined) return 1;28
if (left[index] === right[index]) continue;30
const leftNumeric = /^\d+$/.test(left[index]);31
const rightNumeric = /^\d+$/.test(right[index]);32
if (leftNumeric && rightNumeric) {33
return Number(left[index]) > Number(right[index]) ? 1 : -1;34
}35
if (leftNumeric !== rightNumeric) return leftNumeric ? -1 : 1;36
return left[index] > right[index] ? 1 : -1;37
}38
return 0;39
}41
function compareVersions(leftInput, rightInput) {42
const left = parseVersion(leftInput);43
const right = parseVersion(rightInput);45
for (let index = 0; index < left.numbers.length; index += 1) {46
if (left.numbers[index] === right.numbers[index]) continue;47
return left.numbers[index] > right.numbers[index] ? 1 : -1;48
}49
return comparePrerelease(left.prerelease, right.prerelease);50
}52
module.exports = {53
VERSION_PATTERN,54
compareVersions,55
parseVersion56
};SHA-256: f72255fe2089bfcd9cdd4727c5a47e9e563195db470dbe8073ebe311aa120804
Archive SHA-256: 5ac91caf4fa32a6fdb114f2430deed486fbe7489d5eea343d1f034169fafb5e0