parse

Bun

Symbol

Cookie.parse

static parse(cookieString: string): Cookie

Parse a cookie string into a Cookie object

@param cookieString

The cookie string

Referenced types

class Cookie

A class for working with a single cookie

const cookie = new Bun.Cookie("name", "value");
console.log(cookie.toString()); // "name=value; Path=/; SameSite=Lax"
  • domain?: string

    The domain of the cookie

  • expires?: Date

    The expiration date of the cookie

  • httpOnly: boolean

    Whether the cookie is HTTP-only

  • maxAge?: number

    The maximum age of the cookie in seconds

  • readonly name: string

    The name of the cookie

  • partitioned: boolean

    Whether the cookie is partitioned

  • path: string

    The path of the cookie

  • sameSite: CookieSameSite

    The same-site attribute of the cookie

  • secure: boolean

    Whether the cookie is secure

  • value: string

    The value of the cookie

  • isExpired(): boolean

    Whether the cookie is expired

  • serialize(): string

    Serialize the cookie to a string

    const cookie = Bun.Cookie.from("session", "abc123", {
      domain: "example.com",
      path: "/",
      secure: true,
      httpOnly: true
    }).serialize(); // "session=abc123; Domain=example.com; Path=/; Secure; HttpOnly; SameSite=Lax"
    
  • Serialize the cookie to a JSON object

  • toString(): string

    Serialize the cookie to a string

    Alias of Cookie.serialize

  • static from(name: string, value: string, options?: CookieInit): Cookie

    Create a new cookie from a name and value and optional options

  • static parse(cookieString: string): Cookie

    Parse a cookie string into a Cookie object

    @param cookieString

    The cookie string