mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-26 02:48:22 +03:00
21 lines
750 B
TypeScript
21 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;
|
|
};
|