1.0.3 • Published 10 years ago
thin-mint v1.0.3
thin-mint
HTTP cookie utility. thin-mint provides parsing and stringification of individual HTTP cookies.
Example
var ThinMint = require('thin-mint');
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 = new ThinMint(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.log(cookie.toString());Methods
Cookie(cookieStr) Constructor
- Arguments
cookieStr(string) - An HTTP cookie
- Constructs
- object - An object representation of the
cookieStrargument with the following schema:name(string) - The cookie name. Defaults tonull.value(string) - The cookie value, as parsed bydecodeURIComponent()``. Defaults tonull`.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'ssecureattribute. Defaults tofalse.httpOnly(boolean) - The cookie'shttpOnlyattribute. Defaults tofalse.expires(number) - The cookie'sexpiresattribute passed throughDate.parse(). Defaults toInfinity.maxAge(number) - The cookie'smax-ageattribute. Defaults toInfinity.expiration(number) - The cookie's expiration time. Usesmax-age, or falls back toexpires. Defaults toInfinityif 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'ssecureattribute. Defaults tonull.httpOnly(string) - The cookie'shttpOnlyattribute. Defaults tonull.expires(string) - The cookie'sexpiresattribute. Defaults tonull.maxAge(string) - The cookie'smax-ageattribute. 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, wherevalueis 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.