mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-26 19:08:23 +03:00
22 lines
750 B
TypeScript
22 lines
750 B
TypeScript
|
import { compare } from 'compare-versions';
|
||
|
|
||
|
type SemVerPatternFragment = `${bigint | '*'}`;
|
||
|
|
||
|
type SemVerPattern = SemVerPatternFragment
|
||
|
| `${SemVerPatternFragment}.${SemVerPatternFragment}`
|
||
|
| `${SemVerPatternFragment}.${SemVerPatternFragment}.${SemVerPatternFragment}`;
|
||
|
|
||
|
type Versions = {
|
||
|
maxVersion?: SemVerPattern;
|
||
|
minVersion?: SemVerPattern;
|
||
|
};
|
||
|
|
||
|
export type SemVer = `${bigint}.${bigint}.${bigint}` | 'latest';
|
||
|
|
||
|
export const versionMatch = (versionToMatch: SemVer, { maxVersion, minVersion }: Versions): boolean => {
|
||
|
const matchesMinVersion = !minVersion || compare(versionToMatch, minVersion, '>=');
|
||
|
const matchesMaxVersion = !maxVersion || compare(versionToMatch, maxVersion, '<=');
|
||
|
|
||
|
return matchesMaxVersion && matchesMinVersion;
|
||
|
};
|