[Pkg-javascript-commits] [node-mime-types] 01/08: New upstream version 2.1.17

Praveen Arimbrathodiyil praveen at moszumanska.debian.org
Tue Sep 5 06:24:03 UTC 2017


This is an automated email from the git hooks/post-receive script.

praveen pushed a commit to branch master
in repository node-mime-types.

commit c6097a63cfccceaddba927eb892d999d3156821d
Author: Pirate Praveen <praveen at debian.org>
Date:   Tue Sep 5 10:36:32 2017 +0530

    New upstream version 2.1.17
---
 .eslintignore  |   2 +
 .eslintrc      |   3 +
 .gitignore     |   8 ++
 .travis.yml    |  38 +++++++--
 HISTORY.md     | 208 +++++++++++++++++++++++++++++++++++++++++++++
 LICENSE        |  37 ++++----
 README.md      |  41 +++++----
 index.js       | 217 +++++++++++++++++++++++++++++++++++++----------
 package.json   |  16 +++-
 test/.eslintrc |   5 ++
 test/mime.js   |  66 ---------------
 test/test.js   | 263 ++++++++++++++++++++++++++++++++++++++++++---------------
 12 files changed, 676 insertions(+), 228 deletions(-)

diff --git a/.eslintignore b/.eslintignore
new file mode 100644
index 0000000..62562b7
--- /dev/null
+++ b/.eslintignore
@@ -0,0 +1,2 @@
+coverage
+node_modules
diff --git a/.eslintrc b/.eslintrc
new file mode 100644
index 0000000..e3578aa
--- /dev/null
+++ b/.eslintrc
@@ -0,0 +1,3 @@
+{
+  "extends": "standard"
+}
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..158df32
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,8 @@
+
+.DS_Store*
+*.log
+*.gz
+
+node_modules
+package-lock.json
+coverage
diff --git a/.travis.yml b/.travis.yml
index f034de0..45eb54e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,13 +3,35 @@ node_js:
   - "0.6"
   - "0.8"
   - "0.10"
-  - "0.11"
-matrix:
-  allow_failures:
-    - node_js: "0.11"
-  fast_finish: true
+  - "0.12"
+  - "1.8"
+  - "2.2"
+  - "2.5"
+  - "3.3"
+  - "4.8"
+  - "5.12"
+  - "6.11"
+  - "7.10"
+  - "8.4"
+sudo: false
+dist: percise
+cache:
+  directories:
+    - node_modules
+before_install:
+  # Skip updating shrinkwrap / lock
+  - "npm config set shrinkwrap false"
+  # Setup Node.js version-specific dependencies
+  - "test $TRAVIS_NODE_VERSION != '0.6' || npm rm --save-dev istanbul"
+  - "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul"
+  - "test $(echo $TRAVIS_NODE_VERSION | cut -d. -f1) -ge 4 || npm rm --save-dev $(grep -E '\"eslint\\S*\"' package.json | cut -d'\"' -f2)"
+  # Update Node.js modules
+  - "test ! -d node_modules || npm prune"
+  - "test ! -d node_modules || npm rebuild"
 script:
-  - "test $TRAVIS_NODE_VERSION != '0.6' || npm test"
-  - "test $TRAVIS_NODE_VERSION  = '0.6' || npm run-script test-travis"
+  # Run test script, depending on istanbul install
+  - "test ! -z $(npm -ps ls istanbul) || npm test"
+  - "test   -z $(npm -ps ls istanbul) || npm run-script test-travis"
+  - "test   -z $(npm -ps ls eslint  ) || npm run-script lint"
 after_script:
-  - "test $TRAVIS_NODE_VERSION = '0.10' && npm install coveralls at 2 && cat ./coverage/lcov.info | coveralls"
+  - "test -e ./coverage/lcov.info && npm install coveralls at 2 && cat ./coverage/lcov.info | coveralls"
diff --git a/HISTORY.md b/HISTORY.md
index 6071381..7517c11 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -1,3 +1,211 @@
+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
 ==================
 
