Storage

It uses localStorage under the hood with data expiration support.

WARNING

Your data should be able to be JSON stringified.

Usage

import { writeToStorage, readFromStorage } from '@kocal/web-extension-library';

// scalar value
writeToStorage('key', 'my data');
readFromStorage('key'); // `my data`

// object
writeToStorage('key', { my: 'data'});
readFromStorage('key'); // `{ my: 'data' }`

// will expires in 60 seconds
writeToStorage('key', 'my data', 60);
readFromStorage('key'); // `my data`
// ... 60 seconds later..
readFromStorage('key'); // `null`