pax_global_header00006660000000000000000000000064124121351660014513gustar00rootroot0000000000000052 comment=7272f212651dcaca233803c58dc251b20668ca61 mime-types-2.0.2/000077500000000000000000000000001241213516600136055ustar00rootroot00000000000000mime-types-2.0.2/.gitignore000066400000000000000000000000561241213516600155760ustar00rootroot00000000000000 .DS_Store* *.log *.gz node_modules coverage mime-types-2.0.2/.travis.yml000066400000000000000000000006071241213516600157210ustar00rootroot00000000000000language: node_js node_js: - "0.6" - "0.8" - "0.10" - "0.11" matrix: allow_failures: - node_js: "0.11" fast_finish: true 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@2 && cat ./coverage/lcov.info | coveralls" mime-types-2.0.2/HISTORY.md000066400000000000000000000011541241213516600152710ustar00rootroot000000000000002.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.0.2/LICENSE000066400000000000000000000021131241213516600146070ustar00rootroot00000000000000 The MIT License (MIT) Copyright (c) 2014 Jonathan Ong me@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: 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.0.2/README.md000066400000000000000000000054041241213516600150670ustar00rootroot00000000000000# mime-types [![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] The ultimate javascript content-type utility. 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 `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 Otherwise, the API is compatible. ## Install ```sh $ npm install mime-types ``` ## 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 ```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/x-markdown' mime.lookup('file.html') // 'text/html' mime.lookup('folder/file.js') // 'application/javascript' mime.lookup('cats') // false ``` ### mime.contentType(type) 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' ``` ### 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/x-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) [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 mime-types-2.0.2/index.js000066400000000000000000000032461241213516600152570ustar00rootroot00000000000000 var db = require('mime-db') // types[extension] = type exports.types = Object.create(null) // extensions[type] = [extensions] exports.extensions = 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 } 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] } // type has to be an exact mime type exports.charset = function (type) { var mime = db[type] if (mime && mime.charset) return mime.charset // default text/* to utf-8 if (/^text\//.test(type)) return 'UTF-8' return false } // backwards compatibility 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) if (!type) return false if (!~type.indexOf('charset')) { var charset = exports.charset(type) if (charset) type += '; charset=' + charset.toLowerCase() } return type } mime-types-2.0.2/package.json000066400000000000000000000015731241213516600161010ustar00rootroot00000000000000{ "name": "mime-types", "description": "The ultimate javascript content-type utility.", "version": "2.0.2", "contributors": [ "Jeremiah Senkpiel (https://searchbeam.jit.su)", "Jonathan Ong (http://jongleberry.com)" ], "license": "MIT", "keywords": [ "mime", "types" ], "repository": "jshttp/mime-types", "dependencies": { "mime-db": "~1.1.0" }, "devDependencies": { "istanbul": "0", "mocha": "1" }, "files": [ "HISTORY.md", "LICENSE", "index.js" ], "engines": { "node": ">= 0.6" }, "scripts": { "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" } } mime-types-2.0.2/test/000077500000000000000000000000001241213516600145645ustar00rootroot00000000000000mime-types-2.0.2/test/mime.js000066400000000000000000000042761241213516600160620ustar00rootroot00000000000000/** * 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')); mime-types-2.0.2/test/test.js000066400000000000000000000050421241213516600161020ustar00rootroot00000000000000 var assert = require('assert') var mime = require('..') var lookup = mime.lookup 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 () { 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 not error on non-string types', function () { assert.doesNotThrow(function () { lookup({ noteven: "once" }) lookup(null) lookup(true) lookup(Infinity) }) }) it('should return false for unknown types', function () { assert.equal(lookup('.jalksdjflakjsdjfasdf'), false) }) }) describe('.extension()', function () { 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 unknown types', function () { assert.equal(extension('.jalksdjflakjsdjfasdf'), false) }) }) describe('.charset()', function () { it('should not error on non-string types', function () { assert.doesNotThrow(function () { charset({ noteven: "once" }) charset(null) charset(true) charset(Infinity) }) }) it('should return false for unknown types', function () { assert.equal(charset('.jalksdjflakjsdjfasdf'), false) }) }) describe('.contentType()', function () { it('html', function () { assert.equal(contentType('html'), 'text/html; charset=utf-8') }) it('text/html; charset=ascii', function () { assert.equal(contentType('text/html; charset=ascii'), 'text/html; charset=ascii') }) it('json', function () { assert.equal(contentType('json'), 'application/json; charset=utf-8') }) it('application/json', function () { assert.equal(contentType('application/json'), 'application/json; charset=utf-8') }) it('jade', function () { assert.equal(contentType('jade'), 'text/jade; charset=utf-8') }) it('should not error on non-string types', function () { assert.doesNotThrow(function () { contentType({ noteven: "once" }) contentType(null) contentType(true) contentType(Infinity) }) }) it('should return false for unknown types', function () { assert.equal(contentType('.jalksdjflakjsdjfasdf'), false) }) })