Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cookie-parse-lite

npm install @ferrow/cookie-parse-lite

CI

HTTP cookie parsing and serialization with Set-Cookie attribute support and SameSite validation.

Quick Start

import { parse, serialize } from "cookie-parse-lite";

const cookies = parse("sessionId=abc123; theme=dark");

const setHeader = serialize("token", "xyz", {
  httpOnly: true,
  secure: true,
  sameSite: "Strict",
});

API

parse(cookieHeader: string): Map<string, string>

Parse a Cookie request header into a name→value map.

serialize(name: string, value: string, attributes?: CookieAttributes): string

Create a Set-Cookie header string. Enforces SameSite=None requires Secure flag.

parseSetCookie(header: string): ParsedCookie

Parse a Set-Cookie response header into structured form with name, value, and attributes.

Attributes

interface CookieAttributes {
  maxAge?: number                   // Seconds
  expires?: Date                    // Absolute expiry
  domain?: string                   // Domain restriction
  path?: string                     // Path restriction
  secure?: boolean                  // HTTPS only
  httpOnly?: boolean                // No JS access
  sameSite?: "Strict" | "Lax" | "None"
}

Limits

  • No domain/path matching (scope checking is app responsibility)
  • Attribute parsing case-insensitive (per spec)
  • SameSite=None+Secure validation at serialize time only

Part of the ferrow-toolkit collection · Sponsored by Ferrow

About

HTTP cookie parsing and serialization with attribute validation and Set-Cookie parsing

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages