All Projects → ripeworks → local-storage-fallback

ripeworks / local-storage-fallback

Licence: MIT license
Check and use appropriate storage adapter for browser (localStorage, sessionStorage, cookies, memory)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to local-storage-fallback

Ngx Store
Angular decorators to automagically keep variables in HTML5 LocalStorage, SessionStorage, cookies; injectable services for managing and listening to data changes and a bit more.
Stars: ✭ 152 (+47.57%)
Mutual labels:  cookies, localstorage, sessionstorage
Immortaldb
🔩 A relentless key-value store for the browser.
Stars: ✭ 2,962 (+2775.73%)
Mutual labels:  cookies, localstorage, sessionstorage
Awesome Web Storage
😎 Everything you need to know about Client-side Storage.
Stars: ✭ 227 (+120.39%)
Mutual labels:  cookies, localstorage, sessionstorage
Store
A better way to use localStorage and sessionStorage
Stars: ✭ 1,646 (+1498.06%)
Mutual labels:  localstorage, sessionstorage
Vue Mail List
vue全家桶+localStorage实现一个简易的通讯录
Stars: ✭ 81 (-21.36%)
Mutual labels:  localstorage, sessionstorage
Nuxt Storage
🛢 Utilities for easy read and write browser's storage in Nuxt.js project
Stars: ✭ 98 (-4.85%)
Mutual labels:  localstorage, sessionstorage
Proxy Storage
Provides an adapter for storage mechanisms (cookies, localStorage, sessionStorage, memoryStorage) and implements the Web Storage interface
Stars: ✭ 10 (-90.29%)
Mutual labels:  localstorage, sessionstorage
React Local Storage
Showcase on how to use the native localStorage of the browser in React.
Stars: ✭ 168 (+63.11%)
Mutual labels:  localstorage, sessionstorage
React Storage Hooks
React hooks for persistent state
Stars: ✭ 146 (+41.75%)
Mutual labels:  localstorage, sessionstorage
Brownies
🍫 Tastier cookies, local, session, and db storage in a tiny package. Includes subscribe() events for changes.
Stars: ✭ 2,386 (+2216.5%)
Mutual labels:  localstorage, sessionstorage
Client-Storage
🗄 Bulletproof persistent Client storage, works with disabled Cookies and/or localStorage
Stars: ✭ 15 (-85.44%)
Mutual labels:  cookies, localstorage
Javascript For Everyone
A step by step guide to learn JavaScript and programming
Stars: ✭ 285 (+176.7%)
Mutual labels:  cookies, localstorage
cache-bucket
Light Cache for nodeJs and browserJs with TTL.
Stars: ✭ 14 (-86.41%)
Mutual labels:  localstorage, sessionstorage
Bin
A tiny (<1kb) localStorage and sessionStorage helper library.
Stars: ✭ 70 (-32.04%)
Mutual labels:  localstorage, sessionstorage
mst-persist
Persist and hydrate MobX-state-tree stores (in < 100 LoC)
Stars: ✭ 75 (-27.18%)
Mutual labels:  localstorage, sessionstorage
Recoil Persist
Package for recoil state manager to persist and rehydrate store
Stars: ✭ 66 (-35.92%)
Mutual labels:  localstorage, sessionstorage
Web Storage Cache
对localStorage 和sessionStorage 进行了扩展,添加了超时时间,序列化方法
Stars: ✭ 582 (+465.05%)
Mutual labels:  localstorage, sessionstorage
Storagedb
MongoDB-like API for HTML5 Storage (localStorage and sessionStorage)
Stars: ✭ 16 (-84.47%)
Mutual labels:  localstorage, sessionstorage
Jest Localstorage Mock
A module to mock window.localStorage and window.sessionStorage in Jest
Stars: ✭ 247 (+139.81%)
Mutual labels:  localstorage, sessionstorage
Vue Warehouse
A Cross-browser storage for Vue.js and Nuxt.js, with plugins support and easy extensibility based on Store.js.
Stars: ✭ 161 (+56.31%)
Mutual labels:  cookies, localstorage

local-storage-fallback

Check and use appropriate storage adapter for browser (localStorage, sessionStorage, cookies, memory)

npm version

Installation

$ npm install local-storage-fallback

Usage

import storage from 'local-storage-fallback' // if you use es6 or typescript
// use object destructuring when using require()
// const {storage} = require('local-storage-fallback')

// Use storage directly
storage.setItem('foo', 'bar');
storage.getItem('foo'); // bar

// Or shim window.localStorage
if (!('localStorage' in window)) {
  window.localStorage = storage;
}

Browser Bundle

<script src="https://unpkg.com/local-storage-fallback/lib/dist.min.js"></script>
<script>
  window.localStorageFallback.setItem('foo', 'bar')
</script>

Purpose

With browser settings like "Private Browsing" it has become a problem to rely on a working window.localStorage, even in newer browsers. Even though it may exist, it will throw exceptions when trying to use setItem or getItem. This module will run appropriate checks to see what browser storage mechanism might be available, and then expose it. It uses the same API as localStorage so it should work as a drop-in replacement in most cases.

Gotchas

  • CookieStorage has storage limits. Be careful here.
  • MemoryStorage will not persist between page loads. This is more or less a stop-gap to prevent page crashes, but may be sufficient for websites that don't do full page loads.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].