fa-storagedeprecated

a library to mock session/local storage in case which is not available

Usage no npm install needed!

<script type="module">
  import faStorage from 'https://cdn.skypack.dev/fa-storage';
</script>

README

fake-storage

Fake storage is a library to work with session/local storage, it provides you different polyfills in case that these options are not available.

This library is exported as commonJS module, however it works in browser environments.

Table of contents

Usage

first of all download this library using npm:

npm install --save fa-storage

Then, in a javascript file with browserify/webpack/rollup or whatever library you like to bundle your apps.

/*
  it exposes sessionStorage and localStorage

  the mock process is at follows:

  - native session/local storage
  - cookie storage
  - in memory storage
*/
const { localStorage } = require('fa-storage');



localStorage.setItem('foo', 'bar');

const config = localStorage.getItem('foo'); // returns bar

localStorage.removeItem('foo');

const maybeNull = localStorage.getItem('unexisting key'); // returns null

localStorage.clear(); // removes everything from store


Support

Tested in these browsers:

  • IE >= 10
  • Chrome 48+
  • Firefox 55+
  • Edge 14+
  • Safari 10+

 Known limitations

Cookie and memory storage polyfills currently don't support the full behavior of native implementations.

Given this, these way of using the library currently is not supported:

const { localStorage } = require('fa-storage');

localStorage.something = 'asdf'; // storing a key value
localStorage.something // getting the value