Skip to main content Link Search Menu Expand Document (external link)

Cookies overview

Added in v1.0.0


Table of contents


combinators

get

Get a cookie from a Cookies object

Signature

export declare const get: {
  (name: string): (self: Cookies) => Option.Option<Cookie>
  (self: Cookies, name: string): Option.Option<Cookie>
}

Added in v1.0.0

getValue

Get a cookie from a Cookies object

Signature

export declare const getValue: {
  (name: string): (self: Cookies) => Option.Option<string>
  (self: Cookies, name: string): Option.Option<string>
}

Added in v1.0.0

merge

Combine two Cookies objects, removing duplicates from the first

Signature

export declare const merge: { (that: Cookies): (self: Cookies) => Cookies; (self: Cookies, that: Cookies): Cookies }

Added in v1.0.0

remove

Remove a cookie by name

Signature

export declare const remove: { (name: string): (self: Cookies) => Cookies; (self: Cookies, name: string): Cookies }

Added in v1.0.0

set

Add a cookie to a Cookies object

Signature

export 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>
}

Added in v1.0.0

setAll

Add multiple cookies to a Cookies object

Signature

export 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>
}

Added in v1.0.0

setAllCookie

Add multiple cookies to a Cookies object

Signature

export declare const setAllCookie: {
  (cookies: Iterable<Cookie>): (self: Cookies) => Cookies
  (self: Cookies, cookies: Iterable<Cookie>): Cookies
}

Added in v1.0.0

setCookie

Add a cookie to a Cookies object

Signature

export declare const setCookie: {
  (cookie: Cookie): (self: Cookies) => Cookies
  (self: Cookies, cookie: Cookie): Cookies
}

Added in v1.0.0

unsafeSet

Add a cookie to a Cookies object

Signature

export declare const unsafeSet: {
  (name: string, value: string, options?: Cookie["options"]): (self: Cookies) => Cookies
  (self: Cookies, name: string, value: string, options?: Cookie["options"]): Cookies
}

Added in v1.0.0

unsafeSetAll

Add multiple cookies to a Cookies object, throwing an error if invalid

Signature

export 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
}

Added in v1.0.0

constructors

empty

An empty Cookies object

Signature

export declare const empty: Cookies

Added in v1.0.0

fromIterable

Create a Cookies object from an Iterable

Signature

export declare const fromIterable: (cookies: Iterable<Cookie>) => Cookies

Added in v1.0.0

fromReadonlyRecord

Create a Cookies object from an Iterable

Signature

export declare const fromReadonlyRecord: (cookies: Record.ReadonlyRecord<string, Cookie>) => Cookies

Added in v1.0.0

fromSetCookie

Create a Cookies object from a set of Set-Cookie headers

Signature

export declare const fromSetCookie: (headers: Iterable<string> | string) => Cookies

Added in v1.0.0

makeCookie

Create a new cookie

Signature

export declare function makeCookie(
  name: string,
  value: string,
  options?: Cookie["options"] | undefined
): Either.Either<Cookie, CookiesError>

Added in v1.0.0

unsafeMakeCookie

Create a new cookie, throwing an error if invalid

Signature

export declare const unsafeMakeCookie: (name: string, value: string, options?: Cookie["options"] | undefined) => Cookie

Added in v1.0.0

cookie

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
}

Added in 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

export declare function parseHeader(header: string): Record<string, string>

Added in v1.0.0

encoding

serializeCookie

Serialize a cookie into a string

Adapted from https://github.com/fastify/fastify-cookie under MIT License

Signature

export declare function serializeCookie(self: Cookie): string

Added in v1.0.0

toCookieHeader

Serialize a Cookies object into a Cookie header

Signature

export declare const toCookieHeader: (self: Cookies) => string

Added in v1.0.0

toRecord

To record

Signature

export declare const toRecord: (self: Cookies) => Record<string, string>

Added in v1.0.0

toSetCookieHeaders

Serialize a Cookies object into Headers object containing one or more Set-Cookie headers

Signature

export declare const toSetCookieHeaders: (self: Cookies) => Array<string>

Added in v1.0.0

errors

CookiesError (class)

Signature

export declare class CookiesError

Added in v1.0.0

models

Cookies (interface)

Signature

export interface Cookies extends Pipeable, Inspectable.Inspectable {
  readonly [TypeId]: TypeId
  readonly cookies: Record.ReadonlyRecord<string, Cookie>
}

Added in v1.0.0

refinements

isCookies

Signature

export declare const isCookies: (u: unknown) => u is Cookies

Added in v1.0.0

isEmpty

Signature

export declare const isEmpty: (self: Cookies) => boolean

Added in v1.0.0

type ids

CookieTypeId

Signature

export declare const CookieTypeId: typeof CookieTypeId

Added in v1.0.0

CookieTypeId (type alias)

Signature

export type CookieTypeId = typeof CookieTypeId

Added in v1.0.0

ErrorTypeId

Signature

export declare const ErrorTypeId: typeof ErrorTypeId

Added in v1.0.0

ErrorTypeId (type alias)

Signature

export type ErrorTypeId = typeof ErrorTypeId

Added in v1.0.0

TypeId

Signature

export declare const TypeId: typeof TypeId

Added in v1.0.0

TypeId (type alias)

Signature

export type TypeId = typeof TypeId

Added in v1.0.0