pax_global_header00006660000000000000000000000064135625357040014524gustar00rootroot0000000000000052 comment=7aaede09275fb002f7bbd63060ed4c3a98575b9d mime-types-2.1.25/000077500000000000000000000000001356253570400137045ustar00rootroot00000000000000mime-types-2.1.25/.eslintignore000066400000000000000000000000261356253570400164050ustar00rootroot00000000000000coverage node_modules mime-types-2.1.25/.eslintrc.yml000066400000000000000000000000351356253570400163260ustar00rootroot00000000000000root: true extends: standard mime-types-2.1.25/.gitignore000066400000000000000000000001021356253570400156650ustar00rootroot00000000000000.nyc_output coverage node_modules npm-debug.log package-lock.json mime-types-2.1.25/.travis.yml000066400000000000000000000056501356253570400160230ustar00rootroot00000000000000language: node_js node_js: - "0.6" - "0.8" - "0.10" - "0.12" - "1.8" - "2.5" - "3.3" - "4.9" - "5.12" - "6.17" - "7.10" - "8.16" - "9.11" - "10.17" - "11.15" - "12.13" - "13.1" sudo: false dist: trusty env: global: # Suppress Node.js 0.6 compile warnings - "CXXCOM='$CXX -o $TARGET -c $CXXFLAGS $CCFLAGS -Wno-unused-local-typedefs -Wno-maybe-uninitialized -Wno-narrowing -Wno-strict-overflow $_CCCOMCOM $SOURCES'" cache: directories: - node_modules before_install: - | # Setup utility functions function node_version_lt () { [[ "$(v "$TRAVIS_NODE_VERSION")" -lt "$(v "${1}")" ]] } function npm_module_installed () { npm -lsp ls | grep -Fq "$(pwd)/node_modules/${1}:${1}@" } function npm_remove_module_re () { node -e ' fs = require("fs"); p = JSON.parse(fs.readFileSync("package.json", "utf8")); r = RegExp(process.argv[1]); for (k in p.devDependencies) { if (r.test(k)) delete p.devDependencies[k]; } fs.writeFileSync("package.json", JSON.stringify(p, null, 2) + "\n"); ' "$@" } function npm_use_module () { node -e ' fs = require("fs"); p = JSON.parse(fs.readFileSync("package.json", "utf8")); p.devDependencies[process.argv[1]] = process.argv[2]; fs.writeFileSync("package.json", JSON.stringify(p, null, 2) + "\n"); ' "$@" } function v () { tr '.' '\n' <<< "${1}" \ | awk '{ printf "%03d", $0 }' \ | sed 's/^0*//' } # Configure npm - | # Skip updating shrinkwrap / lock npm config set shrinkwrap false # Setup Node.js version-specific dependencies - | # Configure eslint for linting if node_version_lt '8.0'; then npm_remove_module_re '^eslint(-|$)' fi - | # Configure mocha for testing if node_version_lt '0.8' ; then npm_use_module 'mocha' '1.21.5' elif node_version_lt '0.10'; then npm_use_module 'mocha' '2.5.3' elif node_version_lt '4.0' ; then npm_use_module 'mocha' '3.5.3' elif node_version_lt '6.0' ; then npm_use_module 'mocha' '5.2.0' fi - | # Configure nyc for testing if node_version_lt '0.10'; then npm_remove_module_re '^nyc$' elif node_version_lt '4.0' ; then npm_use_module 'nyc' '10.3.2' elif node_version_lt '6.0' ; then npm_use_module 'nyc' '11.9.0' fi # Update Node.js modules - | # Prune & rebuild node_modules if [[ -d node_modules ]]; then npm prune npm rebuild fi before_scrpt: - | # Contents of node_modules npm -s ls ||: script: - | # Run test script if npm_module_installed 'nyc'; then npm run-script test-travis else npm test fi - | # Run linting, if eslint exists if npm_module_installed 'eslint'; then npm run-script lint fi after_script: - | # Upload coverage to coveralls npm install coveralls@2 nyc report --reporter=text-lcov | coveralls mime-types-2.1.25/HISTORY.md000066400000000000000000000147611356253570400154000ustar00rootroot000000000000002.1.25 / 2019-11-12 =================== * deps: mime-db@1.42.0 - Add new upstream MIME types - Add `application/toml` with extension `.toml` - Add `image/vnd.ms-dds` with extension `.dds` 2.1.24 / 2019-04-20 =================== * deps: mime-db@1.40.0 - Add extensions from IANA for `model/*` types - Add `text/mdx` with extension `.mdx` 2.1.23 / 2019-04-17 =================== * deps: mime-db@~1.39.0 - Add extensions `.siv` and `.sieve` to `application/sieve` - Add new upstream MIME types 2.1.22 / 2019-02-14 =================== * deps: mime-db@~1.38.0 - Add extension `.nq` to `application/n-quads` - Add extension `.nt` to `application/n-triples` - Add new upstream MIME types - Mark `text/less` as compressible 2.1.21 / 2018-10-19 =================== * deps: mime-db@~1.37.0 - Add extensions to HEIC image types - Add new upstream MIME types 2.1.20 / 2018-08-26 =================== * deps: mime-db@~1.36.0 - Add Apple file extensions from IANA - Add extensions from IANA for `image/*` types - Add new upstream MIME types 2.1.19 / 2018-07-17 =================== * deps: mime-db@~1.35.0 - Add extension `.csl` to `application/vnd.citationstyles.style+xml` - Add extension `.es` to `application/ecmascript` - Add extension `.owl` to `application/rdf+xml` - Add new upstream MIME types - Add UTF-8 as default charset for `text/turtle` 2.1.18 / 2018-02-16 =================== * deps: mime-db@~1.33.0 - Add `application/raml+yaml` with extension `.raml` - Add `application/wasm` with extension `.wasm` - Add `text/shex` with extension `.shex` - Add extensions for JPEG-2000 images - Add extensions from IANA for `message/*` types - Add new upstream MIME types - Update font MIME types - Update `text/hjson` to registered `application/hjson` 2.1.17 / 2017-09-01 =================== * deps: mime-db@~1.30.0 - Add `application/vnd.ms-outlook` - Add `application/x-arj` - Add extension `.mjs` to `application/javascript` - Add glTF types and extensions - Add new upstream MIME types - Add `text/x-org` - Add VirtualBox MIME types - Fix `source` records for `video/*` types that are IANA - Update `font/opentype` to registered `font/otf` 2.1.16 / 2017-07-24 =================== * deps: mime-db@~1.29.0 - Add `application/fido.trusted-apps+json` - Add extension `.wadl` to `application/vnd.sun.wadl+xml` - Add extension `.gz` to `application/gzip` - Add new upstream MIME types - Update extensions `.md` and `.markdown` to be `text/markdown` 2.1.15 / 2017-03-23 =================== * deps: mime-db@~1.27.0 - Add new mime types - Add `image/apng` 2.1.14 / 2017-01-14 =================== * deps: mime-db@~1.26.0 - Add new mime types 2.1.13 / 2016-11-18 =================== * deps: mime-db@~1.25.0 - Add new mime types 2.1.12 / 2016-09-18 =================== * deps: mime-db@~1.24.0 - Add new mime types - Add `audio/mp3` 2.1.11 / 2016-05-01 =================== * deps: mime-db@~1.23.0 - Add new mime types 2.1.10 / 2016-02-15 =================== * deps: mime-db@~1.22.0 - Add new mime types - Fix extension of `application/dash+xml` - Update primary extension for `audio/mp4` 2.1.9 / 2016-01-06 ================== * deps: mime-db@~1.21.0 - Add new mime types 2.1.8 / 2015-11-30 ================== * deps: mime-db@~1.20.0 - Add new mime types 2.1.7 / 2015-09-20 ================== * deps: mime-db@~1.19.0 - Add new mime types 2.1.6 / 2015-09-03 ================== * deps: mime-db@~1.18.0 - Add new mime types 2.1.5 / 2015-08-20 ================== * deps: mime-db@~1.17.0 - Add new mime types 2.1.4 / 2015-07-30 ================== * deps: mime-db@~1.16.0 - Add new mime types 2.1.3 / 2015-07-13 ================== * deps: mime-db@~1.15.0 - Add new mime types 2.1.2 / 2015-06-25 ================== * deps: mime-db@~1.14.0 - Add new mime types 2.1.1 / 2015-06-08 ================== * perf: fix deopt during mapping 2.1.0 / 2015-06-07 ================== * Fix incorrectly treating extension-less file name as extension - i.e. `'path/to/json'` will no longer return `application/json` * Fix `.charset(type)` to accept parameters * Fix `.charset(type)` to match case-insensitive * Improve generation of extension to MIME mapping * Refactor internals for readability and no argument reassignment * Prefer `application/*` MIME types from the same source * Prefer any type over `application/octet-stream` * deps: mime-db@~1.13.0 - Add nginx as a source - Add new mime types 2.0.14 / 2015-06-06 =================== * deps: mime-db@~1.12.0 - Add new mime types 2.0.13 / 2015-05-31 =================== * deps: mime-db@~1.11.0 - Add new mime types 2.0.12 / 2015-05-19 =================== * deps: mime-db@~1.10.0 - Add new mime types 2.0.11 / 2015-05-05 =================== * deps: mime-db@~1.9.1 - Add new mime types 2.0.10 / 2015-03-13 =================== * deps: mime-db@~1.8.0 - Add new mime types 2.0.9 / 2015-02-09 ================== * deps: mime-db@~1.7.0 - Add new mime types - Community extensions ownership transferred from `node-mime` 2.0.8 / 2015-01-29 ================== * deps: mime-db@~1.6.0 - Add new mime types 2.0.7 / 2014-12-30 ================== * deps: mime-db@~1.5.0 - Add new mime types - Fix various invalid MIME type entries 2.0.6 / 2014-12-30 ================== * deps: mime-db@~1.4.0 - Add new mime types - Fix various invalid MIME type entries - Remove example template MIME types 2.0.5 / 2014-12-29 ================== * deps: mime-db@~1.3.1 - Fix missing extensions 2.0.4 / 2014-12-10 ================== * deps: mime-db@~1.3.0 - Add new mime types 2.0.3 / 2014-11-09 ================== * deps: mime-db@~1.2.0 - Add new mime types 2.0.2 / 2014-09-28 ================== * deps: mime-db@~1.1.0 - Add new mime types - Add additional compressible - Update charsets 2.0.1 / 2014-09-07 ================== * Support Node.js 0.6 2.0.0 / 2014-09-02 ================== * Use `mime-db` * Remove `.define()` 1.0.2 / 2014-08-04 ================== * Set charset=utf-8 for `text/javascript` 1.0.1 / 2014-06-24 ================== * Add `text/jsx` type 1.0.0 / 2014-05-12 ================== * Return `false` for unknown types * Set charset=utf-8 for `application/json` 0.1.0 / 2014-05-02 ================== * Initial release mime-types-2.1.25/LICENSE000066400000000000000000000022171356253570400147130ustar00rootroot00000000000000(The MIT License) Copyright (c) 2014 Jonathan Ong Copyright (c) 2015 Douglas Christopher Wilson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. mime-types-2.1.25/README.md000066400000000000000000000066461356253570400151770ustar00rootroot00000000000000# mime-types [![NPM Version][npm-version-image]][npm-url] [![NPM Downloads][npm-downloads-image]][npm-url] [![Node.js Version][node-version-image]][node-version-url] [![Build Status][travis-image]][travis-url] [![Test Coverage][coveralls-image]][coveralls-url] The ultimate javascript content-type utility. Similar to [the `mime@1.x` module](https://www.npmjs.com/package/mime), except: - __No fallbacks.__ Instead of naively returning the first available type, `mime-types` simply returns `false`, so do `var type = mime.lookup('unrecognized') || 'application/octet-stream'`. - No `new Mime()` business, so you could do `var lookup = require('mime-types').lookup`. - No `.define()` functionality - Bug fixes for `.lookup(path)` Otherwise, the API is compatible with `mime` 1.x. ## Install This is a [Node.js](https://nodejs.org/en/) module available through the [npm registry](https://www.npmjs.com/). Installation is done using the [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally): ```sh $ npm install mime-types ``` ## Adding Types All mime types are based on [mime-db](https://www.npmjs.com/package/mime-db), so open a PR there if you'd like to add mime types. ## API ```js var mime = require('mime-types') ``` All functions return `false` if input is invalid or not found. ### mime.lookup(path) Lookup the content-type associated with a file. ```js mime.lookup('json') // 'application/json' mime.lookup('.md') // 'text/markdown' mime.lookup('file.html') // 'text/html' mime.lookup('folder/file.js') // 'application/javascript' mime.lookup('folder/.htaccess') // false mime.lookup('cats') // false ``` ### mime.contentType(type) Create 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. ```js mime.contentType('markdown') // 'text/x-markdown; charset=utf-8' mime.contentType('file.json') // 'application/json; charset=utf-8' mime.contentType('text/html') // 'text/html; charset=utf-8' mime.contentType('text/html; charset=iso-8859-1') // 'text/html; charset=iso-8859-1' // from a full path mime.contentType(path.extname('/path/to/file.json')) // 'application/json; charset=utf-8' ``` ### mime.extension(type) Get the default extension for a content-type. ```js mime.extension('application/octet-stream') // 'bin' ``` ### mime.charset(type) Lookup the implied default charset of a content-type. ```js mime.charset('text/markdown') // 'UTF-8' ``` ### var type = mime.types[extension] A map of content-types by extension. ### [extensions...] = mime.extensions[type] A map of extensions by content-type. ## License [MIT](LICENSE) [coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/mime-types/master [coveralls-url]: https://coveralls.io/r/jshttp/mime-types?branch=master [node-version-image]: https://badgen.net/npm/node/mime-types [node-version-url]: https://nodejs.org/en/download [npm-downloads-image]: https://badgen.net/npm/dm/mime-types [npm-url]: https://npmjs.org/package/mime-types [npm-version-image]: https://badgen.net/npm/v/mime-types [travis-image]: https://badgen.net/travis/jshttp/mime-types/master [travis-url]: https://travis-ci.org/jshttp/mime-types mime-types-2.1.25/index.js000066400000000000000000000071171356253570400153570ustar00rootroot00000000000000/*! * mime-types * Copyright(c) 2014 Jonathan Ong * Copyright(c) 2015 Douglas Christopher Wilson * MIT Licensed */ 'use strict' /** * Module dependencies. * @private */ var db = require('mime-db') var extname = require('path').extname /** * Module variables. * @private */ var EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/ var TEXT_TYPE_REGEXP = /^text\//i /** * Module exports. * @public */ exports.charset = charset exports.charsets = { lookup: charset } exports.contentType = contentType exports.extension = extension exports.extensions = Object.create(null) exports.lookup = lookup exports.types = Object.create(null) // Populate the extensions/types maps populateMaps(exports.extensions, exports.types) /** * Get the default charset for a MIME type. * * @param {string} type * @return {boolean|string} */ function charset (type) { if (!type || typeof type !== 'string') { return false } // TODO: use media-typer var match = EXTRACT_TYPE_REGEXP.exec(type) var mime = match && db[match[1].toLowerCase()] if (mime && mime.charset) { return mime.charset } // default text/* to utf-8 if (match && TEXT_TYPE_REGEXP.test(match[1])) { return 'UTF-8' } return false } /** * Create a full Content-Type header given a MIME type or extension. * * @param {string} str * @return {boolean|string} */ function contentType (str) { // TODO: should this even be in this module? if (!str || typeof str !== 'string') { return false } var mime = str.indexOf('/') === -1 ? exports.lookup(str) : str if (!mime) { return false } // TODO: use content-type or other module if (mime.indexOf('charset') === -1) { var charset = exports.charset(mime) if (charset) mime += '; charset=' + charset.toLowerCase() } return mime } /** * Get the default extension for a MIME type. * * @param {string} type * @return {boolean|string} */ function extension (type) { if (!type || typeof type !== 'string') { return false } // TODO: use media-typer var match = EXTRACT_TYPE_REGEXP.exec(type) // get extensions var exts = match && exports.extensions[match[1].toLowerCase()] if (!exts || !exts.length) { return false } return exts[0] } /** * Lookup the MIME type for a file path/extension. * * @param {string} path * @return {boolean|string} */ function lookup (path) { if (!path || typeof path !== 'string') { return false } // get the extension ("ext" or ".ext" or full path) var extension = extname('x.' + path) .toLowerCase() .substr(1) if (!extension) { return false } return exports.types[extension] || false } /** * Populate the extensions and types maps. * @private */ function populateMaps (extensions, types) { // source preference (least -> most) var preference = ['nginx', 'apache', undefined, 'iana'] Object.keys(db).forEach(function forEachMimeType (type) { var mime = db[type] var exts = mime.extensions if (!exts || !exts.length) { return } // mime -> extensions extensions[type] = exts // extension -> mime for (var i = 0; i < exts.length; i++) { var extension = exts[i] if (types[extension]) { var from = preference.indexOf(db[types[extension]].source) var to = preference.indexOf(mime.source) if (types[extension] !== 'application/octet-stream' && (from > to || (from === to && types[extension].substr(0, 12) === 'application/'))) { // skip the remapping continue } } // set the extension -> mime types[extension] = type } }) } mime-types-2.1.25/package.json000066400000000000000000000021111356253570400161650ustar00rootroot00000000000000{ "name": "mime-types", "description": "The ultimate javascript content-type utility.", "version": "2.1.25", "contributors": [ "Douglas Christopher Wilson ", "Jeremiah Senkpiel (https://searchbeam.jit.su)", "Jonathan Ong (http://jongleberry.com)" ], "license": "MIT", "keywords": [ "mime", "types" ], "repository": "jshttp/mime-types", "dependencies": { "mime-db": "1.42.0" }, "devDependencies": { "eslint": "6.6.0", "eslint-config-standard": "14.1.0", "eslint-plugin-import": "2.18.2", "eslint-plugin-node": "10.0.0", "eslint-plugin-promise": "4.2.1", "eslint-plugin-standard": "4.0.1", "mocha": "6.2.2", "nyc": "14.1.1" }, "files": [ "HISTORY.md", "LICENSE", "index.js" ], "engines": { "node": ">= 0.6" }, "scripts": { "lint": "eslint .", "test": "mocha --reporter spec test/test.js", "test-cov": "nyc --reporter=html --reporter=text npm test", "test-travis": "nyc --reporter=text npm test" } } mime-types-2.1.25/test/000077500000000000000000000000001356253570400146635ustar00rootroot00000000000000mime-types-2.1.25/test/.eslintrc.yml000066400000000000000000000000231356253570400173020ustar00rootroot00000000000000env: mocha: true mime-types-2.1.25/test/test.js000066400000000000000000000213371356253570400162060ustar00rootroot00000000000000 var assert = require('assert') var mimeTypes = require('..') describe('mimeTypes', function () { describe('.charset(type)', function () { it('should return "UTF-8" for "application/json"', function () { assert.strictEqual(mimeTypes.charset('application/json'), 'UTF-8') }) it('should return "UTF-8" for "application/json; foo=bar"', function () { assert.strictEqual(mimeTypes.charset('application/json; foo=bar'), 'UTF-8') }) it('should return "UTF-8" for "application/javascript"', function () { assert.strictEqual(mimeTypes.charset('application/javascript'), 'UTF-8') }) it('should return "UTF-8" for "application/JavaScript"', function () { assert.strictEqual(mimeTypes.charset('application/JavaScript'), 'UTF-8') }) it('should return "UTF-8" for "text/html"', function () { assert.strictEqual(mimeTypes.charset('text/html'), 'UTF-8') }) it('should return "UTF-8" for "TEXT/HTML"', function () { assert.strictEqual(mimeTypes.charset('TEXT/HTML'), 'UTF-8') }) it('should return "UTF-8" for any text/*', function () { assert.strictEqual(mimeTypes.charset('text/x-bogus'), 'UTF-8') }) it('should return false for unknown types', function () { assert.strictEqual(mimeTypes.charset('application/x-bogus'), false) }) it('should return false for any application/octet-stream', function () { assert.strictEqual(mimeTypes.charset('application/octet-stream'), false) }) it('should return false for invalid arguments', function () { assert.strictEqual(mimeTypes.charset({}), false) assert.strictEqual(mimeTypes.charset(null), false) assert.strictEqual(mimeTypes.charset(true), false) assert.strictEqual(mimeTypes.charset(42), false) }) }) describe('.contentType(extension)', function () { it('should return content-type for "html"', function () { assert.strictEqual(mimeTypes.contentType('html'), 'text/html; charset=utf-8') }) it('should return content-type for ".html"', function () { assert.strictEqual(mimeTypes.contentType('.html'), 'text/html; charset=utf-8') }) it('should return content-type for "jade"', function () { assert.strictEqual(mimeTypes.contentType('jade'), 'text/jade; charset=utf-8') }) it('should return content-type for "json"', function () { assert.strictEqual(mimeTypes.contentType('json'), 'application/json; charset=utf-8') }) it('should return false for unknown extensions', function () { assert.strictEqual(mimeTypes.contentType('bogus'), false) }) it('should return false for invalid arguments', function () { assert.strictEqual(mimeTypes.contentType({}), false) assert.strictEqual(mimeTypes.contentType(null), false) assert.strictEqual(mimeTypes.contentType(true), false) assert.strictEqual(mimeTypes.contentType(42), false) }) }) describe('.contentType(type)', function () { it('should attach charset to "application/json"', function () { assert.strictEqual(mimeTypes.contentType('application/json'), 'application/json; charset=utf-8') }) it('should attach charset to "application/json; foo=bar"', function () { assert.strictEqual(mimeTypes.contentType('application/json; foo=bar'), 'application/json; foo=bar; charset=utf-8') }) it('should attach charset to "TEXT/HTML"', function () { assert.strictEqual(mimeTypes.contentType('TEXT/HTML'), 'TEXT/HTML; charset=utf-8') }) it('should attach charset to "text/html"', function () { assert.strictEqual(mimeTypes.contentType('text/html'), 'text/html; charset=utf-8') }) it('should not alter "text/html; charset=iso-8859-1"', function () { assert.strictEqual(mimeTypes.contentType('text/html; charset=iso-8859-1'), 'text/html; charset=iso-8859-1') }) it('should return type for unknown types', function () { assert.strictEqual(mimeTypes.contentType('application/x-bogus'), 'application/x-bogus') }) }) describe('.extension(type)', function () { it('should return extension for mime type', function () { assert.strictEqual(mimeTypes.extension('text/html'), 'html') assert.strictEqual(mimeTypes.extension(' text/html'), 'html') assert.strictEqual(mimeTypes.extension('text/html '), 'html') }) it('should return false for unknown type', function () { assert.strictEqual(mimeTypes.extension('application/x-bogus'), false) }) it('should return false for non-type string', function () { assert.strictEqual(mimeTypes.extension('bogus'), false) }) it('should return false for non-strings', function () { assert.strictEqual(mimeTypes.extension(null), false) assert.strictEqual(mimeTypes.extension(undefined), false) assert.strictEqual(mimeTypes.extension(42), false) assert.strictEqual(mimeTypes.extension({}), false) }) it('should return extension for mime type with parameters', function () { assert.strictEqual(mimeTypes.extension('text/html;charset=UTF-8'), 'html') assert.strictEqual(mimeTypes.extension('text/HTML; charset=UTF-8'), 'html') assert.strictEqual(mimeTypes.extension('text/html; charset=UTF-8'), 'html') assert.strictEqual(mimeTypes.extension('text/html; charset=UTF-8 '), 'html') assert.strictEqual(mimeTypes.extension('text/html ; charset=UTF-8'), 'html') }) }) describe('.lookup(extension)', function () { it('should return mime type for ".html"', function () { assert.strictEqual(mimeTypes.lookup('.html'), 'text/html') }) it('should return mime type for ".js"', function () { assert.strictEqual(mimeTypes.lookup('.js'), 'application/javascript') }) it('should return mime type for ".json"', function () { assert.strictEqual(mimeTypes.lookup('.json'), 'application/json') }) it('should return mime type for ".rtf"', function () { assert.strictEqual(mimeTypes.lookup('.rtf'), 'application/rtf') }) it('should return mime type for ".txt"', function () { assert.strictEqual(mimeTypes.lookup('.txt'), 'text/plain') }) it('should return mime type for ".xml"', function () { assert.strictEqual(mimeTypes.lookup('.xml'), 'application/xml') }) it('should work without the leading dot', function () { assert.strictEqual(mimeTypes.lookup('html'), 'text/html') assert.strictEqual(mimeTypes.lookup('xml'), 'application/xml') }) it('should be case insensitive', function () { assert.strictEqual(mimeTypes.lookup('HTML'), 'text/html') assert.strictEqual(mimeTypes.lookup('.Xml'), 'application/xml') }) it('should return false for unknown extension', function () { assert.strictEqual(mimeTypes.lookup('.bogus'), false) assert.strictEqual(mimeTypes.lookup('bogus'), false) }) it('should return false for non-strings', function () { assert.strictEqual(mimeTypes.lookup(null), false) assert.strictEqual(mimeTypes.lookup(undefined), false) assert.strictEqual(mimeTypes.lookup(42), false) assert.strictEqual(mimeTypes.lookup({}), false) }) }) describe('.lookup(path)', function () { it('should return mime type for file name', function () { assert.strictEqual(mimeTypes.lookup('page.html'), 'text/html') }) it('should return mime type for relative path', function () { assert.strictEqual(mimeTypes.lookup('path/to/page.html'), 'text/html') assert.strictEqual(mimeTypes.lookup('path\\to\\page.html'), 'text/html') }) it('should return mime type for absolute path', function () { assert.strictEqual(mimeTypes.lookup('/path/to/page.html'), 'text/html') assert.strictEqual(mimeTypes.lookup('C:\\path\\to\\page.html'), 'text/html') }) it('should be case insensitive', function () { assert.strictEqual(mimeTypes.lookup('/path/to/PAGE.HTML'), 'text/html') assert.strictEqual(mimeTypes.lookup('C:\\path\\to\\PAGE.HTML'), 'text/html') }) it('should return false for unknown extension', function () { assert.strictEqual(mimeTypes.lookup('/path/to/file.bogus'), false) }) it('should return false for path without extension', function () { assert.strictEqual(mimeTypes.lookup('/path/to/json'), false) }) describe('path with dotfile', function () { it('should return false when extension-less', function () { assert.strictEqual(mimeTypes.lookup('/path/to/.json'), false) }) it('should return mime type when there is extension', function () { assert.strictEqual(mimeTypes.lookup('/path/to/.config.json'), 'application/json') }) it('should return mime type when there is extension, but no path', function () { assert.strictEqual(mimeTypes.lookup('.config.json'), 'application/json') }) }) }) })