Skip to content

patkub/local-storage-poorlyfill

Repository files navigation

local-storage-poorlyfill

example workflow Known Vulnerabilities js-standard-style semantic-release

In-memory polyfill for local storage

Add to your project:

npm i local-storage-poorlyfill

<script type="text/javascript" src="node_modules/local-storage-poorlyfill/dist/local-storage-poorlyfill.js"></script>
<script>
// use _localStorage
</script>

Why?

  • For local files, IE and Edge do not have support for local storage

  • local storage can be disabled

Tested browsers

  • Chrome, Firefox, Internet Explorer, Edge, Safari and Opera

Implementation details

  • Use browser's native implementation if supported

  • Mirror native functionality with an object

Implementation flaws

  • Not persistent

  • Need to use _localStorage instead of localStorage

Scripts

Lint with standard:

yarn lint

Transpile with babel:

yarn build

Run unit tests:

yarn test

Use _localStorage or window._localStorage instead of localStorage or window.localStorage because the browser prevents using localStorage or window.localStorage if access is denied for this document.

W3 Spec:

MSDN: