{"id":17114682,"url":"https://github.com/tinyhttp/cookie-parser","last_synced_at":"2025-04-13T04:07:17.270Z","repository":{"id":57166686,"uuid":"382630158","full_name":"tinyhttp/cookie-parser","owner":"tinyhttp","description":"🍪 Cookie parsing middleware for Node.js","archived":false,"fork":false,"pushed_at":"2023-05-27T18:50:27.000Z","size":234,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T04:07:12.327Z","etag":null,"topics":["cookie","cookie-parser","cookies","http","javascript","middleware","nodejs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tinyhttp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"ko_fi":"v1rtl","liberapay":"v1rtl","custom":["https://stakes.social/0x14308514785B216904a41aB817282d25425Cce39","https://paypal.me/v1rtl","https://qiwi.com/n/V1RTL","https://yoomoney.ru/to/410014774355272"],"issuehunt":"talentlessguy"}},"created_at":"2021-07-03T14:04:58.000Z","updated_at":"2023-06-26T17:06:00.000Z","dependencies_parsed_at":"2024-06-19T04:00:57.897Z","dependency_job_id":null,"html_url":"https://github.com/tinyhttp/cookie-parser","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyhttp%2Fcookie-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyhttp%2Fcookie-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyhttp%2Fcookie-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyhttp%2Fcookie-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tinyhttp","download_url":"https://codeload.github.com/tinyhttp/cookie-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248661705,"owners_count":21141450,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cookie","cookie-parser","cookies","http","javascript","middleware","nodejs"],"created_at":"2024-10-14T17:19:46.352Z","updated_at":"2025-04-13T04:07:17.245Z","avatar_url":"https://github.com/tinyhttp.png","language":"TypeScript","readme":"\u003cdiv align=\"center\"\u003e\n\n# @tinyhttp/cookie-parser\n\n[![NPM][npm-badge]][npm-url] [![NPM][dl-badge]][npm-url] [![GitHub Workflow Status][actions-img]][github-actions] [![Coverage][cov-img]][cov-url]\n\n\u003c/div\u003e\n\n\u003e A rewrite of [cookie-parser](https://github.com/expressjs/cookie-parser) module.\n\nA middleware to parse `Cookie` header and populate `req.cookies` with an object keyed by the\ncookie names. Optionally you may enable signed cookie support by passing a\n`secret` string, which assigns `req.secret` so it may be used by other\nmiddleware.\n\n## Install\n\n```sh\npnpm i @tinyhttp/cookie-parser\n```\n\n## API\n\n```ts\nimport { cookieParser, JSONCookie, JSONCookies, signedCookie, signedCookies } from '@tinyhttp/cookie-parser'\n```\n\n### `cookieParser(secret, options)`\n\nCreate a new cookie parser middleware function using the given `secret` and\n`options`.\n\n- `secret` a string or array used for signing cookies. This is optional and if\n  not specified, will not parse signed cookies. If a string is provided, this\n  is used as the secret. If an array is provided, an attempt will be made to\n  unsign the cookie with each secret in order.\n- `options` an object that is passed to `cookie.parse` as the second option. See\n  [cookie](https://www.npmjs.org/package/cookie) for more information.\n  - `decode` a function to decode the value of the cookie\n\nThe middleware will parse the `Cookie` header on the request and expose the\ncookie data as the property `req.cookies` and, if a `secret` was provided, as\nthe property `req.signedCookies`. These properties are name value pairs of the\ncookie name to cookie value.\n\nWhen `secret` is provided, this module will unsign and validate any signed cookie\nvalues and move those name value pairs from `req.cookies` into `req.signedCookies`.\nA signed cookie is a cookie that has a value prefixed with `s:`. Signed cookies\nthat fail signature validation will have the value `false` instead of the tampered\nvalue.\n\nIn addition, this module supports special \"JSON cookies\". These are cookie where\nthe value is prefixed with `j:`. When these values are encountered, the value will\nbe exposed as the result of `JSON.parse`. If parsing fails, the original value will\nremain.\n\n### `JSONCookie(str)`\n\nParse a cookie value as a JSON cookie. This will return the parsed JSON value\nif it was a JSON cookie, otherwise, it will return the passed value.\n\n### `JSONCookies(cookies)`\n\nGiven an object, this will iterate over the keys and call `JSONCookie` on each\nvalue, replacing the original value with the parsed value. This returns the\nsame object that was passed in.\n\n### `signedCookie(str, secret)`\n\nParse a cookie value as a signed cookie. This will return the parsed unsigned\nvalue if it was a signed cookie and the signature was valid. If the value was\nnot signed, the original value is returned. If the value was signed but the\nsignature could not be validated, `false` is returned.\n\nThe `secret` argument can be an array or string. If a string is provided, this\nis used as the secret. If an array is provided, an attempt will be made to\nunsign the cookie with each secret in order.\n\n### `signedCookies(cookies, secret)`\n\nGiven an object, this will iterate over the keys and check if any value is a\nsigned cookie. If it is a signed cookie and the signature is valid, the key\nwill be deleted from the object and added to the new object that is returned.\n\nThe `secret` argument can be an array or string. If a string is provided, this\nis used as the secret. If an array is provided, an attempt will be made to\nunsign the cookie with each secret in order.\n\n## Example\n\n```ts\nimport { App } from '@tinyhttp/app'\nimport { cookieParser } from '@tinyhttp/cookie-parser'\n\nnew App()\n  .use(cookieParser())\n  .get('/', (req, res) =\u003e {\n    // Cookies that have not been signed\n    console.log('Cookies: ', req.cookies)\n\n    // Cookies that have been signed\n    console.log('Signed Cookies: ', req.signedCookies)\n  })\n  .listen(3000)\n\n// curl command that sends an HTTP request with two cookies\n// curl http://127.0.0.1:8080 --cookie \"Cho=Kim;Greet=Hello\"\n```\n\n[npm-badge]: https://img.shields.io/npm/v/@tinyhttp/cookie-parser?style=for-the-badge\u0026color=hotpink\u0026label=\u0026logo=npm\n[npm-url]: https://npmjs.com/package/@tinyhttp/cookie-parser\n[dl-badge]: https://img.shields.io/npm/dt/@tinyhttp/cookie-parser?style=for-the-badge\u0026color=hotpink\n[actions-img]: https://img.shields.io/github/actions/workflow/status/tinyhttp/cookie-parser/main.yml?style=for-the-badge\u0026logo=github\u0026label=\u0026color=hotpink\n[github-actions]: https://github.com/tinyhttp/cookie-parser/actions\n[cov-img]: https://img.shields.io/coveralls/github/tinyhttp/cookie-parser?style=for-the-badge\u0026color=hotpink\u0026a\n[cov-url]: https://coveralls.io/github/tinyhttp/cookie-parser\n","funding_links":["https://ko-fi.com/v1rtl","https://liberapay.com/v1rtl","https://stakes.social/0x14308514785B216904a41aB817282d25425Cce39","https://paypal.me/v1rtl","https://qiwi.com/n/V1RTL","https://yoomoney.ru/to/410014774355272","https://issuehunt.io/r/talentlessguy"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinyhttp%2Fcookie-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinyhttp%2Fcookie-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinyhttp%2Fcookie-parser/lists"}