@babyeyefe/localstorage
v1.0.2
Published
A simplified localStorage API that just works
Downloads
8
Readme
@babyeyefe/localstorage
A simplified
localStorageAPI that just works
Install
npm install @babyeyefe/localstorage
# or
yarn add @babyeyefe/localstorageAPI
The API is a simplified way to interact with all things localStorage. Note that when localStorage is unsupported in the current browser, a fallback to an in-memory store is used transparently.
For that reason, consider that local-storage values might evaporate across page views.
ls(key, value?)
If a value argument is provided, acts as ls.set. When value isn't provided, acts as ls.get.
Example
var ls = require('local-storage');
ls('foo');
// <- null
ls('foo', 'bar');
// <- true
ls('foo');
// <- 'bar'ls.get(key)
Returns value under key in local storage. Equivalent to ls(key). Internally parses the value from JSON before returning it.
Example
var ls = require('local-storage');
ls('foo', 'bar');
// <- true
ls.get('foo');
// <- 'bar'ls.set(key, value)
Persists value under key in local storage. Equivalent to ls(key, value). Internally converts the value to JSON.
Returns whether an error was thrown by the browser when trying to persist the value. Failure typically means a QuotaExceededError was thrown.
Example
var ls = require('local-storage');
ls.set('foo', 'bar');
// <- true
ls.get('foo');
// <- 'bar'ls.remove(key)
Removes key from local storage. Returns true if the property was successfully deleted, and false otherwise.
Example
var ls = require('local-storage');
ls.set('foo', 'bar');
// <- true
ls.remove('foo');
// <- truels.clear()
Clears local storage.
Example
var ls = require('local-storage');
ls.set('foo', 'bar');
ls.set('baz', 'tar');
ls.clear();License
MIT
Reference
https://github.com/bevacqua/local-storage
