-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsemver.ts
More file actions
39 lines (36 loc) · 899 Bytes
/
semver.ts
File metadata and controls
39 lines (36 loc) · 899 Bytes
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
31
32
33
34
35
36
37
38
39
/**
* @fileoverview Semver-aware string comparison. Wraps the vendored
* `external/semver` accessor so callers don't have to thread the
* lazy-load themselves.
*/
import { getSemver } from './_internal'
/**
* Compare semantic versions.
*
* @example
* ```typescript
* compareSemver('1.0.0', '2.0.0') // -1
* compareSemver('2.0.0', '1.0.0') // 1
* compareSemver('1.0.0', '1.0.0') // 0
* ```
*/
/*@__NO_SIDE_EFFECTS__*/
export function compareSemver(a: string, b: string): number {
// External semver calls
/* c8 ignore start */
const semver = getSemver()
const validA: string | null = semver.valid(a)
/* c8 ignore stop */
const validB: string | null = semver.valid(b)
if (!validA && !validB) {
return 0
}
if (!validA) {
return -1
}
if (!validB) {
return 1
}
/* c8 ignore next - External semver call */
return semver.compare(a, b) as number
}