diff --git a/LICENSE b/LICENSE
index a7ae8ee..0616607 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,22 +1,23 @@
+(The MIT License)
 
-The MIT License (MIT)
+Copyright (c) 2014 Jonathan Ong <me at jongleberry.com>
+Copyright (c) 2015 Douglas Christopher Wilson <doug at somethingdoug.com>
 
-Copyright (c) 2014 Jonathan Ong me at jongleberry.com
+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:
 
-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 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.
+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.
diff --git a/README.md b/README.md
index 99d658b..571031c 100644
--- a/README.md
+++ b/README.md
@@ -8,25 +8,30 @@
 
 The ultimate javascript content-type utility.
 
-Similar to [node-mime](https://github.com/broofa/node-mime), except:
+Similar to [the `mime` 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 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`.
-- Additional mime types are added such as jade and stylus via [mime-db](https://github.com/jshttp/mime-db)
 - No `.define()` functionality
+- Bug fixes for `.lookup(path)`
 
 Otherwise, the API is compatible.
 
 ## 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://github.com/jshttp/mime-db),
+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
@@ -42,10 +47,11 @@ All functions return `false` if input is invalid or not found.
 Lookup the content-type associated with a file.
 
 ```js
-mime.lookup('json')           // 'application/json'
-mime.lookup('.md')            // 'text/x-markdown'
-mime.lookup('file.html')      // 'text/html'
-mime.lookup('folder/file.js') // 'application/javascript'
+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
 ```
@@ -57,6 +63,9 @@ Create a full content-type header given a content-type or extension.
 ```js
 mime.contentType('markdown')  // 'text/x-markdown; charset=utf-8'
 mime.contentType('file.json') // 'application/json; charset=utf-8'
+
+// from a full path
+mime.contentType(path.extname('/path/to/file.json')) // 'application/json; charset=utf-8'
 ```
 
 ### mime.extension(type)
@@ -72,7 +81,7 @@ mime.extension('application/octet-stream') // 'bin'
 Lookup the implied default charset of a content-type.
 
 ```js
-mime.charset('text/x-markdown') // 'UTF-8'
+mime.charset('text/markdown') // 'UTF-8'
 ```
 
 ### var type = mime.types[extension]
@@ -87,13 +96,13 @@ A map of extensions by content-type.
 
 [MIT](LICENSE)
 
-[npm-image]: https://img.shields.io/npm/v/mime-types.svg?style=flat
+[npm-image]: https://img.shields.io/npm/v/mime-types.svg
 [npm-url]: https://npmjs.org/package/mime-types
-[node-version-image]: https://img.shields.io/badge/node.js-%3E%3D_0.6-brightgreen.svg?style=flat
-[node-version-url]: http://nodejs.org/download/
-[travis-image]: https://img.shields.io/travis/jshttp/mime-types.svg?style=flat
+[node-version-image]: https://img.shields.io/node/v/mime-types.svg
+[node-version-url]: https://nodejs.org/en/download/
+[travis-image]: https://img.shields.io/travis/jshttp/mime-types/master.svg
 [travis-url]: https://travis-ci.org/jshttp/mime-types
-[coveralls-image]: https://img.shields.io/coveralls/jshttp/mime-types.svg?style=flat
+[coveralls-image]: https://img.shields.io/coveralls/jshttp/mime-types/master.svg
 [coveralls-url]: https://coveralls.io/r/jshttp/mime-types
-[downloads-image]: https://img.shields.io/npm/dm/mime-types.svg?style=flat
+[downloads-image]: https://img.shields.io/npm/dm/mime-types.svg
 [downloads-url]: https://npmjs.org/package/mime-types
diff --git a/index.js b/index.js
index b46a202..b9f34d5 100644
--- a/index.js
+++ b/index.js
@@ -1,63 +1,188 @@
+/*!
+ * 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
 
-// types[extension] = type
-exports.types = Object.create(null)
-// extensions[type] = [extensions]
+/**
+ * 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)
 
-Object.keys(db).forEach(function (name) {
-  var mime = db[name]
-  var exts = mime.extensions
-  if (!exts || !exts.length) return
-  exports.extensions[name] = exts
-  exts.forEach(function (ext) {
-    exports.types[ext] = name
-  })
-})
-
-exports.lookup = function (string) {
-  if (!string || typeof string !== "string") return false
-  // remove any leading paths, though we should just use path.basename
-  string = string.replace(/.*[\.\/\\]/, '').toLowerCase()
-  if (!string) return false
-  return exports.types[string] || false
-}
+// Populate the extensions/types maps
+populateMaps(exports.extensions, exports.types)
 
-exports.extension = function (type) {
-  if (!type || typeof type !== "string") return false
-  // to do: use media-typer
-  type = type.match(/^\s*([^;\s]*)(?:;|\s|$)/)
-  if (!type) return false
-  var exts = exports.extensions[type[1].toLowerCase()]
-  if (!exts || !exts.length) return false
-  return exts[0]
-}
+/**
+ * Get the default charset for a MIME type.
+ *
+ * @param {string} type
+ * @return {boolean|string}
+ */
+
+function charset (type) {
+  if (!type || typeof type !== 'string') {
+    return false
+  }
 
-// type has to be an exact mime type
-exports.charset = function (type) {
-  var mime = db[type]
-  if (mime && mime.charset) return mime.charset
+  // 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 (/^text\//.test(type)) return 'UTF-8'
+  if (match && TEXT_TYPE_REGEXP.test(match[1])) {
+    return 'UTF-8'
+  }
 
   return false
 }
 
-// backwards compatibility
-exports.charsets = {
-  lookup: exports.charset
+/**
+ * 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]
 }
 
-// to do: maybe use set-type module or something
-exports.contentType = function (type) {
-  if (!type || typeof type !== "string") return false
-  if (!~type.indexOf('/')) type = exports.lookup(type)
-  if (!type) return false
-  if (!~type.indexOf('charset')) {
-    var charset = exports.charset(type)
-    if (charset) type += '; charset=' + charset.toLowerCase()
+/**
+ * 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 type
+
+  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
+    }
+  })
 }
diff --git a/package.json b/package.json
index f5a6826..410aa2d 100644
--- a/package.json
+++ b/package.json
@@ -1,8 +1,9 @@
 {
   "name": "mime-types",
   "description": "The ultimate javascript content-type utility.",
-  "version": "2.0.2",
+  "version": "2.1.17",
   "contributors": [
+    "Douglas Christopher Wilson <doug at somethingdoug.com>",
     "Jeremiah Senkpiel <fishrock123 at rocketmail.com> (https://searchbeam.jit.su)",
     "Jonathan Ong <me at jongleberry.com> (http://jongleberry.com)"
   ],
@@ -13,11 +14,17 @@
   ],
   "repository": "jshttp/mime-types",
   "dependencies": {
-    "mime-db": "~1.1.0"
+    "mime-db": "~1.30.0"
   },
   "devDependencies": {
-    "istanbul": "0",
-    "mocha": "1"
+    "eslint": "3.19.0",
+    "eslint-config-standard": "10.2.1",
+    "eslint-plugin-import": "2.7.0",
+    "eslint-plugin-node": "5.1.1",
+    "eslint-plugin-promise": "3.5.0",
+    "eslint-plugin-standard": "3.0.1",
+    "istanbul": "0.4.5",
+    "mocha": "1.21.5"
   },
   "files": [
     "HISTORY.md",
@@ -28,6 +35,7 @@
     "node": ">= 0.6"
   },
   "scripts": {
+    "lint": "eslint .",
     "test": "mocha --reporter spec test/test.js",
     "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot test/test.js",
     "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot test/test.js"
diff --git a/test/.eslintrc b/test/.eslintrc
new file mode 100644
index 0000000..7eeefc3
--- /dev/null
+++ b/test/.eslintrc
@@ -0,0 +1,5 @@
+{
+  "env": {
+    "mocha": true
+  }
+}
diff --git a/test/mime.js b/test/mime.js
deleted file mode 100644
index df0c998..0000000
--- a/test/mime.js
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * Usage: node test.js
- */
-
-var mime = require("..");
-var assert = require('assert');
-var path = require('path');
-
-function eq(a, b) {
-  console.log('Test: ' + a + ' === ' + b);
-  assert.strictEqual.apply(null, arguments);
-}
-
-console.log(Object.keys(mime.extensions).length + ' types');
-console.log(Object.keys(mime.types).length + ' extensions\n');
-
-//
-// Test mime lookups
-//
-
-eq('text/plain', mime.lookup('text.txt'));     // normal file
-eq('text/plain', mime.lookup('TEXT.TXT'));     // uppercase
-eq('text/plain', mime.lookup('dir/text.txt')); // dir + file
-eq('text/plain', mime.lookup('.text.txt'));    // hidden file
-eq('text/plain', mime.lookup('.txt'));         // nameless
-eq('text/plain', mime.lookup('txt'));          // extension-only
-eq('text/plain', mime.lookup('/txt'));         // extension-less ()
-eq('text/plain', mime.lookup('\\txt'));        // Windows, extension-less
-// eq('application/octet-stream', mime.lookup('text.nope')); // unrecognized
-// eq('fallback', mime.lookup('text.fallback', 'fallback')); // alternate default
-
-//
-// Test extensions
-//
-
-eq('txt', mime.extension(mime.types.text));
-eq('html', mime.extension(mime.types.htm));
-eq('bin', mime.extension('application/octet-stream'));
-eq('bin', mime.extension('application/octet-stream '));
-eq('html', mime.extension(' text/html; charset=UTF-8'));
-eq('html', mime.extension('text/html; charset=UTF-8 '));
-eq('html', mime.extension('text/html; charset=UTF-8'));
-eq('html', mime.extension('text/html ; charset=UTF-8'));
-eq('html', mime.extension('text/html;charset=UTF-8'));
-eq('html', mime.extension('text/Html;charset=UTF-8'));
-eq(false, mime.extension('unrecognized'));
-
-//
-// Test node.types lookups
-//
-
-eq('application/font-woff', mime.lookup('file.woff'));
-eq('application/octet-stream', mime.lookup('file.buffer'));
-eq('audio/mp4', mime.lookup('file.m4a'));
-eq('font/opentype', mime.lookup('file.otf'));
-
-//
-// Test charsets
-//
-
-eq('UTF-8', mime.charset('text/plain'));
-eq('UTF-8', mime.charset(mime.types.js));
-eq('UTF-8', mime.charset('application/json'))
-eq('UTF-8', mime.charsets.lookup('text/something'));
-eq(false, mime.charsets.lookup('application/octet-stream'));
-// eq('fallback', mime.charset('application/octet-stream', 'fallback'));
diff --git a/test/test.js b/test/test.js
index be95304..472cbcc 100644
--- a/test/test.js
+++ b/test/test.js
@@ -1,104 +1,227 @@
 
 var assert = require('assert')
+var mimeTypes = require('..')
 
-var mime = require('..')
+describe('mimeTypes', function () {
+  describe('.charset(type)', function () {
+    it('should return "UTF-8" for "application/json"', function () {
+      assert.equal(mimeTypes.charset('application/json'), 'UTF-8')
+    })
 
-var lookup = mime.lookup
-var extension = mime.extension
-var charset = mime.charset
-var contentType = mime.contentType
+    it('should return "UTF-8" for "application/json; foo=bar"', function () {
+      assert.equal(mimeTypes.charset('application/json; foo=bar'), 'UTF-8')
+    })
 
-it('should pass most of node-mime\'s tests', function () {
-  require('./mime')
-})
+    it('should return "UTF-8" for "application/javascript"', function () {
+      assert.equal(mimeTypes.charset('application/javascript'), 'UTF-8')
+    })
 
-describe('.lookup()', function () {
+    it('should return "UTF-8" for "application/JavaScript"', function () {
+      assert.equal(mimeTypes.charset('application/JavaScript'), 'UTF-8')
+    })
 
-  it('jade', function () {
-    assert.equal(lookup('jade'), 'text/jade')
-    assert.equal(lookup('.jade'), 'text/jade')
-    assert.equal(lookup('file.jade'), 'text/jade')
-    assert.equal(lookup('folder/file.jade'), 'text/jade')
-  })
+    it('should return "UTF-8" for "text/html"', function () {
+      assert.equal(mimeTypes.charset('text/html'), 'UTF-8')
+    })
 
-  it('should not error on non-string types', function () {
-    assert.doesNotThrow(function () {
-      lookup({ noteven: "once" })
-      lookup(null)
-      lookup(true)
-      lookup(Infinity)
+    it('should return "UTF-8" for "TEXT/HTML"', function () {
+      assert.equal(mimeTypes.charset('TEXT/HTML'), 'UTF-8')
     })
-  })
 
-  it('should return false for unknown types', function () {
-    assert.equal(lookup('.jalksdjflakjsdjfasdf'), false)
-  })
-})
+    it('should return "UTF-8" for any text/*', function () {
+      assert.equal(mimeTypes.charset('text/x-bogus'), 'UTF-8')
+    })
 
-describe('.extension()', function () {
+    it('should return false for unknown types', function () {
+      assert.strictEqual(mimeTypes.charset('application/x-bogus'), false)
+    })
 
-  it('should not error on non-string types', function () {
-    assert.doesNotThrow(function () {
-      extension({ noteven: "once" })
-      extension(null)
-      extension(true)
-      extension(Infinity)
+    it('should return false for any application/octet-stream', function () {
+      assert.strictEqual(mimeTypes.charset('application/octet-stream'), false)
     })
-  })
 
-  it('should return false for unknown types', function () {
-    assert.equal(extension('.jalksdjflakjsdjfasdf'), 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('.charset()', function () {
+  describe('.contentType(extension)', function () {
+    it('should return content-type for "html"', function () {
+      assert.equal(mimeTypes.contentType('html'), 'text/html; charset=utf-8')
+    })
 
-  it('should not error on non-string types', function () {
-    assert.doesNotThrow(function () {
-      charset({ noteven: "once" })
-      charset(null)
-      charset(true)
-      charset(Infinity)
+    it('should return content-type for ".html"', function () {
+      assert.equal(mimeTypes.contentType('.html'), 'text/html; charset=utf-8')
     })
-  })
 
-  it('should return false for unknown types', function () {
-    assert.equal(charset('.jalksdjflakjsdjfasdf'), false)
-  })
-})
+    it('should return content-type for "jade"', function () {
+      assert.equal(mimeTypes.contentType('jade'), 'text/jade; charset=utf-8')
+    })
 
-describe('.contentType()', function () {
+    it('should return content-type for "json"', function () {
+      assert.equal(mimeTypes.contentType('json'), 'application/json; charset=utf-8')
+    })
 
-  it('html', function () {
-    assert.equal(contentType('html'), 'text/html; charset=utf-8')
-  })
+    it('should return false for unknown extensions', function () {
+      assert.strictEqual(mimeTypes.contentType('bogus'), false)
+    })
 
-  it('text/html; charset=ascii', function () {
-    assert.equal(contentType('text/html; charset=ascii'), 'text/html; charset=ascii')
+    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)
+    })
   })
 
-  it('json', function () {
-    assert.equal(contentType('json'), 'application/json; charset=utf-8')
-  })
+  describe('.contentType(type)', function () {
+    it('should attach charset to "application/json"', function () {
+      assert.equal(mimeTypes.contentType('application/json'), 'application/json; charset=utf-8')
+    })
+
+    it('should attach charset to "application/json; foo=bar"', function () {
+      assert.equal(mimeTypes.contentType('application/json; foo=bar'), 'application/json; foo=bar; charset=utf-8')
+    })
+
+    it('should attach charset to "TEXT/HTML"', function () {
+      assert.equal(mimeTypes.contentType('TEXT/HTML'), 'TEXT/HTML; charset=utf-8')
+    })
 
-  it('application/json', function () {
-    assert.equal(contentType('application/json'), 'application/json; charset=utf-8')
+    it('should attach charset to "text/html"', function () {
+      assert.equal(mimeTypes.contentType('text/html'), 'text/html; charset=utf-8')
+    })
+
+    it('should not alter "text/html; charset=iso-8859-1"', function () {
+      assert.equal(mimeTypes.contentType('text/html; charset=iso-8859-1'), 'text/html; charset=iso-8859-1')
+    })
+
+    it('should return type for unknown types', function () {
+      assert.equal(mimeTypes.contentType('application/x-bogus'), 'application/x-bogus')
+    })
   })
 
-  it('jade', function () {
-    assert.equal(contentType('jade'), 'text/jade; charset=utf-8')
+  describe('.extension(type)', function () {
+    it('should return extension for mime type', function () {
+      assert.equal(mimeTypes.extension('text/html'), 'html')
+      assert.equal(mimeTypes.extension(' text/html'), 'html')
+      assert.equal(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.equal(mimeTypes.extension('text/html;charset=UTF-8'), 'html')
+      assert.equal(mimeTypes.extension('text/HTML; charset=UTF-8'), 'html')
+      assert.equal(mimeTypes.extension('text/html; charset=UTF-8'), 'html')
+      assert.equal(mimeTypes.extension('text/html; charset=UTF-8 '), 'html')
+      assert.equal(mimeTypes.extension('text/html ; charset=UTF-8'), 'html')
+    })
   })
 
-  it('should not error on non-string types', function () {
-    assert.doesNotThrow(function () {
-      contentType({ noteven: "once" })
-      contentType(null)
-      contentType(true)
-      contentType(Infinity)
+  describe('.lookup(extension)', function () {
+    it('should return mime type for ".html"', function () {
+      assert.equal(mimeTypes.lookup('.html'), 'text/html')
+    })
+
+    it('should return mime type for ".js"', function () {
+      assert.equal(mimeTypes.lookup('.js'), 'application/javascript')
+    })
+
+    it('should return mime type for ".json"', function () {
+      assert.equal(mimeTypes.lookup('.json'), 'application/json')
+    })
+
+    it('should return mime type for ".rtf"', function () {
+      assert.equal(mimeTypes.lookup('.rtf'), 'application/rtf')
+    })
+
+    it('should return mime type for ".txt"', function () {
+      assert.equal(mimeTypes.lookup('.txt'), 'text/plain')
+    })
+
+    it('should return mime type for ".xml"', function () {
+      assert.equal(mimeTypes.lookup('.xml'), 'application/xml')
+    })
+
+    it('should work without the leading dot', function () {
+      assert.equal(mimeTypes.lookup('html'), 'text/html')
+      assert.equal(mimeTypes.lookup('xml'), 'application/xml')
+    })
+
+    it('should be case insensitive', function () {
+      assert.equal(mimeTypes.lookup('HTML'), 'text/html')
+      assert.equal(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)
     })
   })
 
-  it('should return false for unknown types', function () {
-    assert.equal(contentType('.jalksdjflakjsdjfasdf'), false)
+  describe('.lookup(path)', function () {
+    it('should return mime type for file name', function () {
+      assert.equal(mimeTypes.lookup('page.html'), 'text/html')
+    })
+
+    it('should return mime type for relative path', function () {
+      assert.equal(mimeTypes.lookup('path/to/page.html'), 'text/html')
+      assert.equal(mimeTypes.lookup('path\\to\\page.html'), 'text/html')
+    })
+
+    it('should return mime type for absolute path', function () {
+      assert.equal(mimeTypes.lookup('/path/to/page.html'), 'text/html')
+      assert.equal(mimeTypes.lookup('C:\\path\\to\\page.html'), 'text/html')
+    })
+
+    it('should be case insensitive', function () {
+      assert.equal(mimeTypes.lookup('/path/to/PAGE.HTML'), 'text/html')
+      assert.equal(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')
+      })
+    })
   })
 })

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-mime-types.git



More information about the Pkg-javascript-commits mailing list