{"id":16214,"library":"set-cookie-parser-es","title":"ESM Set-Cookie Header Parser","description":"set-cookie-parser-es is an actively maintained, ESM-first JavaScript library, currently at version 1.0.5, designed for parsing `Set-Cookie` HTTP headers. It serves as an ECMAScript Module (ESM) port of the popular `set-cookie-parser` package, offering bundled TypeScript types for an enhanced developer experience. Unlike its predecessor, this library distinguishes itself by being entirely framework and runtime agnostic; it specifically does *not* accept Node.js response objects, focusing purely on string-based header parsing. Its `splitCookiesString` utility also strictly operates on a single `set-cookie` header string, deviating from the original's broader input acceptance. While primarily an ESM package, it also provides CommonJS compatibility for wider ecosystem integration. The project appears to follow a release cadence driven by feature parity with the original library, bug fixes, and minor enhancements.","status":"active","version":"1.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/enkot/set-cookie-parser-es","tags":["javascript","cookie","set-cookie","parser","es","typescript"],"install":[{"cmd":"npm install set-cookie-parser-es","lang":"bash","label":"npm"},{"cmd":"yarn add set-cookie-parser-es","lang":"bash","label":"yarn"},{"cmd":"pnpm add set-cookie-parser-es","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The `parse` function is a named export, used for parsing an array of `Set-Cookie` header strings. Ensure named imports are used for ESM or destructuring for CommonJS.","wrong":"import parse from 'set-cookie-parser-es'","symbol":"parse","correct":"import { parse } from 'set-cookie-parser-es'"},{"note":"While the library supports CommonJS `require`, directly accessing `require('pkg').symbol` without destructuring is less idiomatic. `parseString` is for parsing a single `Set-Cookie` header string.","wrong":"const parseString = require('set-cookie-parser-es').parseString","symbol":"parseString","correct":"import { parseString } from 'set-cookie-parser-es'"},{"note":"The `splitCookiesString` function is a named export. While aliasing is not inherently wrong, it can lead to confusion if not consistently applied. This function splits a single string containing multiple concatenated `Set-Cookie` headers.","wrong":"import { splitCookiesString as split } from 'set-cookie-parser-es'","symbol":"splitCookiesString","correct":"import { splitCookiesString } from 'set-cookie-parser-es'"}],"quickstart":{"code":"import { parse, parseString, splitCookiesString } from 'set-cookie-parser-es';\n\n// Example 1: Parse a single Set-Cookie header string\nconst singleSetCookieHeader = 'session_id=abc; Path=/; Expires=Wed, 21 Oct 2026 07:28:00 GMT; HttpOnly; Secure';\nconst parsedCookie = parseString(singleSetCookieHeader);\nconsole.log('Parsed single cookie:', parsedCookie);\n\n// Example 2: Parse an array of Set-Cookie header strings\nconst multipleSetCookieHeaders = [\n  'user_token=xyz; Max-Age=3600; HttpOnly',\n  'preferences=theme=dark; Path=/',\n];\nconst parsedCookiesArray = parse(multipleSetCookieHeaders);\nconsole.log('Parsed array of cookies:', parsedCookiesArray);\n\n// Example 3: Split a single string containing multiple Set-Cookie values\n// This is useful if a server concatenates multiple Set-Cookie headers into one string.\nconst concatenatedSetCookies = 'my_app_session=value1; Path=/; Secure, my_app_prefs=value2; Path=/';\nconst splitCookies = splitCookiesString(concatenatedSetCookies);\nconsole.log('Split cookies string:', splitCookies);\n\n// You can then parse the split strings:\nconst parsedSplitCookies = parse(splitCookies);\nconsole.log('Parsed split cookies:', parsedSplitCookies);","lang":"typescript","description":"Demonstrates how to parse single `Set-Cookie` headers, arrays of headers, and split concatenated `Set-Cookie` strings using the library's core functions."},"warnings":[{"fix":"Manually extract `Set-Cookie` headers from the response object (e.g., `response.headers['set-cookie']` or `res.getHeader('set-cookie')`) before passing to `parse` or `parseString`.","message":"The library explicitly does not accept Node.js response objects, unlike the original `set-cookie-parser` package. Users migrating from the original package in Node.js environments will need to manually extract `Set-Cookie` headers into a string or array of strings.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Ensure only valid `Set-Cookie` header strings are passed to `splitCookiesString`. For parsing `Cookie` request headers, use a dedicated parser for that specific format.","message":"The `splitCookiesString` function strictly expects a `Set-Cookie` header string as input, which can contain multiple comma-separated `Set-Cookie` values. It is not designed to parse generic comma-separated cookie strings (e.g., from a `Cookie` request header), and also does not accept Node.js response objects.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.5':24 'accept':76,109 'activ':14 'agnost':71 'also':91,116 'appear':126 'base':85 'broader':107 'bug':140 'bundl':50 'cadenc':131 'commonj':118 'compat':119 'cooki':4,9,30,46,99,146,149 'current':21 'design':25 'develop':56 'deviat':102 'distinguish':63 'driven':132 'ecmascript':37 'ecosystem':122 'enhanc':55,144 'entir':67 'es':11,151 'esm':1,17,39,113 'esm-first':16 'experi':57 'featur':134 'first':18 'fix':141 'focus':80 'follow':128 'framework':68 'header':5,32,86,100 'http':31 'input':108 'integr':123 'javascript':19,145 'librari':20,62,139 'maintain':15 'minor':143 'modul':38 'node.js':77 'object':79 'offer':49 'oper':93 'origin':105,138 'packag':48,114 'pariti':135 'pars':27,87 'parser':6,10,47,150 'popular':43 'port':40 'predecessor':60 'primarili':111 'project':125 'provid':117 'pure':81 'releas':130 'respons':78 'runtim':70 'serv':34 'set':3,8,29,45,98,148 'set-cooki':2,28,97,147 'set-cookie-pars':44 'set-cookie-parser-':7 'singl':96 'specif':73 'splitcookiesstr':89 'strict':92 'string':84,101 'string-bas':83 'type':52 'typescript':51,152 'unlik':58 'util':90 'version':23 'wider':121","created_at":"2026-04-21T19:18:51.631936+00:00","updated_at":"2026-04-21T19:18:51.631936+00:00","problems":[{"fix":"Use named imports for ESM (`import { parse } from 'set-cookie-parser-es'`) or destructuring for CommonJS (`const { parse } = require('set-cookie-parser-es')`).","cause":"Attempting to import `parse` as a default export in an ESM context, or incorrect CommonJS `require` syntax when the module primarily provides named exports.","error":"TypeError: parse is not a function"},{"fix":"Extract the `set-cookie` header values from the Node.js response object first. For example, `parse(response.headers['set-cookie'])` for an array of headers or `parseString(response.headers['set-cookie'][0])` for a single header.","cause":"Passing a Node.js `http.IncomingMessage` or `http.ServerResponse` object directly to the `parse` or `parseString` functions, which expect string(s).","error":"Argument of type 'IncomingMessage' is not assignable to parameter of type 'string | string[]'."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/enkot/set-cookie-parser-es","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/set-cookie-parser-es","openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-20","install_tag":null}}