@bithero/simple-cookie-storage
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

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(),
});

Package Sidebar

Install

npm i @bithero/simple-cookie-storage

Weekly Downloads

2

Version

1.1.0

License

AGPL-3.0-or-later

Unpacked Size

39 kB

Total Files

7

Last publish

Collaborators

  • mai-lapyst