JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q46455F
  • License MIT

Just localStorage with memory fallback. Works in edge cases like Safari private browsing.

Package Exports

  • just-storage

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (just-storage) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

just-storage

Just localStorage with a memory fallback.

A barebones localStorage module that checks for not only the existance of localStorage, but also checks that localStorage is enabled in the current session. Falls back to memory storage if localStorage isn't supported.

This implementation works in cases like Safari private browsing, where every call to localStorage throws a quota exceeded error.

Also does simple JSON stringify/parse for you.

Sauce Test Status

build status

Install

$ npm install --save just-storage

Usage

var storage = require('just-storage')

storage.set('key', { some: 'value' }) // ==> saves and returns { some: 'value' }
storage('key') // ==> { some: 'value' }

var tokenStorage = storage.forKey('myJwt')
tokenStorage() // ==> returns current value of 'myJwt'
tokenStorage.set('19dk2924ksdf') // ==> saves new value to 'myJwt'

API

justStorage(key) -> value

key

Required Type: string

The key to load from storage.

Returns value

The value saved for key.

justStorage.set(key, value) -> value

key

Required string

The key you're saving to.

value

Required any

The value you're saving for key.

justStorage.forKey(key) -> keyStorageFn

keyStorageFn() -> value

Returns current saved value for key

keyStorageFn.set(value) -> value
value

Required any

The value you're saving for key.

License

MIT © Andrew Joslin