set-cookie-header

0.0.1 • Public • Published

set-cookie-header

Decode and encode Set-Cookie headers. Aligns with RFC6265.

Install

npm install set-cookie-header

Quick Start

import {encode, decode} from 'set-cookie-header';
 
const cookies = decode('foo=bar; Max-Age=1234; Domain=.example.com; Path=/; Expires=December 17, 1995 03:24:00 GMT; HttpOnly');
 
for (const cookie of cookies) {
  cookie.secure = true;
  const encoded = encoded(cookie);
}

API

decode(cookieHeader: string | string[]): Cookie[]

Accepts:

  • cookieHeader can be a raw Set-Cookie header, the value of the header, or an array of header values.
  • Eg:
    • 'Set-Cookie: foo=bar; Path=/'
    • 'foo=bar; Secure'
    • ['foo=bar', 'biz=baz']

Returns:

  • Array of decoded Cookie objects.

encode(cookie: Cookie | Cookie[]): string[]

Accepts:

  • An array or a single Cookie object.

Returns:

  • Array of encoded cookie strings.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.0.118latest

Version History

VersionDownloads (Last 7 Days)Published
0.0.118

Package Sidebar

Install

npm i set-cookie-header

Weekly Downloads

18

Version

0.0.1

License

MIT

Unpacked Size

15 kB

Total Files

17

Last publish

Collaborators

  • trs