1.1.1 • Published 1 year ago

tiny-cookies v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

tiny-cookies

JavaScript Style Guide code size npm version vulnerabilities license

Thin layer of abstraction over document.cookie that makes cookie handling easy.

const cookies = require("tiny-cookies");
cookies.set("hello", "world", {maxAge: 3600});
console.log(cookies.get("hello"));

Features

  • Small
  • Fast
  • No dependencies
  • Compatible with all recent browsers versions
  • Tested on Chrome, Chrome Android, Edge, Firefox, Firefox for Android, Safari and Opera

Installation

Save it to your devDependencies for bundling:

npm i --save-dev tiny-cookies

Usage

• set(name, value, attrs)

Set cookie named name to value, optionally specifying attributes with the attrs object.

cookies.set("lang", "en", {
  path: "/",
  domain: "example.com",
  maxAge: 60*60*24*365,
  expires: "Mon, 1 Jan 2024 12:00:00 GMT",
  sameSite: "Strict",
  secure: true,
  partitioned: false,
});

• get(name)

Return the value of the cookie named name, or null if none exist.

• remove(name)

Delete the cookie named name.

cookies.remove("lang");

License

MIT