Cookies.ts overview
Since v1.0.0
Exports Grouped by Category
combinators
get
Get a cookie from a Cookies object
Signature
declare const get: {
(name: string): (self: Cookies) => Option.Option<Cookie>
(self: Cookies, name: string): Option.Option<Cookie>
}
Since v1.0.0
getValue
Get a cookie from a Cookies object
Signature
declare const getValue: {
(name: string): (self: Cookies) => Option.Option<string>
(self: Cookies, name: string): Option.Option<string>
}
Since v1.0.0
merge
Combine two Cookies objects, removing duplicates from the first
Signature
declare const merge: { (that: Cookies): (self: Cookies) => Cookies; (self: Cookies, that: Cookies): Cookies }
Since v1.0.0
remove
Remove a cookie by name
Signature
declare const remove: { (name: string): (self: Cookies) => Cookies; (self: Cookies, name: string): Cookies }
Since v1.0.0
set
Add a cookie to a Cookies object
Signature
declare const set: {
(name: string, value: string, options?: Cookie["options"]): (self: Cookies) => Either.Either<Cookies, CookiesError>
(self: Cookies, name: string, value: string, options?: Cookie["options"]): Either.Either<Cookies, CookiesError>
}
Since v1.0.0
setAll
Add multiple cookies to a Cookies object
Signature
declare const setAll: {
(
cookies: Iterable<readonly [name: string, value: string, options?: Cookie["options"]]>
): (self: Cookies) => Either.Either<Cookies, CookiesError>
(
self: Cookies,
cookies: Iterable<readonly [name: string, value: string, options?: Cookie["options"]]>
): Either.Either<Cookies, CookiesError>
}
Since v1.0.0
setAllCookie
Add multiple cookies to a Cookies object
Signature
declare const setAllCookie: {
(cookies: Iterable<Cookie>): (self: Cookies) => Cookies
(self: Cookies, cookies: Iterable<Cookie>): Cookies
}
Since v1.0.0
setCookie
Add a cookie to a Cookies object
Signature
declare const setCookie: { (cookie: Cookie): (self: Cookies) => Cookies; (self: Cookies, cookie: Cookie): Cookies }
Since v1.0.0
unsafeSet
Add a cookie to a Cookies object
Signature
declare const unsafeSet: {
(name: string, value: string, options?: Cookie["options"]): (self: Cookies) => Cookies
(self: Cookies, name: string, value: string, options?: Cookie["options"]): Cookies
}
Since v1.0.0
unsafeSetAll
Add multiple cookies to a Cookies object, throwing an error if invalid
Signature
declare const unsafeSetAll: {
(cookies: Iterable<readonly [name: string, value: string, options?: Cookie["options"]]>): (self: Cookies) => Cookies
(self: Cookies, cookies: Iterable<readonly [name: string, value: string, options?: Cookie["options"]]>): Cookies
}
Since v1.0.0
constructors
empty
An empty Cookies object
Signature
declare const empty: Cookies
Since v1.0.0
fromIterable
Create a Cookies object from an Iterable
Signature
declare const fromIterable: (cookies: Iterable<Cookie>) => Cookies
Since v1.0.0
fromReadonlyRecord
Create a Cookies object from an Iterable
Signature
declare const fromReadonlyRecord: (cookies: Record.ReadonlyRecord<string, Cookie>) => Cookies
Since v1.0.0
fromSetCookie
Create a Cookies object from a set of Set-Cookie headers
Signature
declare const fromSetCookie: (headers: Iterable<string> | string) => Cookies
Since v1.0.0
makeCookie
Create a new cookie
Signature
declare const makeCookie: (
name: string,
value: string,
options?: Cookie["options"] | undefined
) => Either.Either<Cookie, CookiesError>
Since v1.0.0
unsafeMakeCookie
Create a new cookie, throwing an error if invalid
Signature
declare const unsafeMakeCookie: (name: string, value: string, options?: Cookie["options"] | undefined) => Cookie
Since v1.0.0
cookie
Cookie (interface)
Signature
export interface Cookie extends Inspectable.Inspectable {
readonly [CookieTypeId]: CookieTypeId
readonly name: string
readonly value: string
readonly valueEncoded: string
readonly options?:
| {
readonly domain?: string | undefined
readonly expires?: Date | undefined
readonly maxAge?: Duration.DurationInput | undefined
readonly path?: string | undefined
readonly priority?: "low" | "medium" | "high" | undefined
readonly httpOnly?: boolean | undefined
readonly secure?: boolean | undefined
readonly partitioned?: boolean | undefined
readonly sameSite?: "lax" | "strict" | "none" | undefined
}
| undefined
}
Since v1.0.0
decoding
parseHeader
Parse a cookie header into a record of key-value pairs
Adapted from https://github.com/fastify/fastify-cookie under MIT License
Signature
declare const parseHeader: (header: string) => Record<string, string>
Since v1.0.0
encoding
serializeCookie
Serialize a cookie into a string
Adapted from https://github.com/fastify/fastify-cookie under MIT License
Signature
declare const serializeCookie: (self: Cookie) => string
Since v1.0.0
toCookieHeader
Serialize a Cookies object into a Cookie header
Signature
declare const toCookieHeader: (self: Cookies) => string
Since v1.0.0
toRecord
To record
Signature
declare const toRecord: (self: Cookies) => Record<string, string>
Since v1.0.0
toSetCookieHeaders
Serialize a Cookies object into Headers object containing one or more Set-Cookie headers
Signature
declare const toSetCookieHeaders: (self: Cookies) => Array<string>
Since v1.0.0
errors
CookiesError (class)
Signature
declare class CookiesError
Since v1.0.0
models
Cookies (interface)
Signature
export interface Cookies extends Pipeable, Inspectable.Inspectable {
readonly [TypeId]: TypeId
readonly cookies: Record.ReadonlyRecord<string, Cookie>
}
Since v1.0.0
refinements
isCookies
Signature
declare const isCookies: (u: unknown) => u is Cookies
Since v1.0.0
isEmpty
Signature
declare const isEmpty: (self: Cookies) => boolean
Since v1.0.0
type ids
CookieTypeId
Signature
declare const CookieTypeId: unique symbol
Since v1.0.0
CookieTypeId (type alias)
Signature
type CookieTypeId = typeof CookieTypeId
Since v1.0.0
ErrorTypeId
Signature
declare const ErrorTypeId: unique symbol
Since v1.0.0
ErrorTypeId (type alias)
Signature
type ErrorTypeId = typeof ErrorTypeId
Since v1.0.0
TypeId
Signature
declare const TypeId: unique symbol
Since v1.0.0
TypeId (type alias)
Signature
type TypeId = typeof TypeId
Since v1.0.0