{"id":18317947,"url":"https://github.com/idiocc/mime-types","last_synced_at":"2025-04-09T13:51:51.521Z","repository":{"id":57113703,"uuid":"185746293","full_name":"idiocc/mime-types","owner":"idiocc","description":"[Fork] The Ultimate Javascript Content-Type utility Written In ES6 And Optimised With JavaScript Compiler.","archived":false,"fork":false,"pushed_at":"2019-05-12T14:57:03.000Z","size":74,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-27T09:18:32.910Z","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-05-09T07:14:05.000Z","updated_at":"2019-05-12T14:57:05.000Z","dependencies_parsed_at":"2022-08-22T05:10:49.082Z","dependency_job_id":null,"html_url":"https://github.com/idiocc/mime-types","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%2Fmime-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fmime-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fmime-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fmime-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/idiocc","download_url":"https://codeload.github.com/idiocc/mime-types/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:57.282Z","updated_at":"2025-04-09T13:51:51.478Z","avatar_url":"https://github.com/idiocc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @goa/mime-types\n\n[![npm version](https://badge.fury.io/js/%40goa%2Fmime-types.svg)](https://npmjs.org/package/@goa/mime-types)\n\n`@goa/mime-types` is the [Fork](https://github.com/jshttp/mime-types) of The Ultimate Javascript Content-Type utility Written In ES6 And Optimised With JavaScript Compiler. Depends on the [`mime-db`](https://github.com/jshttp/mime-db) which was not bundled to allow direct upgrades of the database.\n\nThe original module has been updated to be used in [`@goa/koa`](https://artdecocode.com/goa/): _Koa_ web server compiled with _Google Closure Compiler_ using [**Depack**](https://artdecocode.com/depack/) into a single file library (0 dependencies).\n\n```sh\nyarn add @goa/mime-types\n```\n\n## Table Of Contents\n\n- [Table Of Contents](#table-of-contents)\n- [API](#api)\n- [`lookup(path: string): string`](#lookuppath-string-string)\n- [`contentType(type: string): string`](#contenttypetype-string-string)\n- [`extension(type: string): string`](#extensiontype-string-string)\n- [`charset(type: string): string`](#charsettype-string-string)\n- [`types`](#types)\n- [`extensions`](#extensions)\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 function:\n\n```js\nimport { lookup, contentType, extension, charset, types } from '@goa/mime-types'\n```\n\nAll functions return `false` if input is invalid or not found.\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## `lookup(`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`path: string,`\u003cbr/\u003e`): string`\n\nLookup the content-type associated with a file.\n\n```js\nimport { lookup } from '@goa/mime-types'\n\nconsole.log(lookup('json'))\nconsole.log(lookup('.md'))\nconsole.log(lookup('file.html'))\nconsole.log(lookup('folder/file.js'))\nconsole.log(lookup('folder/.htaccess'))\n\nconsole.log(lookup('cats'))\n```\n```\napplication/json\ntext/markdown\ntext/html\napplication/javascript\nfalse\nfalse\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## `contentType(`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`type: string,`\u003cbr/\u003e`): string`\n\nCreate a full content-type header given a content-type or extension. When given an extension, `mime.lookup` is used to get the matching content-type, otherwise the given content-type is used. Then if the content-type does not already have a `charset` parameter, `mime.charset` is used to get the default charset and add to the returned content-type.\n\n```js\nimport { contentType } from '@goa/mime-types'\nimport { extname } from 'path'\n\nconsole.log(contentType('markdown'))\nconsole.log(contentType('file.json'))\nconsole.log(contentType('text/html'))\nconsole.log(contentType('text/html; charset=iso-8859-1'))\n\n// from a full path\nconsole.log(contentType(extname('/path/to/file.json')))\n```\n```\ntext/markdown; charset=utf-8\napplication/json; charset=utf-8\ntext/html; charset=utf-8\ntext/html; charset=iso-8859-1\napplication/json; charset=utf-8\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## `extension(`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`type: string,`\u003cbr/\u003e`): string`\n\nGet the default extension for a content-type.\n\n```js\nimport { extension } from '@goa/mime-types'\n\nconsole.log(extension('application/octet-stream'))\n```\n```\nbin\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## `charset(`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`type: string,`\u003cbr/\u003e`): string`\n\nLookup the implied default charset of a content-type.\n\n```js\nimport { charset } from '@goa/mime-types'\n\nconsole.log(charset('text/markdown'))\n```\n```\nUTF-8\n```\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\".documentary/section-breaks/5.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## `types`\n\nA map of content-types by extension.\n\n```js\nimport { types } from '@goa/mime-types'\n\nconsole.log(types['json'])\n```\n```\napplication/json\n```\n\n## `extensions`\n\nA map of extensions by content-type.\n\n```js\nimport { extensions } from '@goa/mime-types'\n\nconsole.log(extensions['application/mp4'])\n```\n```\n[ 'mp4s', 'm4p' ]\n```\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\".documentary/section-breaks/6.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## Copyright\n\nOriginal Work by [Jonathan Ong, Douglas Christopher Wilson](https://github.com/jshttp/mime-types).\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%2Fmime-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidiocc%2Fmime-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidiocc%2Fmime-types/lists"}