mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-15 20:13:48 +00:00
Move more components to shlink-web-component when applicable
This commit is contained in:
21
shlink-web-component/utils/helpers/version.ts
Normal file
21
shlink-web-component/utils/helpers/version.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
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;
|
||||
};
|
||||
Reference in New Issue
Block a user