{"id":18317884,"url":"https://github.com/idiocc/content-type","last_synced_at":"2025-04-09T13:51:16.840Z","repository":{"id":57113695,"uuid":"194859217","full_name":"idiocc/content-type","owner":"idiocc","description":"[fork] Create and parse HTTP Content-Type header according to RFC 7231 Written In ES6 And Optimised With JavaScript Compiler.","archived":false,"fork":false,"pushed_at":"2019-07-02T19:52:06.000Z","size":30,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-15T19:37:18.676Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://idio.cc","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/idiocc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-02T12:30:42.000Z","updated_at":"2020-07-09T17:45:46.000Z","dependencies_parsed_at":"2022-08-22T04:51:07.764Z","dependency_job_id":null,"html_url":"https://github.com/idiocc/content-type","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fcontent-type","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fcontent-type/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fcontent-type/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fcontent-type/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/idiocc","download_url":"https://codeload.github.com/idiocc/content-type/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248054218,"owners_count":21039951,"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":[],"created_at":"2024-11-05T18:07:47.038Z","updated_at":"2025-04-09T13:51:16.814Z","avatar_url":"https://github.com/idiocc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @goa/content-type\n\n[![npm version](https://badge.fury.io/js/%40goa%2Fcontent-type.svg)](https://npmjs.org/package/@goa/content-type)\n\n`@goa/content-type` is a fork of [Create and parse HTTP Content-Type header according to RFC 7231](https://github.com/jshttp/content-type) Written In ES6 And Optimised With [JavaScript Compiler](https://compiler.page).\n\n```sh\nyarn add @goa/content-type\n```\n\n## Table Of Contents\n\n- [Table Of Contents](#table-of-contents)\n- [API](#api)\n- [`parse(header: string|http.IncomingMessage|http.ServerResponse): ContentType`](#parseheader-stringhttpincomingmessagehttpserverresponse-contenttype)\n  * [`_goa.ContentType`](#type-_goacontenttype)\n- [`format(obj: ContentType): string`](#formatobj-contenttype-string)\n- [Copyright](#copyright)\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\"/.documentary/section-breaks/0.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## API\n\nThe package is available by importing its named functions:\n\n```js\nimport { parse, format } from '@goa/content-type'\n```\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\"/.documentary/section-breaks/1.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## `parse(`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`header: string|http.IncomingMessage|http.ServerResponse,`\u003cbr/\u003e`): ContentType`\n\nParse a _Content-Type_ header either from a string, or a request or response objects.\n\n`import('http').IncomingMessage` __\u003ca name=\"type-httpincomingmessage\"\u003e`http.IncomingMessage`\u003c/a\u003e__\n\n`import('http').ServerResponse` __\u003ca name=\"type-httpserverresponse\"\u003e`http.ServerResponse`\u003c/a\u003e__\n\n__\u003ca name=\"type-_goacontenttype\"\u003e`_goa.ContentType`\u003c/a\u003e__: The content-type interface.\n\n|      Name       |                  Type                  |                                        Description                                         |\n| --------------- | -------------------------------------- | ------------------------------------------------------------------------------------------ |\n| __type*__       | \u003cem\u003estring\u003c/em\u003e                        | The type of the content-type.                                                              |\n| __parameters*__ | \u003cem\u003e!Object\u0026lt;string, string\u0026gt;\u003c/em\u003e | An object of the parameters in the media type (name of the parameter will be lower-cased). |\n\n```js\nimport { parse } from '@goa/content-type'\n\nconst res = parse('image/svg+xml; charset=utf-8')\nconsole.log(res)\n\nconst asRequest = parse({ headers: { // as IncomingMessage\n  'content-type': 'image/svg+xml; charset=utf-8',\n} })\nconsole.log(asRequest)\n\nconst asResponse = parse({ getHeader(header) { // as ServerResponse\n  if (header == 'content-type')\n    return 'image/svg+xml; charset=utf-8'\n} })\nconsole.log(asResponse)\n```\n```\nContentType { parameters: { charset: 'utf-8' }, type: 'image/svg+xml' }\nContentType { parameters: { charset: 'utf-8' }, type: 'image/svg+xml' }\nContentType { parameters: { charset: 'utf-8' }, type: 'image/svg+xml' }\n```\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\"/.documentary/section-breaks/2.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## `format(`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`obj: ContentType,`\u003cbr/\u003e`): string`\n\nFormat an object into a _Content-Type_ header. This will return a string of the content type for the given object.\n\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003e\u003ca href=\"example/format.js\"\u003eSource\u003c/a\u003e\u003c/th\u003e\u003cth\u003eOutput\u003c/th\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```js\nimport { format } from '@goa/content-type'\n\nconst res = format({\n  type: 'image/svg+xml',\n  parameters: { charset: 'utf-8' },\n})\nconsole.log(res)\n```\n\u003c/td\u003e\n\u003ctd\u003e\n\n```\nimage/svg+xml; charset=utf-8\n```\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\"/.documentary/section-breaks/3.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## Copyright\n\nOriginal work by [Douglas Christopher Wilson and contributors](https://github.com/jshttp/content-type).\n\n---\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003e\n      \u003ca href=\"https://artd.eco\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/wrote/wrote/master/images/artdeco.png\" alt=\"Art Deco\"\u003e\n      \u003c/a\u003e\n    \u003c/th\u003e\n    \u003cth\u003e© \u003ca href=\"https://artd.eco\"\u003eArt Deco\u003c/a\u003e for \u003ca href=\"https://idio.cc\"\u003eIdio\u003c/a\u003e 2019\u003c/th\u003e\n    \u003cth\u003e\n      \u003ca href=\"https://idio.cc\"\u003e\n        \u003cimg src=\"https://avatars3.githubusercontent.com/u/40834161?s=100\" width=\"100\" alt=\"Idio\"\u003e\n      \u003c/a\u003e\n    \u003c/th\u003e\n    \u003cth\u003e\n      \u003ca href=\"https://www.technation.sucks\" title=\"Tech Nation Visa\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/artdecoweb/www.technation.sucks/master/anim.gif\"\n          alt=\"Tech Nation Visa\"\u003e\n      \u003c/a\u003e\n    \u003c/th\u003e\n    \u003cth\u003e\u003ca href=\"https://www.technation.sucks\"\u003eTech Nation Visa Sucks\u003c/a\u003e\u003c/th\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\"/.documentary/section-breaks/-1.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidiocc%2Fcontent-type","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidiocc%2Fcontent-type","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidiocc%2Fcontent-type/lists"}