thin-mint
HTTP cookie utility. thin-mint
provides parsing and stringification of individual HTTP cookies.
Example
var ThinMint = ;var str = 'foo=bar; domain=continuation.io; path=/baz; expires=Sun, 20 Mar 2016 07:05:03 GMT; max-age=1234; secure; httponly';var cookie = str; /*cookie = { name: 'foo', value: 'bar', domain: 'continuation.io', path: '/baz', secure: true, httpOnly: true, expires: 1458457503000, maxAge: 1234, expiration: 1441772074919, input: { cookie: 'foo=bar; domain=continuation.io; path=/baz; expires=Sun, 20 Mar 2016 07:05:03 GMT; max-age=1234; secure; httponly', name: 'foo', value: 'bar', domain: 'continuation.io', path: '/baz', secure: 'secure', httpOnly: 'httponly', expires: 'Sun, 20 Mar 2016 07:05:03 GMT', maxAge: '1234' }}*/ console;
Methods
Cookie(cookieStr)
Constructor
- Arguments
cookieStr
(string) - An HTTP cookie
- Constructs
- object - An object representation of the
cookieStr
argument with the following schema:name
(string) - The cookie name. Defaults tonull
.value
(string) - The cookie value, as parsed bydecodeURIComponent()``. Defaults to
null`.domain
(string) - The cookie domain, converted to lowercase. Defaults tonull
.path
(string) - The cookie path, which must begin with/
. Defaults tonull
.secure
(boolean) - The cookie'ssecure
attribute. Defaults tofalse
.httpOnly
(boolean) - The cookie'shttpOnly
attribute. Defaults tofalse
.expires
(number) - The cookie'sexpires
attribute passed throughDate.parse()
. Defaults toInfinity
.maxAge
(number) - The cookie'smax-age
attribute. Defaults toInfinity
.expiration
(number) - The cookie's expiration time. Usesmax-age
, or falls back toexpires
. Defaults toInfinity
if neither are provided.input
(object) - An object containing the raw input values without any processing. Contains the following properties.cookie
(string) - The original string passed to the constructor.name
(string) - The cookie name. Defaults tonull
.value
(string) - The cookie value. Defaults tonull
.domain
(string) - The cookie domain. Defaults tonull
.path
(string) - The cookie path. Defaults tonull
.secure
(string) - The cookie'ssecure
attribute. Defaults tonull
.httpOnly
(string) - The cookie'shttpOnly
attribute. Defaults tonull
.expires
(string) - The cookie'sexpires
attribute. Defaults tonull
.maxAge
(string) - The cookie'smax-age
attribute. Defaults tonull
.
- object - An object representation of the
Cookie.prototype.toRequestCookie()
- Arguments
- None
- Returns
- string - Request cookie string representation of the cookie. If the cookie has a value, then the string will be of the form
name=value
, wherevalue
is encoded usingencodeURIComponent()
. If the cookie has no value, then the string is just the cookie name.
- string - Request cookie string representation of the cookie. If the cookie has a value, then the string will be of the form
Converts the Cookie
into a request cookie string.
Cookie.prototype.toString()
- Arguments
- None
- Returns
- string - String representation of the cookie containing all fields.
Creates a string representation of the Cookie
object.