b6c9af2533ce1171688d6befc3c0470fe1446931612d983d625c8dc60cda309b71ad853c7e1a9f4037c801a3b5b9127b16a9c93a4da00bdc9acf92db016fc5 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # mime-db
  2. [![NPM Version][npm-version-image]][npm-url]
  3. [![NPM Downloads][npm-downloads-image]][npm-url]
  4. [![Node.js Version][node-image]][node-url]
  5. [![Build Status][ci-image]][ci-url]
  6. [![Coverage Status][coveralls-image]][coveralls-url]
  7. This is a large database of mime types and information about them.
  8. It consists of a single, public JSON file and does not include any logic,
  9. allowing it to remain as un-opinionated as possible with an API.
  10. It aggregates data from the following sources:
  11. - https://www.iana.org/assignments/media-types/media-types.xhtml
  12. - https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
  13. - https://hg.nginx.org/nginx/raw-file/default/conf/mime.types
  14. ## Installation
  15. ```bash
  16. npm install mime-db
  17. ```
  18. ### Database Download
  19. If you intend to use this in a web browser, you can conveniently access the JSON file via [jsDelivr](https://www.jsdelivr.com/), a popular CDN (Content Delivery Network). To ensure stability and compatibility, it is advisable to specify [a release tag](https://github.com/jshttp/mime-db/tags) instead of using the 'master' branch. This is because the JSON file's format might change in future updates, and relying on a specific release tag will prevent potential issues arising from these changes.
  20. ```
  21. https://cdn.jsdelivr.net/gh/jshttp/mime-db@master/db.json
  22. ```
  23. ## Usage
  24. ```js
  25. var db = require('mime-db')
  26. // grab data on .js files
  27. var data = db['application/javascript']
  28. ```
  29. ## Data Structure
  30. The JSON file is a map lookup for lowercased mime types.
  31. Each mime type has the following properties:
  32. - `.source` - where the mime type is defined.
  33. If not set, it's probably a custom media type.
  34. - `apache` - [Apache common media types](https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types)
  35. - `iana` - [IANA-defined media types](https://www.iana.org/assignments/media-types/media-types.xhtml)
  36. - `nginx` - [nginx media types](https://hg.nginx.org/nginx/raw-file/default/conf/mime.types)
  37. - `.extensions[]` - known extensions associated with this mime type.
  38. - `.compressible` - whether a file of this type can be gzipped.
  39. - `.charset` - the default charset associated with this type, if any.
  40. If unknown, every property could be `undefined`.
  41. ## Note on MIME Type Data and Semver
  42. This package considers the programmatic api as the semver compatibility. This means the MIME type resolution is *not* considered
  43. in the semver bumps. This means that if you want to pin your `mime-db` data you will need to do it in your application. While
  44. this expectation was not set in docs until now, it is how the pacakge operated, so we do not feel this is a breaking change.
  45. ## Contributing
  46. The primary way to contribute to this database is by updating the data in
  47. one of the upstream sources. The database is updated from the upstreams
  48. periodically and will pull in any changes.
  49. ### Registering Media Types
  50. The best way to get new media types included in this library is to register
  51. them with the IANA. The community registration procedure is outlined in
  52. [RFC 6838 section 5](https://tools.ietf.org/html/rfc6838#section-5). Types
  53. registered with the IANA are automatically pulled into this library.
  54. ### Direct Inclusion
  55. If that is not possible / feasible, they can be added directly here as a
  56. "custom" type. To do this, it is required to have a primary source that
  57. definitively lists the media type. If an extension is going to be listed as
  58. associated with this media type, the source must definitively link the
  59. media type and extension as well.
  60. To edit the database, only make PRs against `src/custom-types.json` or
  61. `src/custom-suffix.json`.
  62. The `src/custom-types.json` file is a JSON object with the MIME type as the
  63. keys and the values being an object with the following keys:
  64. - `compressible` - leave out if you don't know, otherwise `true`/`false` to
  65. indicate whether the data represented by the type is typically compressible.
  66. - `extensions` - include an array of file extensions that are associated with
  67. the type.
  68. - `notes` - human-readable notes about the type, typically what the type is.
  69. - `sources` - include an array of URLs of where the MIME type and the associated
  70. extensions are sourced from. This needs to be a [primary source](https://en.wikipedia.org/wiki/Primary_source);
  71. links to type aggregating sites and Wikipedia are _not acceptable_.
  72. To update the build, run `npm run build`.
  73. [ci-image]: https://badgen.net/github/checks/jshttp/mime-db/master?label=ci
  74. [ci-url]: https://github.com/jshttp/mime-db/actions/workflows/ci.yml
  75. [coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/mime-db/master
  76. [coveralls-url]: https://coveralls.io/r/jshttp/mime-db?branch=master
  77. [node-image]: https://badgen.net/npm/node/mime-db
  78. [node-url]: https://nodejs.org/en/download
  79. [npm-downloads-image]: https://badgen.net/npm/dm/mime-db
  80. [npm-url]: https://npmjs.org/package/mime-db
  81. [npm-version-image]: https://badgen.net/npm/v/mime-db