Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

isIndexedDBValid.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import idb from './idb';
  2. function isIndexedDBValid() {
  3. try {
  4. // Initialize IndexedDB; fall back to vendor-prefixed versions
  5. // if needed.
  6. if (!idb || !idb.open) {
  7. return false;
  8. }
  9. // We mimic PouchDB here;
  10. //
  11. // We test for openDatabase because IE Mobile identifies itself
  12. // as Safari. Oh the lulz...
  13. var isSafari =
  14. typeof openDatabase !== 'undefined' &&
  15. /(Safari|iPhone|iPad|iPod)/.test(navigator.userAgent) &&
  16. !/Chrome/.test(navigator.userAgent) &&
  17. !/BlackBerry/.test(navigator.platform);
  18. var hasFetch =
  19. typeof fetch === 'function' &&
  20. fetch.toString().indexOf('[native code') !== -1;
  21. // Safari <10.1 does not meet our requirements for IDB support
  22. // (see: https://github.com/pouchdb/pouchdb/issues/5572).
  23. // Safari 10.1 shipped with fetch, we can use that to detect it.
  24. // Note: this creates issues with `window.fetch` polyfills and
  25. // overrides; see:
  26. // https://github.com/localForage/localForage/issues/856
  27. return (
  28. (!isSafari || hasFetch) &&
  29. typeof indexedDB !== 'undefined' &&
  30. // some outdated implementations of IDB that appear on Samsung
  31. // and HTC Android devices <4.4 are missing IDBKeyRange
  32. // See: https://github.com/mozilla/localForage/issues/128
  33. // See: https://github.com/mozilla/localForage/issues/272
  34. typeof IDBKeyRange !== 'undefined'
  35. );
  36. } catch (e) {
  37. return false;
  38. }
  39. }
  40. export default isIndexedDBValid;