Socket
Socket
Sign inDemoInstall

sls-version

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.1 to 2.0.0

3

lib/index.d.ts

@@ -17,2 +17,3 @@ /**

*/
export * from "./public";
export * from "./slsVersion";
export * from "./slsVersionMatcher";

@@ -22,3 +22,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./public"));
__export(require("./slsVersion"));
__export(require("./slsVersionMatcher"));
//# sourceMappingURL=index.js.map

@@ -29,48 +29,21 @@ /**

snapshot: number | undefined;
/** Snapshot hash string. */
hash: string | undefined;
/** Unorderable */
unorderable: boolean;
/** orderable */
orderable: boolean;
}
/** Parse an SLS version string. */
export declare function parse(version: string): ISlsVersion;
/** Returns true if the parsed SLS version is valid. */
export declare function isValid(version: ISlsVersion): boolean;
/** Determine if a version is a release candidate. */
export declare function isReleaseCandidate(version: ISlsVersion): version is ISlsVersion & {
rc: number;
};
/** Determine if a version is a snapshot version. */
export declare function isSnapshot(version: ISlsVersion): version is ISlsVersion & {
snapshot: number;
};
/** Determine if a version is an RC but not a snapshot. */
export declare function isNormalReleaseCandidate(version: ISlsVersion): version is ISlsVersion & {
rc: number;
snapshot: undefined;
};
/** Determine if a version is neither an RC or a snapshot. */
export declare function isNormalRelease(version: ISlsVersion): version is ISlsVersion & {
rc: undefined;
snapshot: undefined;
};
/** Determine if a version is a snapshot but not an RC. */
export declare function isNormalSnapshot(version: ISlsVersion): version is ISlsVersion & {
rc: undefined;
snapshot: number;
};
/** Determine if a version is both a snapshot and an RC. */
export declare function isReleaseCandidateSnapshot(version: ISlsVersion): version is ISlsVersion & {
rc: number;
snapshot: number;
};
/** Returns true if `lhs > rhs`. */
export declare function gt(lhs: ISlsVersion, rhs: ISlsVersion): boolean;
/** Return true if `lhs` = `rhs`. */
export declare function eq(lhs: ISlsVersion, rhs: ISlsVersion): boolean;
/** Return true if `lhs >= rhs`. */
export declare function gte(lhs: ISlsVersion, rhs: ISlsVersion): boolean;
/** Returns true if `lhs < rhs`. */
export declare function lt(lhs: ISlsVersion, rhs: ISlsVersion): boolean;
/** Returns true if `lhs <= rhs`. */
export declare function lte(lhs: ISlsVersion, rhs: ISlsVersion): boolean;
export declare class SlsVersion implements ISlsVersion {
private readonly value;
readonly major: number;
readonly minor: number;
readonly patch: number;
readonly rc: number | undefined;
readonly snapshot: number | undefined;
readonly orderable: boolean;
private static MATCHER;
static of(version: string): SlsVersion;
static safeValueOf(version: string): SlsVersion | null;
static isValid(version: string): boolean;
private constructor();
compare(other: ISlsVersion): -1 | 0 | 1;
toString(): string;
private static compareNullable(a, b, defaultValue);
}

