phanpy/src/utils/supports.js
Lim Chee Aun ab5a115084 Replace semver with compare-versions
Also, semver wasn't even in package.json, it worked because a lot of deps use it
2023-11-02 13:38:39 +08:00

25 lines
613 B
JavaScript

import { satisfies } from 'compare-versions';
import features from '../data/features.json';
import { getCurrentInstance } from './store-utils';
const supportsCache = {};
function supports(feature) {
try {
const { version, domain } = getCurrentInstance();
const key = `${domain}-${feature}`;
if (supportsCache[key]) return supportsCache[key];
const range = features[feature];
if (!range) return false;
return (supportsCache[key] = satisfies(version, range, {
includePrerelease: true,
loose: true,
}));
} catch (e) {
return false;
}
}
export default supports;