phanpy/src/utils/supports.js
2023-02-13 01:21:18 +08:00

26 lines
603 B
JavaScript

import { satisfies } from 'semver';
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;