biskviit

2.0.0 • Public • Published

biskviit

Yet another node module for handling http cookies. This module parses Set-Cookie header, stores the data to memory and returns valid value for Cookie header based on the stored cookie data.

NB Requires Node.js v6+

Usage

Install from npm

npm install biskviit --save

Require as Biskviit

const Biskviit = require('biskviit');

Create a cookie managing biskviit instance

const biskviit = new Biskviit(options);

Where

  • options is an optional options object with the following properties:
    • sessionTimeout is the amount in seconds for default session length, used for cookies without an expire argument

Example

const Biskviit = require('biskviit');
const biskviit = new Biskviit({
    sessionTimeout: 5 * 60 // expire cookies after 5 minutes
});

set

To add new cookies to the storage use set

biskviit.set(cookieString, url)

Where

  • cookieString is the value from the Set-Cookie: header
  • url is the currently open URL that sent the cookie header

Example

biskviit.set('theme=light', 'http://example.com/');
biskviit.set('sessionToken=abc123; Expires=Wed, 09 Jun 2021 10:18:14 GMT', 'http://example.com/');

get

To list all available cookies for a specified URL use get

const cookiesString = biskviit.get(url);

Where

  • url is the URL the cookies are required for

Example

const cookiesString = biskviit.get('http://example.com/');
// theme=light; sessionToken=abc123

list

If you need to filter cookies as objects, use list

const cookiesString = biskviit.list(url);

Where

  • url is the URL the cookies are required for

Example

const cookiesString = biskviit.list('http://example.com/');
// [{key: 'theme', value: 'light', expires: ...}, {key: 'sessionToken', value: 'abc123', expires: ...}]

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i biskviit

Weekly Downloads

85,722

Version

2.0.0

License

MIT

Last publish

Collaborators

  • andris