-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e79603f
commit 6925231
Showing
4 changed files
with
817 additions
and
604 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// copied from Azure Data Explorer plugin | ||
import { isNumber } from 'lodash'; | ||
|
||
const versionPattern = /^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-([0-9A-Za-z\.]+))?/; | ||
|
||
export class SemVersion { | ||
major: number; | ||
minor: number; | ||
patch: number; | ||
meta: string; | ||
|
||
constructor(version: string) { | ||
this.major = 0; | ||
this.minor = 0; | ||
this.patch = 0; | ||
this.meta = ''; | ||
|
||
const 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 { | ||
const compared = new SemVersion(version); | ||
|
||
for (let i = 0; i < this.comparable.length; ++i) { | ||
if (this.comparable[i] > compared.comparable[i]) { | ||
return true; | ||
} | ||
if (this.comparable[i] < compared.comparable[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
isValid(): boolean { | ||
return isNumber(this.major); | ||
} | ||
|
||
get comparable() { | ||
return [this.major, this.minor, this.patch]; | ||
} | ||
} | ||
|
||
export function isVersionGtOrEq(a: string, b: string): boolean { | ||
const aSemver = new SemVersion(a); | ||
return aSemver.isGtOrEq(b); | ||
} |
Oops, something went wrong.