Provides an simple storage interface to work with cookies
Go to file
Mai Lapyst 8152abb048 Add some badges to the readme 2023-09-17 21:23:56 +02:00
src Release 1.1.0 2022-07-01 21:07:39 +02:00
.gitignore Initial Commit 2022-07-01 19:13:00 +02:00
LICENSE Adding LICENSE, Readme.md add keywords 2022-07-01 19:27:48 +02:00
Readme.md Add some badges to the readme 2023-09-17 21:23:56 +02:00
package.json Release 1.1.0 2022-07-01 21:07:39 +02:00
tsconfig.json Initial Commit 2022-07-01 19:13:00 +02:00
yarn.lock Initial Commit 2022-07-01 19:13:00 +02:00

Readme.md

simple-cookie-storage

Npm package version Npm package license Npm package types

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