|
@ -5,6 +5,7 @@ export namespace Versions { |
|
|
major: number; |
|
|
major: number; |
|
|
minor: number; |
|
|
minor: number; |
|
|
patch: number; |
|
|
patch: number; |
|
|
|
|
|
pre?: string; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export function compare(v1: Version, v2: Version): number { |
|
|
export function compare(v1: Version, v2: Version): number { |
|
@ -17,19 +18,26 @@ export namespace Versions { |
|
|
if (v1.patch > v2.patch) return 1; |
|
|
if (v1.patch > v2.patch) return 1; |
|
|
if (v1.patch < v2.patch) return -1; |
|
|
if (v1.patch < v2.patch) return -1; |
|
|
|
|
|
|
|
|
|
|
|
if (v1.pre === undefined && v2.pre !== undefined) return 1; |
|
|
|
|
|
if (v1.pre !== undefined && v2.pre === undefined) return -1; |
|
|
|
|
|
|
|
|
|
|
|
if (v1.pre !== undefined && v2.pre !== undefined) return v1.pre.localeCompare(v2.pre); |
|
|
|
|
|
|
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export function from(major: string | number, minor: string | number, patch: string | number): Version { |
|
|
|
|
|
|
|
|
export function from(major: string | number, minor: string | number, patch: string | number, pre?: string): Version { |
|
|
return { |
|
|
return { |
|
|
major: typeof major === 'string' ? parseInt(major, 10) : major, |
|
|
major: typeof major === 'string' ? parseInt(major, 10) : major, |
|
|
minor: typeof minor === 'string' ? parseInt(minor, 10) : minor, |
|
|
minor: typeof minor === 'string' ? parseInt(minor, 10) : minor, |
|
|
patch: typeof patch === 'string' ? parseInt(patch, 10) : patch |
|
|
|
|
|
|
|
|
patch: typeof patch === 'string' ? parseInt(patch, 10) : patch, |
|
|
|
|
|
pre: pre |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export function fromString(version: string): Version { |
|
|
export function fromString(version: string): Version { |
|
|
const [major, minor, patch] = version.split('.'); |
|
|
|
|
|
return from(major, minor, patch); |
|
|
|
|
|
|
|
|
const [ver, pre] = version.split('-'); |
|
|
|
|
|
const [major, minor, patch] = ver.split('.'); |
|
|
|
|
|
return from(major, minor, patch, pre); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |