1.0.0 • Published 3 years ago
web-storage-browser-cookies v1.0.0
web-storage-browser-cookies
Use cookies in the browser through the Storage interface of the Web Storage Api.
Installation
npm i cookie-parser web-storage-browser-cookiesUsage
Pass the window object to the constructor.
import { BrowserCookies } from 'web-storage-browser-cookies';
const storage = new BrowserCookies({ window });
// when we have set three items: fruit=banana,drink=coffee,food=hamburger
console.log(storage.getItem('fruit')); // -> banana
storage.setItem('girl', 'alice');
// now the storage will contain: fruit=banana,drink=coffee,food=hamburger,girl=alice
storage.removeItem('drink');
// now the storage will contain: fruit=banana,food=hamburger,girl=alice
storage.clear();
// now the storage will be emptyAn options object can be passed that will be used on setItem, removeItem and clear.
For all possible values please see all possible cookie attributes
import { BrowserCookies } from 'web-storage-browser-cookies';
const storage = new BrowserCookies({ window, options: { path: '/mydir' } });A custom prefix can be passed to override the default one __cookie-storage__.
import { BrowserCookies } from 'web-storage-browser-cookies';
const storage = new BrowserCookies({ window, prefix: '__custom-prefix__' });1.0.0
3 years ago