/localStorage-by-IndexedDB-shim

makes available localStorage functions by using IndexedDB

Primary LanguageJavaScriptApache License 2.0Apache-2.0

localStorage-by-IndexedDB-shim

The tiny polyfill makes available localStorage functions by using IndexedDB


logo_msedge

The library uses native implementation if it isn't too poor, or polls indexedDB with interval from options (start of the file, parameter poll_time, even minified), saves it and gives You ability to use it almost like normal regular localStorage! (see belowe why almost: it's a function). Poll interval is set to 200ms by default.

For the sake of EDGE support, where we cannot replace native localStorage, the library makes own variable (localStorageShim by default, but can be changed easily by changing it in one of first lines :)

In types the library behave like standard localStorage: makes ALL just strings. Even Objects. Be careful.

Example:

  // Here the library or <script> tag.

  localStorageShim.getItem(14); // -> undefined
  
  localStorageShim.setItem(14, 42)  // -> undefined
  localStorageShim.setItem('next to all', 43)  // -> undefined
  
  localStorageShim.getItem(14)  // -> "42"

... page reloads, browser reloads, or it's another tab from that source...

  localStorageShim.getItem(14)  // -> "42"
  localStorageShim.setItem('next to all') // -> "43"