@bithero/simple-cookie-storage
v1.1.1
Published
Provides an simple storage interface to work with cookies
Downloads
44
Maintainers
Readme
simple-cookie-storage
A simple interface to work with cookies
License
AGPL-3.0-or-later; see LICENSE
file
Installation
$ yarn add @bithero/simple-cookie-storage
Usage
import { defaultCookieStorage } from '@bithero/simple-cookie-storage';
// use the default cookie storage;
// default options of it are:
// - path: '/'
// - domain: window.location.hostname
// - sameSite: 'Strict'
defaultCookieStorage.size === 0;
defaultCookieStorage.setItem('key', 'value');
defaultCookieStorage.size === 1;
defaultCookieStorage.getItem('key') === 'value';
defaultCookieStorage.removeItem('key');
defaultCookieStorage.setItem('key', 'value', {
path: '/',
domain: 'example.com',
sameSite: 'Lax', // Also supports 'Strict' and 'None'
secure: true,
httpOnly: true, // Be aware that httpOnly=true will prevent you
// from ever accessing the cookie again!
maxAge: 1200,
expires: new Date(),
});
// ...or create a custom storage
const myStorage = new CookieStorage({
path: '/',
domain: 'example.com',
sameSite: 'Lax', // Also supports 'Strict' and 'None'
secure: true,
httpOnly: true,
maxAge: 1200,
expires: new Date(),
});