version.ts 758 B

12345678910111213141516171819202122232425262728
  1. const versionPattern = /(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-([0-9A-Za-z\.]+))?/;
  2. export class SemVersion {
  3. major: number;
  4. minor: number;
  5. patch: number;
  6. meta: string;
  7. constructor(version: string) {
  8. let match = versionPattern.exec(version);
  9. if (match) {
  10. this.major = Number(match[1]);
  11. this.minor = Number(match[2] || 0);
  12. this.patch = Number(match[3] || 0);
  13. this.meta = match[4];
  14. }
  15. }
  16. isGtOrEq(version: string): boolean {
  17. let compared = new SemVersion(version);
  18. return !(this.major < compared.major || this.minor < compared.minor || this.patch < compared.patch);
  19. }
  20. }
  21. export function isVersionGtOrEq(a: string, b: string): boolean {
  22. let a_semver = new SemVersion(a);
  23. return a_semver.isGtOrEq(b);
  24. }