UNPKG

dmclc

Version:

Dolphin Minecraft Launcher Core

68 lines (67 loc) 3.35 kB
/* * Ported from Fabric Loader. * Copyright 2016 FabricMC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { SemanticVersion } from "./SemanticVersion.js"; import { SemanticVersionImpl } from "./SemanticVersionImpl.js"; class VersionComparisonOperator { test0; minVersion; maxVersion; // order is important to match the longest substring (e.g. try >= before >) static GREATER_EQUAL = new VersionComparisonOperator(">=", true, false, (a, b) => a.compareTo(b) >= 0, (version) => version); static LESS_EQUAL = new VersionComparisonOperator("<=", false, true, (a, b) => a.compareTo(b) <= 0, () => undefined, (version) => version); static GREATER = new VersionComparisonOperator(">", false, false, (a, b) => a.compareTo(b) > 0, (version) => version); static LESS = new VersionComparisonOperator("<", false, false, (a, b) => a.compareTo(b) < 0, () => undefined, (version) => version); static EQUAL = new VersionComparisonOperator("=", true, true, (a, b) => a.compareTo(b) == 0, (version) => version, (version) => version); static SAME_TO_NEXT_MINOR = new VersionComparisonOperator("~", true, false, (a, b) => a.compareTo(b) >= 0 && a.getVersionComponent(0) == b.getVersionComponent(0) && a.getVersionComponent(1) == b.getVersionComponent(1), (version) => version, (version) => new SemanticVersionImpl([version.getVersionComponent(0), version.getVersionComponent(1) + 1], "", null)); static SAME_TO_NEXT_MAJOR = new VersionComparisonOperator("^", true, false, (a, b) => a.compareTo(b) >= 0 && a.getVersionComponent(0) == b.getVersionComponent(0), (version) => version, (version) => new SemanticVersionImpl([version.getVersionComponent(0) + 1], "", null)); static values = [this.GREATER_EQUAL, this.LESS_EQUAL, this.GREATER, this.LESS, this.EQUAL, this.SAME_TO_NEXT_MINOR, this.SAME_TO_NEXT_MAJOR]; serialized; minInclusive; maxInclusive; constructor(serialized, minInclusive, maxInclusive, test0, minVersion = () => undefined, maxVersion = () => undefined) { this.test0 = test0; this.minVersion = minVersion; this.maxVersion = maxVersion; this.serialized = serialized; this.minInclusive = minInclusive; this.maxInclusive = maxInclusive; } getSerialized() { return this.serialized; } isMinInclusive() { return this.minInclusive; } isMaxInclusive() { return this.maxInclusive; } test(a, b) { if (a instanceof SemanticVersion && b instanceof SemanticVersion) { return this.test0(a, b); } else if (this.minInclusive || this.maxInclusive) { return a.getFriendlyString() === b.getFriendlyString(); } else { return false; } } } export { VersionComparisonOperator };