mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-02-27 12:16:36 +00:00
Created new feature checkers
This commit is contained in:
@@ -4,4 +4,20 @@ import { versionMatch, Versions } from './version';
|
||||
const serverMatchesVersions = (versions: Versions) => (selectedServer: SelectedServer): boolean =>
|
||||
isReachableServer(selectedServer) && versionMatch(selectedServer.version, versions);
|
||||
|
||||
export const titleIsSupported = serverMatchesVersions({ minVersion: '2.6.0' });
|
||||
export const supportsSettingShortCodeLength = serverMatchesVersions({ minVersion: '2.1.0' });
|
||||
|
||||
export const supportsTagVisits = serverMatchesVersions({ minVersion: '2.2.0' });
|
||||
|
||||
export const supportsListingDomains = serverMatchesVersions({ minVersion: '2.4.0' });
|
||||
|
||||
export const supportsQrCodeSvgFormat = supportsListingDomains;
|
||||
|
||||
export const supportsQrCodeSizeInQuery = serverMatchesVersions({ minVersion: '2.5.0' });
|
||||
|
||||
export const supportsShortUrlTitle = serverMatchesVersions({ minVersion: '2.6.0' });
|
||||
|
||||
export const supportsOrphanVisits = supportsShortUrlTitle;
|
||||
|
||||
export const supportsQrCodeMargin = supportsShortUrlTitle;
|
||||
|
||||
export const supportsTagsInPatch = supportsShortUrlTitle;
|
||||
|
||||
@@ -13,7 +13,7 @@ export interface Versions {
|
||||
minVersion?: SemVerPattern;
|
||||
}
|
||||
|
||||
export type SemVer = `${bigint}.${bigint}.${bigint}`;
|
||||
export type SemVer = `${bigint}.${bigint}.${bigint}` | 'latest';
|
||||
|
||||
export const versionMatch = (versionToMatch: SemVer | Empty, { maxVersion, minVersion }: Versions): boolean => {
|
||||
if (!hasValue(versionToMatch)) {
|
||||
@@ -26,7 +26,7 @@ export const versionMatch = (versionToMatch: SemVer | Empty, { maxVersion, minVe
|
||||
return matchesMaxVersion && matchesMinVersion;
|
||||
};
|
||||
|
||||
const versionIsValidSemVer = memoizeWith(identity, (version: string): version is SemVerPattern => {
|
||||
const versionIsValidSemVer = memoizeWith(identity, (version: string): version is SemVer => {
|
||||
try {
|
||||
return compare(version, version, '=');
|
||||
} catch (e) {
|
||||
@@ -36,5 +36,5 @@ const versionIsValidSemVer = memoizeWith(identity, (version: string): version is
|
||||
|
||||
export const versionToPrintable = (version: string) => !versionIsValidSemVer(version) ? version : `v${version}`;
|
||||
|
||||
export const versionToSemVer = (defaultValue = 'latest') =>
|
||||
(version: string) => versionIsValidSemVer(version) ? version : defaultValue;
|
||||
export const versionToSemVer = (defaultValue: SemVer = 'latest') =>
|
||||
(version: string): SemVer => versionIsValidSemVer(version) ? version : defaultValue;
|
||||
|
||||
Reference in New Issue
Block a user