{"id":13000,"library":"cookie-lite","title":"cookie-lite: Lightweight Cookie Parser and Serializer","description":"cookie-lite is a super lightweight JavaScript library designed for parsing and serializing HTTP cookie strings. It serves as a friendly fork of the `lightcookie` package, which was deprecated by its original author. The library focuses on efficiency and a minimal footprint, utilizing JavaScript regular expressions for its parsing logic, making it a smaller and faster alternative compared to more feature-rich cookie handling packages. Currently at version 0.0.2, it supports Node.js environments from version 18 onwards. Its primary differentiator is its minimal resource consumption and speed for fundamental cookie operations, suitable for applications where performance and size are critical. It offers straightforward methods for converting raw cookie strings into objects and vice versa, providing core functionality without extensive configuration or advanced features like signed cookies or complex attribute validation. Its simple API aims for ease of integration for basic cookie management tasks.","status":"active","version":"0.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/leelaprasadv/cookie-lite","tags":["javascript","cookie","cookie-lite","lightcookie","cookie-parse","cookie-serialize"],"install":[{"cmd":"npm install cookie-lite","lang":"bash","label":"npm"},{"cmd":"yarn add cookie-lite","lang":"bash","label":"yarn"},{"cmd":"pnpm add cookie-lite","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The `cookie-lite` package provides a default object containing `parse` and `serialize` methods. This is the primary way to import the module in both ESM and CJS contexts.","wrong":"const cookieLite = require('cookie-lite').default","symbol":"cookieLite","correct":"import cookieLite from 'cookie-lite'"},{"note":"The `parse` function is a method of the default `cookieLite` object. While some modern packages offer direct named exports, this approach ensures compatibility with the library's primary export structure. For CommonJS, use `require('cookie-lite').parse`.","wrong":"import { parse } from 'cookie-lite'","symbol":"parse","correct":"import cookieLite from 'cookie-lite';\nconst parse = cookieLite.parse;"},{"note":"The `serialize` function is a method of the default `cookieLite` object. This reflects the library's export pattern. For CommonJS, use `require('cookie-lite').serialize`.","wrong":"import { serialize } from 'cookie-lite'","symbol":"serialize","correct":"import cookieLite from 'cookie-lite';\nconst serialize = cookieLite.serialize;"}],"quickstart":{"code":"import { parse, serialize } from 'cookie-lite';\n\n// Example 1: Parsing cookie strings\nconst cookieString = 'foo=bar; copyright=%C2%A9; another=test';\nconst parsedCookies = parse(cookieString);\nconsole.log('Parsed cookies:', parsedCookies);\n// Expected: { foo: 'bar', copyright: '©', another: 'test' }\n\n// Example 2: Serializing objects to cookie strings\nconst cookieObject = {\n  name: 'Choco',\n  HttpOnly: null, // Should serialize as just 'HttpOnly' flag\n  Expires: new Date(Date.now() + 3600 * 1000).toUTCString(), // Add an Expires date\n  MaxAge: 3600,\n  Path: '/',\n  Secure: true,\n  SameSite: 'Lax',\n  ValueWithSpace: 'hello world' // Test value with space\n};\nconst serializedCookie = serialize(cookieObject);\nconsole.log('Serialized cookie:', serializedCookie);\n// Expected: 'name=Choco;HttpOnly;Expires=...;Max-Age=3600;Path=/;Secure;SameSite=Lax;ValueWithSpace=hello%20world'\n\n// Demonstrate basic usage\nconsole.log('\\nDemonstrating basic usage:');\nconst myCookie = serialize({ user: 'Alice', theme: 'dark', 'Path': '/' });\nconsole.log('Set-Cookie header:', myCookie);\nconst receivedCookies = parse(myCookie);\nconsole.log('Received cookies:', receivedCookies);","lang":"typescript","description":"Demonstrates how to parse a raw cookie string into an object and serialize an object into a cookie string, including common attributes like `HttpOnly`, `Expires`, and `SameSite`."},"warnings":[{"fix":"Update all package imports to `cookie-lite` and conduct comprehensive regression testing. Review `cookie-lite`'s documentation for any specific changes or new features relative to `lightcookie`.","message":"Users migrating from the deprecated `ethan7g/lightcookie` package should be aware that `cookie-lite` is a new, independent fork. While it aims for functional compatibility, it's essential to perform thorough testing as behavioral nuances might exist. The original `lightcookie` is no longer maintained.","severity":"breaking","affected_versions":">=0.0.1"},{"fix":"Always validate and sanitize cookie data from untrusted sources. Explicitly set secure cookie attributes (`Secure`, `HttpOnly`, `SameSite='Lax'` or `'Strict'`) when creating cookies, especially for production or sensitive data.","message":"`cookie-lite` focuses on basic parsing and serialization without implementing advanced security features like automatic cookie validation, signing, or comprehensive sanitization. Users are solely responsible for setting appropriate security attributes and handling untrusted input.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Maintain consistent encoding practices for cookie values. Avoid double-encoding. If specific encoding requirements exist, ensure they are applied before serialization and processed after parsing, potentially outside of `cookie-lite`'s default handling.","message":"`cookie-lite` handles URI component encoding and decoding for cookie values. Be cautious with non-standard or double-encoded cookie values, as unexpected behavior may occur if encoding schemes conflict or are applied incorrectly at the application layer.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}