Serialize options.

interface CookieSerializeOptions {
    domain?: string;
    encode?: ((str: string) => string);
    expires?: Date;
    httpOnly?: boolean;
    maxAge?: number;
    partitioned?: boolean;
    path?: string;
    priority?: "high" | "low" | "medium";
    sameSite?:
        | boolean
        | "none"
        | "strict"
        | "lax";
    secure?: boolean;
}

Properties

domain?: string

Specifies the value for the Domain Set-Cookie attribute. When no domain is set clients consider the cookie to apply to the current domain only.

encode?: ((str: string) => string)

Specifies a function that will be used to encode a cookie-value. Since value of a cookie has a limited character set (and must be a simple string), this function can be used to encode a value into a string suited for a cookie's value, and should mirror decode when parsing.

encodeURIComponent
expires?: Date

Specifies the Date object to be the value for the Expires Set-Cookie attribute. When no expiration is set clients consider this a "non-persistent cookie" and delete it the current session is over.

The cookie storage model specification states that if both expires and maxAge are set, then maxAge takes precedence, but it is possible not all clients by obey this, so if both are set, they should point to the same date and time.

httpOnly?: boolean

Enables the HttpOnly Set-Cookie attribute. When enabled, clients will not allow client-side JavaScript to see the cookie in document.cookie.

maxAge?: number

Specifies the number (in seconds) to be the value for the Max-Age Set-Cookie attribute.

The cookie storage model specification states that if both expires and maxAge are set, then maxAge takes precedence, but it is possible not all clients by obey this, so if both are set, they should point to the same date and time.

partitioned?: boolean

Enables the Partitioned Set-Cookie attribute. When enabled, clients will only send the cookie back when the current domain and top-level domain matches.

This is an attribute that has not yet been fully standardized, and may change in the future. This also means clients may ignore this attribute until they understand it. More information about can be found in the proposal.

path?: string

Specifies the value for the Path Set-Cookie attribute. When no path is set, the path is considered the "default path".

priority?: "high" | "low" | "medium"

Specifies the value for the Priority Set-Cookie attribute.

  • 'low' will set the Priority attribute to Low.
  • 'medium' will set the Priority attribute to Medium, the default priority when not set.
  • 'high' will set the Priority attribute to High.

More information about priority levels can be found in the specification.

sameSite?:
    | boolean
    | "none"
    | "strict"
    | "lax"

Specifies the value for the SameSite Set-Cookie attribute.

  • true will set the SameSite attribute to Strict for strict same site enforcement.
  • 'lax' will set the SameSite attribute to Lax for lax same site enforcement.
  • 'none' will set the SameSite attribute to None for an explicit cross-site cookie.
  • 'strict' will set the SameSite attribute to Strict for strict same site enforcement.

More information about enforcement levels can be found in the specification.

secure?: boolean

Enables the Secure Set-Cookie attribute. When enabled, clients will only send the cookie back if the browser has a HTTPS connection.