sls-version
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -1,17 +0,1 @@ | ||
/** | ||
* @license | ||
* Copyright 2018 Palantir Technologies, Inc. | ||
* | ||
* 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. | ||
*/ | ||
/** Parsed SLS version. */ | ||
@@ -41,2 +25,4 @@ export interface ISlsVersion { | ||
private static MATCHER; | ||
private static ABSENT_IS_GREATER; | ||
private static ABSENT_IS_LESSER; | ||
static of(version: string): SlsVersion; | ||
@@ -48,3 +34,2 @@ static safeValueOf(version: string): SlsVersion | null; | ||
toString(): string; | ||
private static compareNullable(a, b, defaultValue); | ||
} |
@@ -19,2 +19,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var comparison_1 = require("./comparison"); | ||
var SlsVersion = /** @class */ (function () { | ||
@@ -74,7 +75,7 @@ function SlsVersion(value, major, minor, patch, rc, snapshot, orderable) { | ||
} | ||
var compareRc = SlsVersion.compareNullable(this.rc, other.rc, 1); | ||
var compareRc = comparison_1.compareNullable(this.rc, other.rc, SlsVersion.ABSENT_IS_GREATER); | ||
if (compareRc !== 0) { | ||
return compareRc; | ||
} | ||
var compareSnapshot = SlsVersion.compareNullable(this.snapshot, other.snapshot, -1); | ||
var compareSnapshot = comparison_1.compareNullable(this.snapshot, other.snapshot, SlsVersion.ABSENT_IS_LESSER); | ||
if (compareSnapshot !== 0 || | ||
@@ -96,15 +97,5 @@ (this.snapshot == null && other.snapshot == null) || | ||
}; | ||
SlsVersion.compareNullable = function (a, b, defaultValue) { | ||
if (a === b) { | ||
return 0; | ||
} | ||
else if (a == null || b == null) { | ||
if (a == null) { | ||
return defaultValue; | ||
} | ||
return -defaultValue; | ||
} | ||
return a > b ? 1 : -1; | ||
}; | ||
SlsVersion.MATCHER = /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-rc([0-9]+))?(?:-([0-9]+)-g([a-f0-9]+))?(\.dirty)?$/; | ||
SlsVersion.ABSENT_IS_GREATER = function (t) { return (t == null ? Number.MAX_SAFE_INTEGER : t); }; | ||
SlsVersion.ABSENT_IS_LESSER = function (t) { return (t == null ? Number.MIN_VALUE : t); }; | ||
return SlsVersion; | ||
@@ -111,0 +102,0 @@ }()); |
@@ -1,17 +0,1 @@ | ||
/** | ||
* @license | ||
* Copyright 2018 Palantir Technologies, Inc. | ||
* | ||
* 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 { ISlsVersion } from "./slsVersion"; | ||
@@ -32,2 +16,3 @@ export interface ISlsVersionMatcher { | ||
private static MATCHER; | ||
private static ABSENT_IS_GREATER; | ||
static safeValueOf(versionMatcher: string): SlsVersionMatcher | null; | ||
@@ -37,4 +22,5 @@ static of(versionMatcher: string): SlsVersionMatcher; | ||
matches(version: ISlsVersion): boolean; | ||
compare(version: ISlsVersion): -1 | 0 | 1; | ||
compare(version: ISlsVersion | ISlsVersionMatcher): -1 | 0 | 1; | ||
private compareSlsVersion(version); | ||
toString(): string; | ||
} |
@@ -19,2 +19,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var comparison_1 = require("./comparison"); | ||
var slsVersion_1 = require("./slsVersion"); | ||
@@ -75,3 +76,21 @@ var SlsVersionMatcher = /** @class */ (function () { | ||
SlsVersionMatcher.prototype.compare = function (version) { | ||
// we can just compare these 2 as SLS versions | ||
if (isSlsVersion(version)) { | ||
return this.compareSlsVersion(version); | ||
} | ||
var comparison; | ||
comparison = comparison_1.compareNullable(this.major, version.major, SlsVersionMatcher.ABSENT_IS_GREATER); | ||
if (comparison !== 0) { | ||
return comparison; | ||
} | ||
comparison = comparison_1.compareNullable(this.minor, version.minor, SlsVersionMatcher.ABSENT_IS_GREATER); | ||
if (comparison !== 0) { | ||
return comparison; | ||
} | ||
comparison = comparison_1.compareNullable(this.patch, version.patch, SlsVersionMatcher.ABSENT_IS_GREATER); | ||
if (comparison !== 0) { | ||
return comparison; | ||
} | ||
return 0; | ||
}; | ||
SlsVersionMatcher.prototype.compareSlsVersion = function (version) { | ||
if (this.major !== undefined && this.minor !== undefined && this.patch !== undefined) { | ||
@@ -104,5 +123,9 @@ return slsVersion_1.SlsVersion.of(this.value).compare(version); | ||
SlsVersionMatcher.MATCHER = /^([0-9]+|x)\.([0-9]+|x)\.([0-9]+|x)$/; | ||
SlsVersionMatcher.ABSENT_IS_GREATER = function (t) { return (t == null ? Number.MAX_SAFE_INTEGER : t); }; | ||
return SlsVersionMatcher; | ||
}()); | ||
exports.SlsVersionMatcher = SlsVersionMatcher; | ||
function isSlsVersion(version) { | ||
return version.orderable != null; | ||
} | ||
function compareNumbers(lhs, rhs) { | ||
@@ -109,0 +132,0 @@ return lhs === rhs ? 0 : lhs < rhs ? -1 : 1; |
{ | ||
"name": "sls-version", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Typescript utilities for manipulating SLS versions", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
40791
15
344