[Pkg-javascript-commits] [node-mime-types] 01/19: Imported Upstream version 2.0.1

Leo Iannacone l3on-guest at moszumanska.debian.org
Fri Oct 10 10:12:35 UTC 2014


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

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

commit df769282c3b974c8443a582ea628c053ba01937c
Author: Leo Iannacone <l3on at ubuntu.com>
Date:   Wed Sep 10 13:58:25 2014 +0200

    Imported Upstream version 2.0.1
---
 .npmignore               | 14 ----------
 .travis.yml              |  9 ++++---
 HISTORY.md               | 31 +++++++++++++++++++++++
 Makefile                 |  9 -------
 README.md                | 66 +++++++++++++++++++++++-------------------------
 SOURCES.md               | 17 -------------
 build.js                 | 57 -----------------------------------------
 component.json           | 16 ------------
 lib/index.js => index.js | 43 ++++++++++++-------------------
 lib/custom.json          | 27 --------------------
 package.json             | 43 ++++++++++++++++---------------
 test/mime.js             |  3 ++-
 test/test.js             |  4 +++
 13 files changed, 113 insertions(+), 226 deletions(-)

diff --git a/.npmignore b/.npmignore
deleted file mode 100644
index 919d51b..0000000
--- a/.npmignore
+++ /dev/null
@@ -1,14 +0,0 @@
-test
-build.js
-
-# OS generated files #
-######################
-.DS_Store*
-# Icon?
-ehthumbs.db
-Thumbs.db
-
-# Node.js #
-###########
-node_modules
-npm-debug.log
diff --git a/.travis.yml b/.travis.yml
index 73c85c6..f034de0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,6 @@
 language: node_js
 node_js:
+  - "0.6"
   - "0.8"
   - "0.10"
   - "0.11"
@@ -7,6 +8,8 @@ matrix:
   allow_failures:
     - node_js: "0.11"
   fast_finish: true
-before_install:
-  # remove build script deps before install
-  - node -pe 'f="./package.json";p=require(f);d=p.devDependencies;for(k in d){if("co"===k.substr(0,2))delete d[k]}require("fs").writeFileSync(f,JSON.stringify(p,null,2))'
+script:
+  - "test $TRAVIS_NODE_VERSION != '0.6' || npm test"
+  - "test $TRAVIS_NODE_VERSION  = '0.6' || npm run-script test-travis"
+after_script:
+  - "test $TRAVIS_NODE_VERSION = '0.10' && npm install coveralls at 2 && cat ./coverage/lcov.info | coveralls"
diff --git a/HISTORY.md b/HISTORY.md
new file mode 100644
index 0000000..510ea56
--- /dev/null
+++ b/HISTORY.md
@@ -0,0 +1,31 @@
+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
diff --git a/Makefile b/Makefile
deleted file mode 100644
index ceaf011..0000000
--- a/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
-
-build:
-	node --harmony-generators build.js
-
-test:
-	node test/mime.js
-	mocha --require should --reporter spec test/test.js
-
-.PHONY: build test
diff --git a/README.md b/README.md
index 8e21ee1..99d658b 100644
--- a/README.md
+++ b/README.md
@@ -1,32 +1,33 @@
 # mime-types
