@builds-dev/cookie

1.1.0 • Public • Published

cookie

import * as cookie from '@builds-dev/cookie'

header (cookie_strings)

Takes an array of cookie strings and returns a string suitable to use as the value of the Cookie header.

cookie.header([
	'foo=bar; Secure; HttpOnly',
	'baz=qux; Secure'
])
// => 'foo=bar; baz=qux'

join (cookie_pairs)

Joins an array of cookie pairs into a string.

cookie.join([
	'foo=bar',
	'Expires=Thu, 21 Oct 2021 07:28:00 GMT',
	'Secure',
	'HttpOnly'
])
// => 'foo=bar; Expires=Thu, 21 Oct 2021 07:28:00 GMT; Secure; HttpOnly'

parse (cookie)

Takes a cookie string and parses it into an object.

cookie.parse('foo=bar; Expires=Thu, 21 Oct 2021 07:28:00 GMT; Secure; HttpOnly')
/*
=> {
	name: 'foo',
	value: 'bar',
	expires: 'Thu, 21 Oct 2021 07:28:00 GMT',
	secure: true,
	httponly: true
}
*/

split (cookie_string)

Split a cookie string into an array of cookie pairs.

cookie.split('foo=bar; Expires=Thu, 21 Oct 2021 07:28:00 GMT; Secure; HttpOnly')
/*
=> [
	'foo=bar',
	'Expires=Thu, 21 Oct 2021 07:28:00 GMT',
	'Secure',
	'HttpOnly'
]
*/

stringify (object)

Takes a parsed cookie object and returns a cookie string.

cookie.stringify({
	name: 'foo',
	value: 'bar',
	expires: 'Thu, 21 Oct 2021 07:28:00 GMT',
	secure: true,
	httponly: true
})
// => 'foo=bar; expires=Thu, 21 Oct 2021 07:28:00 GMT; secure; httponly'

Package Sidebar

Install

npm i @builds-dev/cookie

Weekly Downloads

0

Version

1.1.0

License

ISC

Unpacked Size

9.98 kB

Total Files

10

Last publish

Collaborators

  • builds-ops
  • m59
  • craig-l