-
-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use mime-db as canonical source of mime types.
- Loading branch information
Showing
8 changed files
with
89 additions
and
1,761 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
npm-debug.log | ||
types.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var db = require('mime-db'); | ||
|
||
var mapByType = {}; | ||
Object.keys(db).forEach(function(key) { | ||
var extensions = db[key].extensions; | ||
if (extensions) { | ||
mapByType[key] = extensions; | ||
} | ||
}); | ||
|
||
console.log(JSON.stringify(mapByType)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Usage: node test.js | ||
*/ | ||
|
||
var mime = require('../mime'); | ||
var assert = require('assert'); | ||
var path = require('path'); | ||
|
||
// | ||
// Test mime lookups | ||
// | ||
|
||
assert.equal('text/plain', mime.lookup('text.txt')); // normal file | ||
assert.equal('text/plain', mime.lookup('TEXT.TXT')); // uppercase | ||
assert.equal('text/plain', mime.lookup('dir/text.txt')); // dir + file | ||
assert.equal('text/plain', mime.lookup('.text.txt')); // hidden file | ||
assert.equal('text/plain', mime.lookup('.txt')); // nameless | ||
assert.equal('text/plain', mime.lookup('txt')); // extension-only | ||
assert.equal('text/plain', mime.lookup('/txt')); // extension-less () | ||
assert.equal('text/plain', mime.lookup('\\txt')); // Windows, extension-less | ||
assert.equal('application/octet-stream', mime.lookup('text.nope')); // unrecognized | ||
assert.equal('fallback', mime.lookup('text.fallback', 'fallback')); // alternate default | ||
|
||
// | ||
// Test extensions | ||
// | ||
|
||
assert.equal('txt', mime.extension(mime.types.text)); | ||
assert.equal('html', mime.extension(mime.types.htm)); | ||
assert.equal('bin', mime.extension('application/octet-stream')); | ||
assert.equal('bin', mime.extension('application/octet-stream ')); | ||
assert.equal('html', mime.extension(' text/html; charset=UTF-8')); | ||
assert.equal('html', mime.extension('text/html; charset=UTF-8 ')); | ||
assert.equal('html', mime.extension('text/html; charset=UTF-8')); | ||
assert.equal('html', mime.extension('text/html ; charset=UTF-8')); | ||
assert.equal('html', mime.extension('text/html;charset=UTF-8')); | ||
assert.equal('html', mime.extension('text/Html;charset=UTF-8')); | ||
assert.equal(undefined, mime.extension('unrecognized')); | ||
|
||
// | ||
// Test node.types lookups | ||
// | ||
|
||
assert.equal('application/font-woff', mime.lookup('file.woff')); | ||
assert.equal('application/octet-stream', mime.lookup('file.buffer')); | ||
assert.equal('audio/mp4', mime.lookup('file.m4a')); | ||
assert.equal('font/opentype', mime.lookup('file.otf')); | ||
|
||
// | ||
// Test charsets | ||
// | ||
|
||
assert.equal('UTF-8', mime.charsets.lookup('text/plain')); | ||
assert.equal(undefined, mime.charsets.lookup(mime.types.js)); | ||
assert.equal('fallback', mime.charsets.lookup('application/octet-stream', 'fallback')); | ||
|
||
console.log('\nAll tests passed'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.