-[![NPM version](https://badge.fury.io/js/mime-types.svg)](https://badge.fury.io/js/mime-types) [![Build Status](https://travis-ci.org/expressjs/mime-types.svg?branch=master)](https://travis-ci.org/expressjs/mime-types)
 
-The ultimate javascript content-type utility.
-
-### Install
+[![NPM Version][npm-image]][npm-url]
+[![NPM Downloads][downloads-image]][downloads-url]
+[![Node.js Version][node-version-image]][node-version-url]
+[![Build Status][travis-image]][travis-url]
+[![Test Coverage][coveralls-image]][coveralls-url]
 
-```sh
-$ npm install mime-types
-```
+The ultimate javascript content-type utility.
 
-#### Similar to [node-mime](https://github.com/broofa/node-mime), except:
+Similar to [node-mime](https://github.com/broofa/node-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. Feel free to add more!
-- Browser support via Browserify and Component by converting lists to JSON files.
+- Additional mime types are added such as jade and stylus via [mime-db](https://github.com/jshttp/mime-db)
+- No `.define()` functionality
 
 Otherwise, the API is compatible.
 
-### Adding Types
+## Install
 
-If you'd like to add additional types,
-simply create a PR adding the type to `custom.json` and
-a reference link to the [sources](SOURCES.md).
+```sh
+$ npm install mime-types
+```
 
-Do __NOT__ edit `mime.json` or `node.json`.
-Those are pulled using `build.js`.
-You should only touch `custom.json`.
+## Adding Types
+
+All mime types are based on [mime-db](https://github.com/jshttp/mime-db),
+so open a PR there if you'd like to add mime types.
 
 ## API
 
@@ -74,28 +75,25 @@ Lookup the implied default charset of a content-type.
 mime.charset('text/x-markdown') // 'UTF-8'
 ```
 
-### mime.types[extension] = type
+### var type = mime.types[extension]
 
 A map of content-types by extension.
 
-### mime.extensions[type] = [extensions]
+### [extensions...] = mime.extensions[type]
 
 A map of extensions by content-type.
 
-### mime.define(types)
-
-Globally add definitions.
-`types` must be an object of the form:
-
-```js
-{
-  "<content-type>": [extensions...],
-  "<content-type>": [extensions...]
-}
-```
-
-See the `.json` files in `lib/` for examples.
-
 ## License
 
 [MIT](LICENSE)
+
+[npm-image]: https://img.shields.io/npm/v/mime-types.svg?style=flat
+[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
+[travis-url]: https://travis-ci.org/jshttp/mime-types
+[coveralls-image]: https://img.shields.io/coveralls/jshttp/mime-types.svg?style=flat
+[coveralls-url]: https://coveralls.io/r/jshttp/mime-types
+[downloads-image]: https://img.shields.io/npm/dm/mime-types.svg?style=flat
+[downloads-url]: https://npmjs.org/package/mime-types
diff --git a/SOURCES.md b/SOURCES.md
deleted file mode 100644
index 1d65012..0000000
--- a/SOURCES.md
+++ /dev/null
@@ -1,17 +0,0 @@
-
-### Sources for custom types
-
-This is a list of sources for any custom mime types.
-When adding custom mime types, please link to where you found the mime type,
-even if it's from an unofficial source.
-
-- `text/coffeescript` - http://coffeescript.org/#scripts
-- `text/x-handlebars-template` - https://handlebarsjs.com/#getting-started
-- `text/x-sass` & `text/x-scss` - https://github.com/janlelis/rubybuntu-mime/blob/master/sass.xml
-- `text.jsx` - http://facebook.github.io/react/docs/getting-started.html [[2]](https://github.com/facebook/react/blob/f230e0a03154e6f8a616e0da1fb3d97ffa1a6472/vendor/browser-transforms.js#L210)
-
-[Sources for node.json types](https://github.com/broofa/node-mime/blob/master/types/node.types)
-
-### Notes on weird types
-
-- `font/opentype` - This type is technically invalid according to the spec. No valid types begin with `font/`. No-one uses the official type of `application/vnd.ms-opentype` as the community standardized `application/x-font-otf`. However, chrome logs nonsense warnings unless opentype fonts are served with `font/opentype`. [[1]](http://stackoverflow.com/questions/2871655/proper-mime-type-for-fonts)
diff --git a/build.js b/build.js
deleted file mode 100644
index 6ba0171..0000000
--- a/build.js
+++ /dev/null
@@ -1,57 +0,0 @@
-
-/**
- * http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
- * https://github.com/broofa/node-mime/blob/master/types/node.types
- *
- * Convert these text files to JSON for browser usage.
- */
-
-var co = require('co')
-var fs = require('fs')
-var path = require('path')
-var cogent = require('cogent')
-
-function* get(url) {
-  var res = yield* cogent(url, {
-    string: true
-  })
-
-  if (res.statusCode !== 200)
-    throw new Error('got status code ' + res.statusCode + ' from ' + url)
-
-  var text = res.text
-  var json = {}
-  // http://en.wikipedia.org/wiki/Internet_media_type#Naming
-  /**
-   * Mime types and associated extensions are stored in the form:
-   *
-   *   <type> <ext> <ext> <ext>
-   *
-   * And some are commented out with a leading `#` because they have no associated extensions.
-   * This regexp checks whether a single line matches this format, ignoring lines that are just comments.
-   * We could also just remove all lines that start with `#` if we want to make the JSON files smaller
-   * and ignore all mime types without associated extensions.
-   */
-  var re = /^(?:# )?([\w-]+\/[\w\+\.-]+)(?:\s+\w+)*$/
-  text = text.split('\n')
-  .filter(Boolean)
-  .forEach(function (line) {
-    line = line.trim()
-    if (!line) return
-    var match = re.exec(line)
-    if (!match) return
-    // remove the leading # and <type> and return all the <ext>s
-    json[match[1]] = line.replace(/^(?:# )?([\w-]+\/[\w\+\.-]+)/, '')
-      .split(/\s+/)
-      .filter(Boolean)
-  })
-  fs.writeFileSync('lib/' + path.basename(url).split('.')[0] + '.json',
-    JSON.stringify(json, null, 2) + '\n')
-}
-
-co(function* () {
-  yield [
-    get('http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types'),
-    get('https://raw.githubusercontent.com/broofa/node-mime/master/types/node.types')
-  ]
-})()
diff --git a/component.json b/component.json
deleted file mode 100644
index fa67a6d..0000000
--- a/component.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
-  "name": "mime-types",
-  "description": "The ultimate javascript content-type utility.",
-  "version": "0.1.0",
-  "author": {
-    "name": "Jonathan Ong",
-    "email": "me at jongleberry.com",
-    "url": "http://jongleberry.com",
-    "twitter": "https://twitter.com/jongleberry"
-  },
-  "repository": "expressjs/mime-types",
-  "license": "MIT",
-  "main": "lib/index.js",
-  "scripts": ["lib/index.js"],
-  "json": ["mime.json", "node.json", "custom.json"]
-}
diff --git a/lib/index.js b/index.js
similarity index 64%
rename from lib/index.js
rename to index.js
index 27559ea..b46a202 100644
--- a/lib/index.js
+++ b/index.js
@@ -1,20 +1,24 @@
 
+var db = require('mime-db')
+
 // types[extension] = type
 exports.types = Object.create(null)
 // extensions[type] = [extensions]
 exports.extensions = Object.create(null)
-// define more mime types
-exports.define = define
 
-// store the json files
-exports.json = {
-  mime: require('./mime.json'),
-  node: require('./node.json'),
-  custom: require('./custom.json'),
-}
+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
@@ -22,6 +26,7 @@ exports.lookup = function (string) {
 
 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()]
@@ -31,10 +36,8 @@ exports.extension = function (type) {
 
 // type has to be an exact mime type
 exports.charset = function (type) {
-  // special cases
-  switch (type) {
-    case 'application/json': return 'UTF-8'
-  }
+  var mime = db[type]
+  if (mime && mime.charset) return mime.charset
 
   // default text/* to utf-8
   if (/^text\//.test(type)) return 'UTF-8'
@@ -47,6 +50,7 @@ exports.charsets = {
   lookup: exports.charset
 }
 
+// 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)
@@ -57,18 +61,3 @@ exports.contentType = function (type) {
   }
   return type
 }
-
-define(exports.json.mime)
-define(exports.json.node)
-define(exports.json.custom)
-
-function define(json) {
-  Object.keys(json).forEach(function (type) {
-    var exts = json[type] || []
-    exports.extensions[type] = exports.extensions[type] || []
-    exts.forEach(function (ext) {
-      if (!~exports.extensions[type].indexOf(ext)) exports.extensions[type].push(ext)
-      exports.types[ext] = type
-    })
-  })
-}
diff --git a/lib/custom.json b/lib/custom.json
deleted file mode 100644
index 6137da3..0000000
--- a/lib/custom.json
+++ /dev/null
@@ -1,27 +0,0 @@
-{
-  "text/jade": [
-    "jade"
-  ],
-  "text/stylus": [
-    "stylus",
-    "styl"
-  ],
-  "text/less": [
-    "less"
-  ],
-  "text/x-sass": [
-    "sass"
-  ],
-  "text/x-scss": [
-    "scss"
-  ],
-  "text/coffeescript": [
-    "coffee"
-  ],
-  "text/x-handlebars-template": [
-    "hbs"
-  ],
-  "text/jsx": [
-    "jsx"
-  ]
-}
diff --git a/package.json b/package.json
index 358a671..829a820 100644
--- a/package.json
+++ b/package.json
@@ -1,34 +1,35 @@
 {
   "name": "mime-types",
   "description": "The ultimate javascript content-type utility.",
-  "version": "1.0.1",
-  "author": {
-    "name": "Jonathan Ong",
-    "email": "me at jongleberry.com",
-    "url": "http://jongleberry.com",
-    "twitter": "https://twitter.com/jongleberry"
-  },
+  "version": "2.0.1",
   "contributors": [
-    {
-      "name": "Jeremiah Senkpiel",
-      "email": "fishrock123 at rocketmail.com",
-      "url": "https://searchbeam.jit.su",
-      "twitter": "https://twitter.com/fishrock123"
-    }
+    "Jeremiah Senkpiel <fishrock123 at rocketmail.com> (https://searchbeam.jit.su)",
+    "Jonathan Ong <me at jongleberry.com> (http://jongleberry.com)"
   ],
-  "repository": "expressjs/mime-types",
   "license": "MIT",
-  "main": "lib",
+  "keywords": [
+    "mime",
+    "types"
+  ],
+  "repository": "jshttp/mime-types",
+  "dependencies": {
+    "mime-db": "~1.0.1"
+  },
   "devDependencies": {
-    "co": "3",
-    "cogent": "0",
-    "mocha": "1",
-    "should": "3"
+    "istanbul": "0",
+    "mocha": "1"
   },
+  "files": [
+    "HISTORY.md",
+    "LICENSE",
+    "index.js"
+  ],
   "engines": {
-    "node": ">= 0.8.0"
+    "node": ">= 0.6"
   },
   "scripts": {
-    "test": "make test"
+    "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/mime.js b/test/mime.js
index 3e6bd10..df0c998 100644
--- a/test/mime.js
+++ b/test/mime.js
@@ -59,7 +59,8 @@ eq('font/opentype', mime.lookup('file.otf'));
 //
 
 eq('UTF-8', mime.charset('text/plain'));
-eq(false, mime.charset(mime.types.js));
+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 2ecee92..be95304 100644
--- a/test/test.js
+++ b/test/test.js
@@ -8,6 +8,10 @@ var extension = mime.extension
 var charset = mime.charset
 var contentType = mime.contentType
 
+it('should pass most of node-mime\'s tests', function () {
+  require('./mime')
+})
+
 describe('.lookup()', function () {
 
   it('jade', function () {

-- 
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