grafana/public/app/core/utils/version.ts

35 lines
847 B
TypeScript
Raw Normal View History

2017-12-20 05:33:33 -06:00
import _ from 'lodash';
2017-10-20 08:25:19 -05:00
const versionPattern = /^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-([0-9A-Za-z\.]+))?/;
2017-10-20 07:50:44 -05:00
export class SemVersion {
major: number;
minor: number;
patch: number;
meta: string;
constructor(version: string) {
let match = versionPattern.exec(version);
if (match) {
this.major = Number(match[1]);
this.minor = Number(match[2] || 0);
this.patch = Number(match[3] || 0);
this.meta = match[4];
}
}
isGtOrEq(version: string): boolean {
let compared = new SemVersion(version);
return !(this.major < compared.major || this.minor < compared.minor || this.patch < compared.patch);
2017-10-20 07:50:44 -05:00
}
2017-10-20 08:25:19 -05:00
isValid(): boolean {
return _.isNumber(this.major);
}
2017-10-20 07:50:44 -05:00
}
export function isVersionGtOrEq(a: string, b: string): boolean {
let a_semver = new SemVersion(a);
return a_semver.isGtOrEq(b);
}