UNPKG

vue-sqlite-hook

Version:
31 lines (26 loc) 772 B
import { Capacitor } from '@capacitor/core'; import { FeatureNotAvailableError } from './models'; const allTrue = { web: true, ios: true, android: true, electron: true } const featureMap = { CapacitorSQLite: { useSQLite: {...allTrue/*, web: false*/}, } } export async function isFeatureAvailable< T extends typeof featureMap, PluginKeys extends keyof NonNullable<T>, FeatureKeys extends keyof NonNullable<NonNullable<T>[PluginKeys]>> (plugin: PluginKeys, method: FeatureKeys): Promise<boolean> { if(Capacitor.isPluginAvailable(plugin as string) && !!(featureMap as any)[plugin][method][Capacitor.platform!]) { return true; } return false; } export function featureNotAvailableError(): any { throw new FeatureNotAvailableError() }