Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async isSupported(): Promise {
if (typeof window === 'undefined' || !window.localStorage) {
const message = `LocalStorage is not available on your platform.`;
throw new StoreEngineError.UnsupportedError(message);
}
}
async isSupported(): Promise {
if (typeof window === 'undefined' || !fs.isSupported()) {
const message = `File and Directory Entries API is not available on your platform.`;
throw new StoreEngineError.UnsupportedError(message);
}
}
const platform = typeof global === 'undefined' ? window : global;
if ('indexedDB' in platform) {
return new Promise((resolve, reject) => {
const name = 'test';
const DBOpenRequest = platform.indexedDB.open(name);
DBOpenRequest.onerror = error => reject(error);
DBOpenRequest.onsuccess = () => {
const db = DBOpenRequest.result;
db.close();
const deleteRequest = platform.indexedDB.deleteDatabase(name);
deleteRequest.onerror = error => reject(error);
deleteRequest.onsuccess = () => resolve();
};
});
} else {
return Promise.reject(new StoreEngineError.UnsupportedError('Could not find indexedDB in global scope'));
}
}
const platform = typeof global === 'undefined' ? window : global;
if ('indexedDB' in platform) {
return new Promise((resolve, reject) => {
const name = 'test';
const DBOpenRequest = platform.indexedDB.open(name);
DBOpenRequest.onerror = error => reject(error);
DBOpenRequest.onsuccess = () => {
const db = DBOpenRequest.result;
db.close();
const deleteRequest = platform.indexedDB.deleteDatabase(name);
deleteRequest.onerror = error => reject(error);
deleteRequest.onsuccess = () => resolve();
};
});
} else {
return Promise.reject(new StoreEngineError.UnsupportedError('Could not find indexedDB in global scope'));
}
}
public async isSupported(): Promise {
if (typeof window === 'undefined' || !window.localStorage) {
const message = `LocalStorage is not available on your platform.`;
throw new StoreEngineError.UnsupportedError(message);
}
}
async isSupported(): Promise {
if (typeof WebAssembly === 'object' && typeof WebAssembly.instantiate === 'function') {
const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
if (module instanceof WebAssembly.Module) {
if (new WebAssembly.Instance(module) instanceof WebAssembly.Instance) {
return;
}
}
}
throw new StoreEngineError.UnsupportedError('WebAssembly is not supported.');
}
}