-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathangular-version-comparer.ts
More file actions
30 lines (27 loc) · 1.07 KB
/
angular-version-comparer.ts
File metadata and controls
30 lines (27 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import {AngularVersion} from './types/angular-version';
/**
*
* Compares two angular versions, A and B. Based on their minor and major versions.
*
*
* @export
* @param {AngularVersion} versionA
* @param {AngularVersion} versionB
* @return {number} > 0 if A is newer, 0 if they are the same version, < 0 if A is older
*/
export function angularVersionComparer(
versionA: AngularVersion,
versionB: AngularVersion
): number {
// Gets the major and minor versions
const [majorA, minorA] = versionA.split('.');
const [majorB, minorB] = versionB.split('.');
// Obtains the major version difference between versions A and B
const majorDifference =
Number.parseInt(majorA, 10) - Number.parseInt(majorB, 10);
// Obtains the minor version difference between versions A and B
const minorDifference =
Number.parseInt(minorA, 10) - Number.parseInt(minorB, 10);
// If the major versions are different use the major version difference to compare, if they are equal use the minor version difference
return majorDifference === 0 ? minorDifference : majorDifference;
}