@@ -19,120 +19,93 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
/** Parse an SLS version string. */
function parse(version) {
// Parse the version string as an SLS version
var match = version.match(/^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-rc([0-9]+))?(?:-([0-9]+)-g([a-f0-9]+))?(\.dirty)?$/);
if (null == match) {
throw new Error("Invalid SLS version: \"" + version + "\"");
var SlsVersion = /** @class */ (function () {
function SlsVersion(value, major, minor, patch, rc, snapshot, orderable) {
this.value = value;
this.major = major;
this.minor = minor;
this.patch = patch;
this.rc = rc;
this.snapshot = snapshot;
this.orderable = orderable;
}
var major = match[1], minor = match[2], patch = match[3], rc = match[4], snapshot = match[5], hash = match[6], dirty = match[7];
var parsedVersion = {
hash: hash,
major: parseInt(major, undefined),
minor: parseInt(minor, undefined),
patch: parseInt(patch, undefined),
rc: undefined !== rc ? parseInt(rc, undefined) : undefined,
snapshot: undefined !== snapshot ? parseInt(snapshot, undefined) : undefined,
unorderable: Boolean(dirty),
SlsVersion.of = function (version) {
var slsVersion = SlsVersion.safeValueOf(version);
if (slsVersion == null) {
throw new Error("Invalid SLS version: \"" + version + "\"");
}
return slsVersion;
};
if (!isValid(parsedVersion)) {
throw new Error("Invalid SLS version: \"" + version + "\"");
}
return parsedVersion;
}
exports.parse = parse;
/** Returns true if the parsed SLS version is valid. */
function isValid(version) {
return (null != version.major &&
null != version.minor &&
null != version.patch &&
((null == version.hash && null == version.snapshot) || (null !== version.hash && null != version.snapshot)));
}
exports.isValid = isValid;
/** Determine if a version is a release candidate. */
function isReleaseCandidate(version) {
return null != version.rc;
}
exports.isReleaseCandidate = isReleaseCandidate;
/** Determine if a version is a snapshot version. */
function isSnapshot(version) {
return null != version.snapshot;
}
exports.isSnapshot = isSnapshot;
/** Determine if a version is an RC but not a snapshot. */
function isNormalReleaseCandidate(version) {
return isReleaseCandidate(version) && !isSnapshot(version);
}
exports.isNormalReleaseCandidate = isNormalReleaseCandidate;
/** Determine if a version is neither an RC or a snapshot. */
function isNormalRelease(version) {
return !isReleaseCandidate(version) && !isSnapshot(version);
}
exports.isNormalRelease = isNormalRelease;
/** Determine if a version is a snapshot but not an RC. */
function isNormalSnapshot(version) {
return !isReleaseCandidate(version) && isSnapshot(version);
}
exports.isNormalSnapshot = isNormalSnapshot;
/** Determine if a version is both a snapshot and an RC. */
function isReleaseCandidateSnapshot(version) {
return isReleaseCandidate(version) && isSnapshot(version);
}
exports.isReleaseCandidateSnapshot = isReleaseCandidateSnapshot;
/** Returns true if `lhs > rhs`. */
function gt(lhs, rhs) {
if (lhs.unorderable || rhs.unorderable) {
throw Error("Attempting to comparing unorderable versions");
}
else if (lhs.major !== rhs.major) {
return lhs.major > rhs.major;
}
else if (lhs.minor !== rhs.minor) {
return lhs.minor > rhs.minor;
}
else if (lhs.patch !== rhs.patch) {
return lhs.patch > rhs.patch;
}
else if (isNormalSnapshot(lhs) && isNormalRelease(rhs)) {
return true;
}
else if (isNormalRelease(lhs) && isNormalReleaseCandidate(rhs)) {
return true;
}
else if (isNormalSnapshot(lhs) && isNormalSnapshot(rhs) && lhs.snapshot !== rhs.snapshot) {
return lhs.snapshot > rhs.snapshot;
}
else if (isReleaseCandidate(lhs) && isReleaseCandidate(rhs) && lhs.rc !== rhs.rc) {
return lhs.rc > rhs.rc;
}
else if (isReleaseCandidateSnapshot(lhs) && isNormalReleaseCandidate(rhs)) {
return true;
}
else if (isReleaseCandidateSnapshot(lhs) && isReleaseCandidateSnapshot(rhs)) {
return lhs.snapshot > rhs.snapshot;
}
else {
return false;
}
}
exports.gt = gt;
/** Return true if `lhs` = `rhs`. */
function eq(lhs, rhs) {
return !gt(lhs, rhs) && !gt(rhs, lhs);
}
exports.eq = eq;
/** Return true if `lhs >= rhs`. */
function gte(lhs, rhs) {
return gt(lhs, rhs) || eq(lhs, rhs);
}
exports.gte = gte;
/** Returns true if `lhs < rhs`. */
function lt(lhs, rhs) {
return gt(rhs, lhs) && !eq(lhs, rhs);
}
exports.lt = lt;
/** Returns true if `lhs <= rhs`. */
function lte(lhs, rhs) {
return gt(rhs, lhs) || eq(lhs, rhs);
}
exports.lte = lte;
SlsVersion.safeValueOf = function (version) {
// Parse the version string as an SLS version
var match = version.match(SlsVersion.MATCHER);
if (match == null) {
return null;
}
var major = match[1], minor = match[2], patch = match[3], rc = match[4], snapshot = match[5], hash = match[6], dirty = match[7];
var majorVersion = parseInt(major, undefined);
var minorVersion = parseInt(minor, undefined);
var patchVersion = parseInt(patch, undefined);
var rcNumber = rc != null ? parseInt(rc, undefined) : undefined;
var snapshotNumber = snapshot != null ? parseInt(snapshot, undefined) : undefined;
if (major == null ||
minor == null ||
patch == null ||
(hash != null && snapshot == null) ||
(hash == null && snapshot != null)) {
return null;
}
return new SlsVersion(version, majorVersion, minorVersion, patchVersion, rcNumber, snapshotNumber, !Boolean(dirty));
};
SlsVersion.isValid = function (version) {
return SlsVersion.safeValueOf(version) != null;
};
SlsVersion.prototype.compare = function (other) {
if (!this.orderable || !other.orderable) {
throw Error("Attempting to comparing unorderable versions");
}
else if (this.major !== other.major) {
return this.major > other.major ? 1 : -1;
}
else if (this.minor !== other.minor) {
return this.minor > other.minor ? 1 : -1;
}
else if (this.patch !== other.patch) {
return this.patch > other.patch ? 1 : -1;
}
var compareRc = SlsVersion.compareNullable(this.rc, other.rc, 1);
if (compareRc !== 0) {
return compareRc;
}
var compareSnapshot = SlsVersion.compareNullable(this.snapshot, other.snapshot, -1);
if (compareSnapshot !== 0 ||
(this.snapshot == null && other.snapshot == null) ||
(this.snapshot != null && other.snapshot != null)) {
return compareSnapshot;
}
if (this.snapshot != null) {
return 1;
}
else if (other.snapshot != null) {
return -1;
}
return 0;
};
SlsVersion.prototype.toString = function () {
return this.value;
};
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)?$/;
return SlsVersion;
}());
exports.SlsVersion = SlsVersion;
//# sourceMappingURL=slsVersion.js.map

@@ -27,10 +27,13 @@ /**

export declare class SlsVersionMatcher implements ISlsVersionMatcher {
private value;
major: number | undefined;
minor: number | undefined;
patch: number | undefined;
private static MATCHER;
static safeValueOf(versionMatcher: string): SlsVersionMatcher | null;
static parse(versionMatcher: string): SlsVersionMatcher;
static of(versionMatcher: string): SlsVersionMatcher;
private constructor();
matches(version: ISlsVersion): boolean;
compare(version: ISlsVersion): 0 | 1 | -1;
compare(version: ISlsVersion): -1 | 0 | 1;
toString(): string;
}

@@ -21,3 +21,4 @@ "use strict";

var SlsVersionMatcher = /** @class */ (function () {
function SlsVersionMatcher(major, minor, patch) {
function SlsVersionMatcher(value, major, minor, patch) {
this.value = value;
this.major = major;

@@ -29,3 +30,3 @@ this.minor = minor;

try {
return SlsVersionMatcher.parse(versionMatcher);
return SlsVersionMatcher.of(versionMatcher);
}

@@ -36,4 +37,4 @@ catch (error) {

};
SlsVersionMatcher.parse = function (versionMatcher) {
var match = versionMatcher.match(/^([0-9]+|x)\.([0-9]+|x)\.([0-9]+|x)$/);
SlsVersionMatcher.of = function (versionMatcher) {
var match = versionMatcher.match(this.MATCHER);
if (match == null) {

@@ -67,3 +68,3 @@ throw new Error("Invalid SLS version match: \"" + versionMatcher + "\"");

}
return new SlsVersionMatcher(slsVersionMatcher.major, slsVersionMatcher.minor, slsVersionMatcher.patch);
return new SlsVersionMatcher(versionMatcher, slsVersionMatcher.major, slsVersionMatcher.minor, slsVersionMatcher.patch);
};

@@ -79,20 +80,3 @@ SlsVersionMatcher.prototype.matches = function (version) {

if (this.major !== undefined && this.minor !== undefined && this.patch !== undefined) {
var versionMatcherVersion = {
hash: undefined,
major: this.major,
minor: this.minor,
patch: this.patch,
rc: undefined,
snapshot: undefined,
unorderable: false,
};
if (slsVersion_1.eq(version, versionMatcherVersion)) {
return 0;
}
else if (slsVersion_1.gt(version, versionMatcherVersion)) {
return 1;
}
else {
return -1;
}
return slsVersion_1.SlsVersion.of(this.value).compare(version);
}

@@ -119,2 +103,6 @@ if (this.major !== undefined) {

};
SlsVersionMatcher.prototype.toString = function () {
return this.value;
};
SlsVersionMatcher.MATCHER = /^([0-9]+|x)\.([0-9]+|x)\.([0-9]+|x)$/;
return SlsVersionMatcher;

@@ -121,0 +109,0 @@ }());

{
"name": "sls-version",
"version": "1.1.1",
"version": "2.0.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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc