{"id":18535282,"url":"https://github.com/tinyhttp/content-type","last_synced_at":"2026-03-04T19:32:47.171Z","repository":{"id":57226898,"uuid":"279152430","full_name":"tinyhttp/content-type","owner":"tinyhttp","description":"content-type rewrite in TypeScript and ESM","archived":false,"fork":false,"pushed_at":"2024-07-18T18:01:32.000Z","size":166,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-08T19:25:55.761Z","etag":null,"topics":["content-type","nodejs","typescript"],"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":null,"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}},"created_at":"2020-07-12T21:39:49.000Z","updated_at":"2025-08-27T13:22:18.000Z","dependencies_parsed_at":"2022-08-24T15:51:59.410Z","dependency_job_id":"1db5786b-38e6-49ad-a45d-4c04fd61a65b","html_url":"https://github.com/tinyhttp/content-type","commit_stats":null,"previous_names":["talentlessguy/es-content-type"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/tinyhttp/content-type","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyhttp%2Fcontent-type","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyhttp%2Fcontent-type/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyhttp%2Fcontent-type/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyhttp%2Fcontent-type/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tinyhttp","download_url":"https://codeload.github.com/tinyhttp/content-type/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyhttp%2Fcontent-type/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30090559,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T18:31:08.343Z","status":"ssl_error","status_checked_at":"2026-03-04T18:31:07.708Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["content-type","nodejs","typescript"],"created_at":"2024-11-06T19:21:44.082Z","updated_at":"2026-03-04T19:32:47.133Z","avatar_url":"https://github.com/tinyhttp.png","language":"TypeScript","readme":"# @tinyhttp/content-type\n\n[![Version][v-badge-url]][npm-url] [![Downloads][dl-badge-url]][npm-url] [![GitHub Workflow Status][gh-actions-img]][github-actions] [![Codecov][cov-badge-url]][cov-url]\n\n\u003e [`content-type`](https://github.com/jshttp/content-type) rewrite in TypeScript and ESM.\n\nCreate and parse HTTP Content-Type header according to RFC 7231\n\n## Install\n\n```sh\npnpm i @tinyhttp/content-type\n```\n\n## API\n\n```ts\nimport { parse, format } from '@tinyhttp/content-type'\n```\n\n### `parse(string: string | Request | Response)`\n\n```ts\nconst obj = parse('image/svg+xml; charset=utf-8')\n```\n\nParse a `Content-Type` header. This will return an object with the following\nproperties (examples are shown for the string `'image/svg+xml; charset=utf-8'`):\n\n- `type`: The media type (the type and subtype, always lower case).\n  Example: `'image/svg+xml'`\n\n- `parameters`: An object of the parameters in the media type (name of parameter\n  always lower case). Example: `{charset: 'utf-8'}`\n\nThrows a `TypeError` if the string is missing or invalid.\n\n```ts\nconst obj = contentType.parse(req)\n```\n\nParse the `Content-Type` header from the given `req`. Short-cut for\n`contentType.parse(req.headers['content-type'])`.\n\nThrows a `TypeError` if the `Content-Type` header is missing or invalid.\n\n```js\nconst obj = contentType.parse(res)\n```\n\nParse the `Content-Type` header set on the given `res`. Short-cut for\n`contentType.parse(res.getHeader('content-type'))`.\n\nThrows a `TypeError` if the `Content-Type` header is missing or invalid.\n\n### `format(obj)`\n\n```ts\nconst str = contentType.format({\n  type: 'image/svg+xml',\n  parameters: { charset: 'utf-8' },\n})\n```\n\nFormat an object into a `Content-Type` header. This will return a string of the\ncontent type for the given object with the following properties (examples are\nshown that produce the string `'image/svg+xml; charset=utf-8'`):\n\n- `type`: The media type (will be lower-cased). Example: `'image/svg+xml'`\n\n- `parameters`: An object of the parameters in the media type (name of the\n  parameter will be lower-cased). Example: `{charset: 'utf-8'}`\n\nThrows a `TypeError` if the object contains an invalid type or parameter names.\n\n[v-badge-url]: https://img.shields.io/npm/v/@tinyhttp/content-type.svg?style=for-the-badge\u0026color=FF69B4\u0026label=\u0026logo=npm\n[npm-url]: https://www.npmjs.com/package/@tinyhttp/content-type\n[cov-badge-url]: https://img.shields.io/coveralls/github/tinyhttp/content-type?style=for-the-badge\u0026color=FF69B4\n[cov-url]: https://coveralls.io/github/tinyhttp/@tinyhttp/content-type\n[dl-badge-url]: https://img.shields.io/npm/dt/@tinyhttp/content-type?style=for-the-badge\u0026color=FF69B4\n[github-actions]: https://github.com/tinyhttp/content-type/actions\n[gh-actions-img]: https://img.shields.io/github/actions/workflow/status/tinyhttp/content-type/ci.yml?branch=master\u0026style=for-the-badge\u0026color=FF69B4\u0026label=\u0026logo=github\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinyhttp%2Fcontent-type","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinyhttp%2Fcontent-type","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinyhttp%2Fcontent-type/lists"}