Skip to content
master
Switch branches/tags
Go to file
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

cookie-storage

cookie-storage: A Web Storage interface for Cookie.

Storage interface spec.

Installation

$ npm install cookie-storage

Usage

import { CookieStorage } from "cookie-storage";

const cookieStorage = new CookieStorage();

cookieStorage.length === 0;
cookieStorage.getItem("key") === null;

cookieStorage.setItem("key", "value");
cookieStorage.length === 1;
cookieStorage.key(0) === "key";

cookieStorage.getItem("key") === "value";
cookieStorage.removeItem("key");
cookieStorage.length === 0;

cookieStorage.setItem("k1", "v1");
cookieStorage.setItem("k2", "v2");
cookieStorage.length === 2;

cookieStorage.clear();
cookieStorage.length === 0;

// Cookie options
cookieStorage.setItem("key", "value", {
  path: "/",
  domain: "example.com",
  expires: new Date(),
  secure: true,
  sameSite: "Strict", // Can be 'Strict' or 'Lax' or 'None'.
});

// Use default cookie options
const storage = new CookieStorage({
  path: "/",
  domain: "example.com",
  expires: new Date(),
  secure: true,
  sameSite: "Strict", // Can be 'Strict' or 'Lax' or 'None'.
});
storage.setItem("key", "value"); // ;path=/;domain=example.com;...

Development

$ npm install
$ npm run watch

Badges

NPM Travis CI

License

MIT

Related Project

Contributors

Author

bouzuya <m@bouzuya.net> (http://bouzuya.net)