Total Complexity | 9 |
Complexity/F | 1.8 |
Lines of Code | 27 |
Function Count | 5 |
Duplicated Lines | 0 |
Ratio | 0 % |
Coverage | 100% |
Changes | 0 |
1 | import { compare } from 'compare-versions'; |
||
2 | import { identity, memoizeWith } from 'ramda'; |
||
3 | import { hasValue } from '../utils'; |
||
4 | |||
5 | 5 | export const versionMatch = (versionToMatch, { maxVersion, minVersion }) => { |
|
6 | 41 | if (!hasValue(versionToMatch)) { |
|
7 | 24 | return false; |
|
8 | } |
||
9 | |||
10 | 17 | const matchesMinVersion = !minVersion || compare(versionToMatch, minVersion, '>='); |
|
11 | 17 | const matchesMaxVersion = !maxVersion || compare(versionToMatch, maxVersion, '<='); |
|
12 | |||
13 | 17 | return !!(matchesMaxVersion && matchesMinVersion); |
|
14 | }; |
||
15 | |||
16 | 5 | const versionIsValidSemVer = memoizeWith(identity, (version) => { |
|
17 | 9 | try { |
|
18 | 9 | return compare(version, version, '='); |
|
19 | } catch (e) { |
||
20 | 5 | return false; |
|
21 | } |
||
22 | }); |
||
23 | |||
24 | 9 | export const versionToPrintable = (version) => !versionIsValidSemVer(version) ? version : `v${version}`; |
|
25 | |||
26 | 5 | export const versionToSemVer = (defaultValue = 'latest') => |
|
27 | (version) => versionIsValidSemVer(version) ? version : defaultValue; |
||
28 |