LocalVersionPopover.utils.ts28 lines · main
| 1 | type CLIVersionSemver = { major: number; minor: number; patch: number } |
| 2 | |
| 3 | // [Joshen] Specifically in the syntax of `v0.0.0` |
| 4 | export const getSemver = (version?: string) => { |
| 5 | if (!version) return undefined |
| 6 | const [major, minor, patch] = version.slice(1).split('.') |
| 7 | return { major: Number(major), minor: Number(minor), patch: Number(patch) } |
| 8 | } |
| 9 | |
| 10 | export const semverLte = (a: CLIVersionSemver, b: CLIVersionSemver) => { |
| 11 | if ( |
| 12 | a.major > b.major || |
| 13 | (a.major === b.major && a.minor > b.minor) || |
| 14 | (a.major === b.major && a.minor === b.minor && a.patch > b.patch) |
| 15 | ) |
| 16 | return false |
| 17 | return true |
| 18 | } |
| 19 | |
| 20 | export const semverGte = (a: CLIVersionSemver, b: CLIVersionSemver) => { |
| 21 | if ( |
| 22 | a.major < b.major || |
| 23 | (a.major === b.major && a.minor < b.minor) || |
| 24 | (a.major === b.major && a.minor === b.minor && a.patch < b.patch) |
| 25 | ) |
| 26 | return false |
| 27 | return true |
| 28 | } |