td-storage

1.1.4 • Public • Published

td-storage npm version

Helper functions to access local storage, wrapped in try catches and JSON parsing taken care of.

Install

yarn add td-storage

Configuration

Support for both localStorage and sessionStorage.

import storageFactory from 'td-storage';

const store = storageFactory({
  driver: 'localStorage', // 'sessionStorage'
  name: 'my-cool-app',
});

/**
 * each instance of the storageFactory is prefixed with the provided name
 * i.e the below will be stored under "my-cool-app/my-key"
 */
store.set(key, 'any value'); // => void

Methods (has, get, set, remove)

const key = 'my-key';

store.has(key); // => false
store.get(key); // => null

store.set(key, 'any value'); // => void
store.has(key); // => true
store.get(key); // => 'any value'

store.remove(key); // => void
store.get(key); // => null

Package Sidebar

Install

npm i td-storage

Weekly Downloads

0

Version

1.1.4

License

ISC

Unpacked Size

7.2 kB

Total Files

8

Last publish

Collaborators

  • tdtele