{"id":18317913,"url":"https://github.com/idiocc/type-is","last_synced_at":"2025-04-09T13:51:23.247Z","repository":{"id":57113710,"uuid":"194858689","full_name":"idiocc/type-is","owner":"idiocc","description":"[fork] Infer the content-type of a request Written In ES6 And Optimised With JavaScript Compiler.","archived":false,"fork":false,"pushed_at":"2019-07-03T14:08:01.000Z","size":50,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-15T08:48:18.867Z","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:26:57.000Z","updated_at":"2019-07-03T14:08:03.000Z","dependencies_parsed_at":"2022-08-22T05:31:12.234Z","dependency_job_id":null,"html_url":"https://github.com/idiocc/type-is","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/idiocc%2Ftype-is","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Ftype-is/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Ftype-is/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Ftype-is/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/idiocc","download_url":"https://codeload.github.com/idiocc/type-is/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:50.721Z","updated_at":"2025-04-09T13:51:23.224Z","avatar_url":"https://github.com/idiocc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @goa/type-is\n\n[![npm version](https://badge.fury.io/js/%40goa%2Ftype-is.svg)](https://npmjs.org/package/@goa/type-is)\n\n`@goa/type-is` is a fork of [Infer the content-type of a request](https://github.com/jshttp/type-is) Written In ES6 And Optimised With [JavaScript Compiler](https://compiler.page).\n\n```sh\nyarn add @goa/type-is\n```\n\n## Table Of Contents\n\n- [Table Of Contents](#table-of-contents)\n- [API](#api)\n- [`typeis(request: http.IncomingMessage, types: string|Array\u003cstring\u003e, ...types: string): ?string|boolean`](#typeisrequest-httpincomingmessagetypes-stringarraystringtypes-string-stringboolean)\n- [`hasBody(request: http.IncomingMessage): boolean`](#hasbodyrequest-httpincomingmessage-boolean)\n- [`is(mediaType: string, types: string|Array\u003cstring\u003e, ...types: string): ?string|boolean`](#ismediatype-stringtypes-stringarraystringtypes-string-stringboolean)\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 default and named functions:\n\n```js\nimport typeis, { hasBody } from '@goa/type-is'\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## `typeis(`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`request: http.IncomingMessage,`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`types: string|Array\u003cstring\u003e,`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`...types: string,`\u003cbr/\u003e`): ?string|boolean`\n\nChecks if the `request` is one of the types. If the request has no body, even if there is a _Content-Type_ header, then `null` is returned. If the _Content-Type_ header is invalid or does not matches any of the `types`, then `false` is returned. Otherwise, a string of the type that matched is returned.\n\nThe `request` argument is expected to be a Node.js HTTP request. The `types` argument is an array of type strings.\n\nEach `type` in the types array can be one of the following:\n\n- A file extension name such as `json`. This name will be returned if matched.\n- A mime type such as `application/json`.\n- A mime type with a wildcard such as `*/*` or `*/json` or `application/*`. The full mime type will be returned if matched.\n- A suffix such as `+json`. This can be combined with a wildcard such as `*/vnd+json` or `application/*+json`. The full mime type will be returned if matched.\n\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003e\u003ca href=\"example/index.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 typeis from '@goa/type-is'\n\nconst req = {\n  headers: {\n    'content-length': 10,\n    'content-type': 'application/json',\n  },\n}\n\nlog(typeis(req, ['json']))\nlog(typeis(req, ['html', 'json']))\nlog(typeis(req, ['application/*']))\nlog(typeis(req, ['application/json']))\n\n// pass types as variable arguments\nlog(typeis(req, 'text/html', 'application/json'))\n\nlog(typeis(req, ['html']))\n```\n\u003c/td\u003e\n\u003ctd\u003e\n\n```js\n​\n​\n​\n​\n​\n​\n​\n​\n​\n​json\njson\napplication/json\napplication/json\n\n​\n​application/json\n\n​false\n```\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\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## `hasBody(`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`request: http.IncomingMessage,`\u003cbr/\u003e`): boolean`\n\nReturns a _Boolean_ if the given `request` has a body, regardless of the _Content-Type_ header.\n\nHaving a body has no relation to how large the body is (it may be 0 bytes). This is similar to how file existence works. If a body does exist, then this indicates that there is data to read from the Node.js request stream.\n\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003e\u003ca href=\"example/has-body.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 { hasBody } from '@goa/type-is'\n\nlog(hasBody({ headers: {\n  'content-length': 10,\n  'content-type': 'application/json' },\n}))\n\nlog(hasBody({ headers: {\n  'transfer-encoding': 'utf-8' },\n}))\n\nlog(hasBody({ headers: {\n  'content-type': 'application/json' },\n}))\n```\n\u003c/td\u003e\n\u003ctd\u003e\n\n```js\n​\n​\n​\n​\n​\n​true\n\n​\n​\n​true\n\n​\n​\n​false\n```\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\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## `is(`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`mediaType: string,`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`types: string|Array\u003cstring\u003e,`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`...types: string,`\u003cbr/\u003e`): ?string|boolean`\n\nChecks if the `mediaType` is one of the types. If the `mediaType` is invalid or does not matches any of the types, then false is returned. Otherwise, a string of the type that matched is returned.\n\nThe mediaType argument is expected to be a [media type](https://tools.ietf.org/html/rfc6838) string. The types argument is an array of type strings.\n\nEach `type` in the types array follows the same rules as described in the `typeis` section.\n\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003e\u003ca href=\"example/is.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 { is } from '@goa/type-is'\n\nconst mediaType = 'application/json'\n\nlog(is(mediaType, ['json']))\nlog(is(mediaType, ['html', 'json']))\nlog(is(mediaType, ['application/*']))\nlog(is(mediaType, ['application/json']))\n\n// pass types as variable arguments\nlog(is(mediaType, 'text/html', 'application/json'))\n\nlog(is(mediaType, ['html']))\n```\n\u003c/td\u003e\n\u003ctd\u003e\n\n```js\n​\n​\n​\n​\n​json\njson\napplication/json\napplication/json\n\n​\n​application/json\n\n​false\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/4.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## Copyright\n\nOriginal Work by [Jonathan Ong, Douglas Christopher Wilson and contributors](https://github.com/jshttp/type-is).\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%2Ftype-is","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidiocc%2Ftype-is","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidiocc%2Ftype-is/lists"}