Class: CookieCollection
Class: CookieCollection
Class representing a collection of Cookies.
Constructors
Constructor
protected new CookieCollection(
cookie?,
options?,
secret?): CookieCollection;
Create a CookieCollection.
Parameters
cookie?
string
String cookie from header.
options?
CookieOptions
= {}
Cookies options.
secret?
string
Secret value to sign and unsign cookies.
Returns
CookieCollection
Methods
add()
add(
name,
value,
options): this;
Add a cookie to the collection.
Parameters
name
string
Cookie name.
value
unknown
Cookie value.
options
CookieOptions
= {}
Cookie options.
Returns
this
all()
all<S>(serialize): S extends true ? string[] : Record<string, unknown>;
Get all cookies in the collection.
Type Parameters
S
S
extends boolean
Parameters
serialize
S
= ...
If true, serialize the cookies.
Returns
S
extends true
? string
[] : Record
<string
, unknown
>
clear()
clear(force): this;
Clear all cookies from the collection.
Parameters
force
boolean
= false
If true, remove only from collection without setting expiry.
Returns
this
get()
Get a cookie from the collection.
Param
Cookie name.
Param
Fallback value if the cookie does not exist.
Call Signature
get(name): undefined | Cookie;
Get a cookie from the collection.
Parameters
name
string
Cookie name.
Returns
undefined
| Cookie
Cookie value.
Param
Cookie name.
Param
Fallback value if the cookie does not exist.
Call Signature
get(name, fallback): Cookie;
Get a cookie from the collection.
Parameters
name
string
Cookie name.
fallback
Fallback value if the cookie does not exist.
Returns
Cookie value.
Param
Cookie name.
Param
Fallback value if the cookie does not exist.
getValue()
Get a cookie value from the collection.
Param
Cookie name.
Param
Fallback value if the cookie does not exist.
Call Signature
getValue<ValueType>(name): undefined | ValueType;
Get a cookie value from the collection.
Type Parameters
ValueType
ValueType
= unknown
Parameters
name
string
Cookie name.
Returns
undefined
| ValueType
Cookie value.
Param
Cookie name.
Param
Fallback value if the cookie does not exist.
Call Signature
getValue<ValueType>(name, fallback): ValueType;
Get a cookie value from the collection.
Type Parameters
ValueType
ValueType
= unknown
Parameters
name
string
Cookie name.
fallback
ValueType
Fallback value if the cookie does not exist.
Returns
ValueType
Cookie value.
Param
Cookie name.
Param
Fallback value if the cookie does not exist.
has()
has(name): boolean;
Check if the collection has a cookie.
Parameters
name
string
Cookie name.
Returns
boolean
isEmpty()
isEmpty(): boolean;
Check if the collection is empty.
Returns
boolean
remove()
remove(
name,
options,
force): this;
Remove a cookie from the collection.
Parameters
name
string
Cookie name to remove.
options
CookieOptions
= {}
Cookie options.
force
boolean
= false
If true, remove only from collection without setting expiry.
Returns
this
secure()
secure(value): this;
Set secure flag for all cookies in the collection.
Parameters
value
boolean
= false
Whether the cookies are secure.
Returns
this
setOptions()
setOptions(options): this;
Set options for all cookies in the collection.
Parameters
options
Cookie options.
Returns
this
setSecret()
setSecret(value): this;
Set secret for signing and unsigning cookies.
Parameters
value
string
Secret value.
Returns
this
update()
update(
name,
value,
options): this;
Update a cookie in the collection.
Parameters
name
string
Cookie name.
value
unknown
New cookie value.
options
CookieOptions
= {}
Cookie options.
Returns
this
create()
static create(
cookie?,
options?,
secret?): CookieCollection;
Create a CookieCollection.
Parameters
cookie?
string
String cookie from header.
options?
CookieOptions
= {}
Cookies options.
secret?
string
Secret value to sign and unsign cookies.
Returns
CookieCollection