Commit 45cd1548 authored by Leo Iannacone's avatar Leo Iannacone

update internal libraries

parent 0813b08b

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

1.1.1 / 2014-06-20
==================
* deps: accepts@~1.0.4
- use `mime-types`
1.1.0 / 2014-06-16
==================
......
1.0.5 / 2014-06-20
==================
* fix crash when unknown extension given
1.0.4 / 2014-06-19
==================
* use `mime-types`
1.0.3 / 2014-06-11
==================
......
var Negotiator = require('negotiator')
var mime = require('mime')
var mime = require('mime-types')
var slice = [].slice
......@@ -60,7 +60,7 @@ Accepts.prototype.types = function (types) {
var n = this.negotiator;
if (!types.length) return n.mediaTypes();
if (!this.headers.accept) return types[0];
var mimes = types.map(extToMime);
var mimes = types.map(extToMime).filter(validMime);
var accepts = n.mediaTypes(mimes);
var first = accepts[0];
if (!first) return false;
......@@ -146,3 +146,15 @@ function extToMime(type) {
if (~type.indexOf('/')) return type;
return mime.lookup(type);
}
/**
* Check if mime is valid.
*
* @param {String} type
* @return {String}
* @api private
*/
function validMime(type) {
return typeof type === 'string';
}
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
# Logs and databases #
######################
*.log
*.sql
*.sqlite
# OS generated files #
######################
.DS_Store*
# Icon?
ehthumbs.db
Thumbs.db
# Node.js #
###########
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
pids
logs
results
node_modules
npm-debug.log
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.
build:
node --harmony-generators build.js
test:
node test/mime.js
mocha --require should --reporter spec test/test.js
.PHONY: build test
# mime-types [![Build Status](https://travis-ci.org/expressjs/mime-types.svg?branch=master)](https://travis-ci.org/expressjs/mime-types) [![NPM version](https://badge.fury.io/js/mime-types.svg)](https://badge.fury.io/js/mime-types)
The ultimate javascript content-type utility.
### Install
```sh
$ npm install mime-types
```
#### Similar to [mime](https://github.com/broofa/node-mime) except:
- No `new Mime()` business, so you could do `var lookup = require('mime-types').lookup`.
- No fallbacks, so do `var type = mime.lookup('unrecognized') || 'application/octet-stream'`.
- 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.
Otherwise, the API is compatible.
### Adding Types
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).
Do __NOT__ edit `mime.json` or `node.json`.
Those are pulled using `build.js`.
You should only touch `custom.json`.
## 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'
```
### mime.types[extension] = type
A map of content-types by extension.
### mime.extensions[type] = [extensions]
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)
### 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
[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)
/**
* 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')
]
})()
{
"name": "mime-types",
"description": "ultimate mime type utility",
"version": "0.1.0",
"author": {
"name": "Jonathan Ong",
"email": "me@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"]
}
{
"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"
]
}
// 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'),
}
exports.lookup = function (string) {
if (!string || typeof string !== "string") return false
string = string.replace(/.*[\.\/\\]/, '').toLowerCase()
if (!string) return false
return exports.types[string] || false
}
exports.extension = function (type) {
if (!type || typeof type !== "string") return false
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) {
// special cases
switch (type) {
case 'application/json': return 'UTF-8'
}
// default text/* to utf-8
if (/^text\//.test(type)) return 'UTF-8'
return false
}
// backwards compatibility
exports.charsets = {
lookup: exports.charset
}
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
}
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
})
})
}
{
"text/vtt": [
"vtt"
],
"application/x-chrome-extension": [
"crx"
],
"text/x-component": [
"htc"
],
"text/cache-manifest": [
"manifest"
],
"application/octet-stream": [
"buffer"
],
"application/mp4": [
"m4p"
],
"audio/mp4": [
"m4a"
],
"video/MP2T": [
"ts"
],
"application/x-web-app-manifest+json": [
"webapp"
],
"text/x-lua": [
"lua"
],
"application/x-lua-bytecode": [
"luac"
],
"text/x-markdown": [
"markdown",
"md",
"mkd"
],
"text/plain": [
"ini"
],
"application/dash+xml": [
"mdp"
],
"font/opentype": [
"otf"
],
"application/json": [
"map"
],
"application/xml": [
"xsd"
]
}
{
"name": "mime-types",
"description": "ultimate mime type utility",
"version": "1.0.0",
"author": {
"name": "Jonathan Ong",
"email": "me@jongleberry.com",
"url": "http://jongleberry.com"
},
"contributors": [
{
"name": "Jeremiah Senkpiel",
"email": "fishrock123@rocketmail.com",
"url": "https://searchbeam.jit.su"
}
],
"repository": {
"type": "git",
"url": "git://github.com/expressjs/mime-types"
},
"license": "MIT",
"main": "lib",
"devDependencies": {
"co": "3",
"cogent": "0",
"mocha": "1",
"should": "3"
},
"scripts": {
"test": "make test"
},
"readme": "# mime-types [![Build Status](https://travis-ci.org/expressjs/mime-types.svg?branch=master)](https://travis-ci.org/expressjs/mime-types) [![NPM version](https://badge.fury.io/js/mime-types.svg)](https://badge.fury.io/js/mime-types)\n\nThe ultimate javascript content-type utility.\n\n### Install\n\n```sh\n$ npm install mime-types\n```\n\n#### Similar to [mime](https://github.com/broofa/node-mime) except:\n\n- No `new Mime()` business, so you could do `var lookup = require('mime-types').lookup`.\n- No fallbacks, so do `var type = mime.lookup('unrecognized') || 'application/octet-stream'`.\n- Additional mime types are added such as jade and stylus. Feel free to add more!\n- Browser support via Browserify and Component by converting lists to JSON files.\n\nOtherwise, the API is compatible.\n\n### Adding Types\n\nIf you'd like to add additional types,\nsimply create a PR adding the type to `custom.json` and\na reference link to the [sources](SOURCES.md).\n\nDo __NOT__ edit `mime.json` or `node.json`.\nThose are pulled using `build.js`.\nYou should only touch `custom.json`.\n\n## API\n\n```js\nvar mime = require('mime-types')\n```\n\nAll functions return `false` if input is invalid or not found.\n\n### mime.lookup(path)\n\nLookup the content-type associated with a file.\n\n```js\nmime.lookup('json') // 'application/json'\nmime.lookup('.md') // 'text/x-markdown'\nmime.lookup('file.html') // 'text/html'\nmime.lookup('folder/file.js') // 'application/javascript'\n\nmime.lookup('cats') // false\n```\n\n### mime.contentType(type)\n\nCreate a full content-type header given a content-type or extension.\n\n```js\nmime.contentType('markdown') // 'text/x-markdown; charset=utf-8'\nmime.contentType('file.json') // 'application/json; charset=utf-8'\n```\n\n### mime.extension(type)\n\nGet the default extension for a content-type.\n\n```js\nmime.extension('application/octet-stream') // 'bin'\n```\n\n### mime.charset(type)\n\nLookup the implied default charset of a content-type.\n\n```js\nmime.charset('text/x-markdown') // 'UTF-8'\n```\n\n### mime.types[extension] = type\n\nA map of content-types by extension.\n\n### mime.extensions[type] = [extensions]\n\nA map of extensions by content-type.\n\n### mime.define(types)\n\nGlobally add definitions.\n`types` must be an object of the form:\n\n```js\n{\n \"<content-type>\": [extensions...],\n \"<content-type>\": [extensions...]\n}\n```\n\nSee the `.json` files in `lib/` for examples.\n\n## License\n\n[MIT](LICENSE)\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/expressjs/mime-types/issues"
},
"_id": "mime-types@1.0.0",
"_from": "mime-types@~1.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(false, mime.charset(mime.types.js));
eq('UTF-8', mime.charset('application/json'))
eq('UTF-8', mime.charsets.lookup('text/something'));
// eq('fallback', mime.charset('application/octet-stream', 'fallback'));
var assert = require('assert')
var mime = require('..')
var lookup = mime.lookup
var extension = mime.extension
var charset = mime.charset
var contentType = mime.contentType
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)
})
})
Copyright (c) 2010 Benjamin Thomas, Robert Kieffer
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
Comprehensive MIME type mapping API. Includes all 600+ types and 800+ extensions defined by the Apache project, plus additional types submitted by the node.js community.
## Install
Install with [npm](http://github.com/isaacs/npm):
npm install mime
## API - Queries
### mime.lookup(path)
Get the mime type associated with a file, if no mime type is found `application/octet-stream` is returned. Performs a case-insensitive lookup using the extension in `path` (the substring after the last '/' or '.'). E.g.
var mime = require('mime');
mime.lookup('/path/to/file.txt'); // => 'text/plain'
mime.lookup('file.txt'); // => 'text/plain'
mime.lookup('.TXT'); // => 'text/plain'
mime.lookup('htm'); // => 'text/html'
### mime.default_type
Sets the mime type returned when `mime.lookup` fails to find the extension searched for. (Default is `application/octet-stream`.)
### mime.extension(type)
Get the default extension for `type`
mime.extension('text/html'); // => 'html'
mime.extension('application/octet-stream'); // => 'bin'
### mime.charsets.lookup()
Map mime-type to charset
mime.charsets.lookup('text/plain'); // => 'UTF-8'
(The logic for charset lookups is pretty rudimentary. Feel free to suggest improvements.)
## API - Defining Custom Types
The following APIs allow you to add your own type mappings within your project. If you feel a type should be included as part of node-mime, see [requesting new types](https://github.com/broofa/node-mime/wiki/Requesting-New-Types).
### mime.define()
Add custom mime/extension mappings
mime.define({
'text/x-some-format': ['x-sf', 'x-sft', 'x-sfml'],
'application/x-my-type': ['x-mt', 'x-mtt'],
// etc ...
});
mime.lookup('x-sft'); // => 'text/x-some-format'
The first entry in the extensions array is returned by `mime.extension()`. E.g.
mime.extension('text/x-some-format'); // => 'x-sf'
### mime.load(filepath)
Load mappings from an Apache ".types" format file
mime.load('./my_project.types');
The .types file format is simple - See the `types` dir for examples.
var path = require('path');
var fs = require('fs');
function Mime() {
// Map of extension -> mime type
this.types = Object.create(null);
// Map of mime type -> extension
this.extensions = Object.create(null);
}
/**
* Define mimetype -> extension mappings. Each key is a mime-type that maps
* to an array of extensions associated with the type. The first extension is
* used as the default extension for the type.
*
* e.g. mime.define({'audio/ogg', ['oga', 'ogg', 'spx']});
*
* @param map (Object) type definitions
*/
Mime.prototype.define = function (map) {
for (var type in map) {
var exts = map[type];
for (var i = 0; i < exts.length; i++) {
if (process.env.DEBUG_MIME && this.types[exts]) {
console.warn(this._loading.replace(/.*\//, ''), 'changes "' + exts[i] + '" extension type from ' +
this.types[exts] + ' to ' + type);
}
this.types[exts[i]] = type;
}
// Default extension is the first one we encounter
if (!this.extensions[type]) {
this.extensions[type] = exts[0];
}
}
};
/**
* Load an Apache2-style ".types" file
*
* This may be called multiple times (it's expected). Where files declare
* overlapping types/extensions, the last file wins.
*
* @param file (String) path of file to load.
*/
Mime.prototype.load = function(file) {
this._loading = file;
// Read file and split into lines
var map = {},
content = fs.readFileSync(file, 'ascii'),
lines = content.split(/[\r\n]+/);
lines.forEach(function(line) {
// Clean up whitespace/comments, and split into fields
var fields = line.replace(/\s*#.*|^\s*|\s*$/g, '').split(/\s+/);
map[fields.shift()] = fields;
});
this.define(map);
this._loading = null;
};
/**
* Lookup a mime type based on extension
*/
Mime.prototype.lookup = function(path, fallback) {
var ext = path.replace(/.*[\.\/\\]/, '').toLowerCase();
return this.types[ext] || fallback || this.default_type;
};
/**
* Return file extension associated with a mime type
*/
Mime.prototype.extension = function(mimeType) {
var type = mimeType.match(/^\s*([^;\s]*)(?:;|\s|$)/)[1].toLowerCase();
return this.extensions[type];
};
// Default instance
var mime = new Mime();
// Load local copy of
// http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
mime.load(path.join(__dirname, 'types/mime.types'));
// Load additional types from node.js community
mime.load(path.join(__dirname, 'types/node.types'));
// Default type
mime.default_type = mime.lookup('bin');
//
// Additional API specific to the default instance
//
mime.Mime = Mime;
/**
* Lookup a charset based on mime type.
*/
mime.charsets = {
lookup: function(mimeType, fallback) {
// Assume text types are utf8
return (/^text\//).test(mimeType) ? 'UTF-8' : fallback;
}
};
module.exports = mime;
{
"author": {
"name": "Robert Kieffer",
"email": "robert@broofa.com",
"url": "http://github.com/broofa"
},
"contributors": [
{
"name": "Benjamin Thomas",
"email": "benjamin@benjaminthomas.org",
"url": "http://github.com/bentomas"
}
],
"dependencies": {},
"description": "A comprehensive library for mime-type mapping",
"devDependencies": {},
"keywords": [
"util",
"mime"
],
"main": "mime.js",
"name": "mime",
"repository": {
"url": "https://github.com/broofa/node-mime",
"type": "git"
},
"version": "1.2.11",
"readme": "# mime\n\nComprehensive MIME type mapping API. Includes all 600+ types and 800+ extensions defined by the Apache project, plus additional types submitted by the node.js community.\n\n## Install\n\nInstall with [npm](http://github.com/isaacs/npm):\n\n npm install mime\n\n## API - Queries\n\n### mime.lookup(path)\nGet the mime type associated with a file, if no mime type is found `application/octet-stream` is returned. Performs a case-insensitive lookup using the extension in `path` (the substring after the last '/' or '.'). E.g.\n\n var mime = require('mime');\n\n mime.lookup('/path/to/file.txt'); // => 'text/plain'\n mime.lookup('file.txt'); // => 'text/plain'\n mime.lookup('.TXT'); // => 'text/plain'\n mime.lookup('htm'); // => 'text/html'\n\n### mime.default_type\nSets the mime type returned when `mime.lookup` fails to find the extension searched for. (Default is `application/octet-stream`.)\n\n### mime.extension(type)\nGet the default extension for `type`\n\n mime.extension('text/html'); // => 'html'\n mime.extension('application/octet-stream'); // => 'bin'\n\n### mime.charsets.lookup()\n\nMap mime-type to charset\n\n mime.charsets.lookup('text/plain'); // => 'UTF-8'\n\n(The logic for charset lookups is pretty rudimentary. Feel free to suggest improvements.)\n\n## API - Defining Custom Types\n\nThe following APIs allow you to add your own type mappings within your project. If you feel a type should be included as part of node-mime, see [requesting new types](https://github.com/broofa/node-mime/wiki/Requesting-New-Types).\n\n### mime.define()\n\nAdd custom mime/extension mappings\n\n mime.define({\n 'text/x-some-format': ['x-sf', 'x-sft', 'x-sfml'],\n 'application/x-my-type': ['x-mt', 'x-mtt'],\n // etc ...\n });\n\n mime.lookup('x-sft'); // => 'text/x-some-format'\n\nThe first entry in the extensions array is returned by `mime.extension()`. E.g.\n\n mime.extension('text/x-some-format'); // => 'x-sf'\n\n### mime.load(filepath)\n\nLoad mappings from an Apache \".types\" format file\n\n mime.load('./my_project.types');\n\nThe .types file format is simple - See the `types` dir for examples.\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/broofa/node-mime/issues"
},
"_id": "mime@1.2.11",
"_from": "mime@~1.2.11"
}
/**
* Usage: node test.js
*/
var mime = require('./mime');
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(undefined, 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.charsets.lookup('text/plain'));
eq(undefined, mime.charsets.lookup(mime.types.js));
eq('fallback', mime.charsets.lookup('application/octet-stream', 'fallback'));
//
// Test for overlaps between mime.types and node.types
//
var apacheTypes = new mime.Mime(), nodeTypes = new mime.Mime();
apacheTypes.load(path.join(__dirname, 'types/mime.types'));
nodeTypes.load(path.join(__dirname, 'types/node.types'));
var keys = [].concat(Object.keys(apacheTypes.types))
.concat(Object.keys(nodeTypes.types));
keys.sort();
for (var i = 1; i < keys.length; i++) {
if (keys[i] == keys[i-1]) {
console.warn('Warning: ' +
'node.types defines ' + keys[i] + '->' + nodeTypes.types[keys[i]] +
', mime.types defines ' + keys[i] + '->' + apacheTypes.types[keys[i]]);
}
}
console.log('\nOK');
# What: WebVTT
# Why: To allow formats intended for marking up external text track resources.
# http://dev.w3.org/html5/webvtt/
# Added by: niftylettuce
text/vtt vtt
# What: Google Chrome Extension
# Why: To allow apps to (work) be served with the right content type header.
# http://codereview.chromium.org/2830017
# Added by: niftylettuce
application/x-chrome-extension crx
# What: HTC support
# Why: To properly render .htc files such as CSS3PIE
# Added by: niftylettuce
text/x-component htc
# What: HTML5 application cache manifes ('.manifest' extension)
# Why: De-facto standard. Required by Mozilla browser when serving HTML5 apps
# per https://developer.mozilla.org/en/offline_resources_in_firefox
# Added by: louisremi
text/cache-manifest manifest
# What: node binary buffer format
# Why: semi-standard extension w/in the node community
# Added by: tootallnate
application/octet-stream buffer
# What: The "protected" MP-4 formats used by iTunes.
# Why: Required for streaming music to browsers (?)
# Added by: broofa
application/mp4 m4p
audio/mp4 m4a
# What: Video format, Part of RFC1890
# Why: See https://github.com/bentomas/node-mime/pull/6
# Added by: mjrusso
video/MP2T ts
# What: EventSource mime type
# Why: mime type of Server-Sent Events stream
# http://www.w3.org/TR/eventsource/#text-event-stream
# Added by: francois2metz
text/event-stream event-stream
# What: Mozilla App manifest mime type
# Why: https://developer.mozilla.org/en/Apps/Manifest#Serving_manifests
# Added by: ednapiranha
application/x-web-app-manifest+json webapp
# What: Lua file types
# Why: Googling around shows de-facto consensus on these
# Added by: creationix (Issue #45)
text/x-lua lua
application/x-lua-bytecode luac
# What: Markdown files, as per http://daringfireball.net/projects/markdown/syntax
# Why: http://stackoverflow.com/questions/10701983/what-is-the-mime-type-for-markdown
# Added by: avoidwork
text/x-markdown markdown md mkd
# What: ini files
# Why: because they're just text files
# Added by: Matthew Kastor
text/plain ini
# What: DASH Adaptive Streaming manifest
# Why: https://developer.mozilla.org/en-US/docs/DASH_Adaptive_Streaming_for_HTML_5_Video
# Added by: eelcocramer
application/dash+xml mdp
# What: OpenType font files - http://www.microsoft.com/typography/otspec/
# Why: Browsers usually ignore the font MIME types and sniff the content,
# but Chrome, shows a warning if OpenType fonts aren't served with
# the `font/opentype` MIME type: http://i.imgur.com/8c5RN8M.png.
# Added by: alrra
font/opentype otf
{
"name": "accepts",
"description": "Higher-level content negotiation",
"version": "1.0.3",
"version": "1.0.5",
"author": {
"name": "Jonathan Ong",
"email": "me@jongleberry.com",
......@@ -13,7 +13,7 @@
"url": "git://github.com/expressjs/accepts"
},
"dependencies": {
"mime": "~1.2.11",
"mime-types": "~1.0.0",
"negotiator": "0.4.6"
},
"devDependencies": {
......@@ -34,6 +34,6 @@
"bugs": {
"url": "https://github.com/expressjs/accepts/issues"
},
"_id": "accepts@1.0.3",
"_from": "accepts@1.0.3"
"_id": "accepts@1.0.5",
"_from": "accepts@~1.0.5"
}
{
"name": "errorhandler",
"description": "connect's default error handler page",
"version": "1.1.0",
"version": "1.1.1",
"author": {
"name": "Jonathan Ong",
"email": "me@jongleberry.com",
......@@ -13,7 +13,7 @@
"url": "git://github.com/expressjs/errorhandler"
},
"dependencies": {
"accepts": "1.0.3",
"accepts": "~1.0.4",
"escape-html": "1.0.1"
},
"devDependencies": {
......@@ -36,10 +36,10 @@
"bugs": {
"url": "https://github.com/expressjs/errorhandler/issues"
},
"_id": "errorhandler@1.1.0",
"_id": "errorhandler@1.1.1",
"dist": {
"shasum": "7bb1df71337b0c350f065cc47733e4aa1014932c"
"shasum": "1bb0d6fa98b4aff72bf60371a0198925b49216fa"
},
"_from": "errorhandler @*",
"_resolved": "https://registry.npmjs.org/errorhandler/-/errorhandler-1.1.0.tgz"
"_resolved": "https://registry.npmjs.org/errorhandler/-/errorhandler-1.1.1.tgz"
}
4.4.4 / 2014-06-20
==================
* fix `res.attachment` Unicode filenames in Safari
* fix "trim prefix" debug message in `express:router`
* deps: accepts@~1.0.5
* deps: buffer-crc32@0.2.3
4.4.3 / 2014-06-11
==================
......
......@@ -226,9 +226,11 @@ proto.handle = function(req, res, done) {
// Trim off the part of the url that matches the route
// middleware (.use stuff) needs to have the path stripped
debug('trim prefix (%s) from url %s', removed, req.url);
removed = layerPath;
req.url = protohost + req.url.substr(protohost.length + removed.length);
if (removed.length) {
debug('trim prefix (%s) from url %s', layerPath, req.url);
req.url = protohost + req.url.substr(protohost.length + removed.length);
}
// Ensure leading slash
if (!fqdn && req.url[0] !== '/') {
......
......@@ -164,7 +164,7 @@ exports.contentDisposition = function(filename){
filename = basename(filename);
// if filename contains non-ascii characters, add a utf-8 version ala RFC 5987
ret = /[^\040-\176]/.test(filename)
? 'attachment; filename=' + encodeURI(filename) + '; filename*=UTF-8\'\'' + encodeURI(filename)
? 'attachment; filename="' + encodeURI(filename) + '"; filename*=UTF-8\'\'' + encodeURI(filename)
: 'attachment; filename="' + filename + '"';
}
......
1.0.5 / 2014-06-20
==================
* fix crash when unknown extension given
1.0.4 / 2014-06-19
==================
* use `mime-types`
1.0.3 / 2014-06-11
==================
......
var Negotiator = require('negotiator')
var mime = require('mime')
var mime = require('mime-types')
var slice = [].slice
......@@ -60,7 +60,7 @@ Accepts.prototype.types = function (types) {
var n = this.negotiator;
if (!types.length) return n.mediaTypes();
if (!this.headers.accept) return types[0];
var mimes = types.map(extToMime);
var mimes = types.map(extToMime).filter(validMime);
var accepts = n.mediaTypes(mimes);
var first = accepts[0];
if (!first) return false;
......@@ -146,3 +146,15 @@ function extToMime(type) {
if (~type.indexOf('/')) return type;
return mime.lookup(type);
}
/**
* Check if mime is valid.
*
* @param {String} type
* @return {String}
* @api private
*/
function validMime(type) {
return typeof type === 'string';
}
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
# Logs and databases #
######################
*.log
*.sql
*.sqlite
# OS generated files #
######################
.DS_Store*
# Icon?
ehthumbs.db
Thumbs.db
# Node.js #
###########
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
pids
logs
results
node_modules
npm-debug.log
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.
build:
node --harmony-generators build.js
test:
node test/mime.js
mocha --require should --reporter spec test/test.js
.PHONY: build test
# mime-types [![Build Status](https://travis-ci.org/expressjs/mime-types.svg?branch=master)](https://travis-ci.org/expressjs/mime-types) [![NPM version](https://badge.fury.io/js/mime-types.svg)](https://badge.fury.io/js/mime-types)
The ultimate javascript content-type utility.
### Install
```sh
$ npm install mime-types
```
#### Similar to [mime](https://github.com/broofa/node-mime) except:
- No `new Mime()` business, so you could do `var lookup = require('mime-types').lookup`.
- No fallbacks, so do `var type = mime.lookup('unrecognized') || 'application/octet-stream'`.
- 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.
Otherwise, the API is compatible.
### Adding Types
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).
Do __NOT__ edit `mime.json` or `node.json`.
Those are pulled using `build.js`.
You should only touch `custom.json`.
## 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'
```
### mime.types[extension] = type
A map of content-types by extension.
### mime.extensions[type] = [extensions]
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)
### 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
[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)
/**
* 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')
]
})()
{
"name": "mime-types",
"description": "ultimate mime type utility",
"version": "0.1.0",
"author": {
"name": "Jonathan Ong",
"email": "me@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"]
}
{
"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"
]
}
// 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'),
}
exports.lookup = function (string) {
if (!string || typeof string !== "string") return false
string = string.replace(/.*[\.\/\\]/, '').toLowerCase()
if (!string) return false
return exports.types[string] || false
}
exports.extension = function (type) {
if (!type || typeof type !== "string") return false
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) {
// special cases
switch (type) {
case 'application/json': return 'UTF-8'
}
// default text/* to utf-8
if (/^text\//.test(type)) return 'UTF-8'
return false
}
// backwards compatibility
exports.charsets = {
lookup: exports.charset
}
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
}
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
})
})
}
{
"text/vtt": [
"vtt"
],
"application/x-chrome-extension": [
"crx"
],
"text/x-component": [
"htc"
],
"text/cache-manifest": [
"manifest"
],
"application/octet-stream": [
"buffer"
],
"application/mp4": [
"m4p"
],
"audio/mp4": [
"m4a"
],
"video/MP2T": [
"ts"
],
"application/x-web-app-manifest+json": [
"webapp"
],
"text/x-lua": [
"lua"
],
"application/x-lua-bytecode": [
"luac"
],
"text/x-markdown": [
"markdown",
"md",
"mkd"
],
"text/plain": [
"ini"
],
"application/dash+xml": [
"mdp"
],
"font/opentype": [
"otf"
],
"application/json": [
"map"
],
"application/xml": [
"xsd"
]
}
{
"name": "mime-types",
"description": "ultimate mime type utility",
"version": "1.0.0",
"author": {
"name": "Jonathan Ong",
"email": "me@jongleberry.com",
"url": "http://jongleberry.com"
},
"contributors": [
{
"name": "Jeremiah Senkpiel",
"email": "fishrock123@rocketmail.com",
"url": "https://searchbeam.jit.su"
}
],
"repository": {
"type": "git",
"url": "git://github.com/expressjs/mime-types"
},
"license": "MIT",
"main": "lib",
"devDependencies": {
"co": "3",
"cogent": "0",
"mocha": "1",
"should": "3"
},
"scripts": {
"test": "make test"
},
"readme": "# mime-types [![Build Status](https://travis-ci.org/expressjs/mime-types.svg?branch=master)](https://travis-ci.org/expressjs/mime-types) [![NPM version](https://badge.fury.io/js/mime-types.svg)](https://badge.fury.io/js/mime-types)\n\nThe ultimate javascript content-type utility.\n\n### Install\n\n```sh\n$ npm install mime-types\n```\n\n#### Similar to [mime](https://github.com/broofa/node-mime) except:\n\n- No `new Mime()` business, so you could do `var lookup = require('mime-types').lookup`.\n- No fallbacks, so do `var type = mime.lookup('unrecognized') || 'application/octet-stream'`.\n- Additional mime types are added such as jade and stylus. Feel free to add more!\n- Browser support via Browserify and Component by converting lists to JSON files.\n\nOtherwise, the API is compatible.\n\n### Adding Types\n\nIf you'd like to add additional types,\nsimply create a PR adding the type to `custom.json` and\na reference link to the [sources](SOURCES.md).\n\nDo __NOT__ edit `mime.json` or `node.json`.\nThose are pulled using `build.js`.\nYou should only touch `custom.json`.\n\n## API\n\n```js\nvar mime = require('mime-types')\n```\n\nAll functions return `false` if input is invalid or not found.\n\n### mime.lookup(path)\n\nLookup the content-type associated with a file.\n\n```js\nmime.lookup('json') // 'application/json'\nmime.lookup('.md') // 'text/x-markdown'\nmime.lookup('file.html') // 'text/html'\nmime.lookup('folder/file.js') // 'application/javascript'\n\nmime.lookup('cats') // false\n```\n\n### mime.contentType(type)\n\nCreate a full content-type header given a content-type or extension.\n\n```js\nmime.contentType('markdown') // 'text/x-markdown; charset=utf-8'\nmime.contentType('file.json') // 'application/json; charset=utf-8'\n```\n\n### mime.extension(type)\n\nGet the default extension for a content-type.\n\n```js\nmime.extension('application/octet-stream') // 'bin'\n```\n\n### mime.charset(type)\n\nLookup the implied default charset of a content-type.\n\n```js\nmime.charset('text/x-markdown') // 'UTF-8'\n```\n\n### mime.types[extension] = type\n\nA map of content-types by extension.\n\n### mime.extensions[type] = [extensions]\n\nA map of extensions by content-type.\n\n### mime.define(types)\n\nGlobally add definitions.\n`types` must be an object of the form:\n\n```js\n{\n \"<content-type>\": [extensions...],\n \"<content-type>\": [extensions...]\n}\n```\n\nSee the `.json` files in `lib/` for examples.\n\n## License\n\n[MIT](LICENSE)\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/expressjs/mime-types/issues"
},
"_id": "mime-types@1.0.0",
"_from": "mime-types@~1.0.0"
}
......@@ -55,6 +55,9 @@ var CRC_TABLE = [
0x2d02ef8d
];
if (typeof Int32Array !== 'undefined')
CRC_TABLE = new Int32Array(CRC_TABLE);
function bufferizeInt(num) {
var tmp = Buffer(4);
tmp.writeInt32BE(num, 0);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment