feat: add 'feature' options
This commit is contained in:
1 parent
e28ab154d9
commit
24c0c248f3
5 files changed
+46
-21
No files matched your search
+23
-13
@@ -1,3 +1,21 @@
|
||||
import { site } from '$lib/lemmy.js'
|
||||
import { derived } from 'svelte/store'
|
||||
|
||||
const FEATURES = {
|
||||
moderatorView: '0.19.0',
|
||||
controversialSort: '0.19.0',
|
||||
scaledSort: '0.19.0',
|
||||
unproxiedImageUpload: '0.19.0',
|
||||
}
|
||||
|
||||
type Feature = keyof typeof FEATURES
|
||||
|
||||
/**
|
||||
* Check if a feature is supported by the current version.
|
||||
*/
|
||||
export const feature = (feature: Feature, version: string = '0.0.0'): boolean =>
|
||||
versionIsSupported(version, FEATURES[feature])
|
||||
|
||||
export const MINIMUM_VERSION = '0.18.1'
|
||||
export const MAXIMUM_VERSION = '0.999'
|
||||
|
||||
@@ -11,21 +29,13 @@ export const versionIsSupported = (v: string, minimum: string) => {
|
||||
const [minMajor, minMinor, minPatch] = min.slice(1, 4).map((i) => Number(i))
|
||||
const [curMajor, curMinor, curPatch] = cur.slice(1, 4).map((i) => Number(i))
|
||||
|
||||
if (curMajor < minMajor) {
|
||||
return false
|
||||
} else if (curMajor > minMajor) {
|
||||
return true
|
||||
}
|
||||
if (curMajor < minMajor) return false
|
||||
else if (curMajor > minMajor) return true
|
||||
|
||||
if (curMinor < minMinor) {
|
||||
return false
|
||||
} else if (curMinor > minMinor) {
|
||||
return true
|
||||
}
|
||||
if (curMinor < minMinor) return false
|
||||
else if (curMinor > minMinor) return true
|
||||
|
||||
if (curPatch < minPatch) {
|
||||
return false
|
||||
}
|
||||
if (curPatch < minPatch) return false
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in new issue
Block a user