1.0.2 • Published 5 years ago

@babyeyefe/localstorage v1.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

@babyeyefe/localstorage

A simplified localStorage API that just works

Install

npm install @babyeyefe/localstorage
# or
yarn add @babyeyefe/localstorage

API

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');
// <- true

ls.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

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago