Skip to content

Commit

Permalink
minor: case-insensitive input, lowercase output (fixes #224)
Browse files Browse the repository at this point in the history
  • Loading branch information
broofa committed Apr 3, 2019
1 parent 3e567a9 commit 639c913
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Mime.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ function Mime() {
*/
Mime.prototype.define = function(typeMap, force) {
for (var type in typeMap) {
var extensions = typeMap[type];
var extensions = typeMap[type].map(t => t.toLowerCase());

This comment has been minimized.

Copy link
@stevendesu

stevendesu Apr 3, 2019

👍

type = type.toLowerCase();

for (var i = 0; i < extensions.length; i++) {
var ext = extensions[i];

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ Module | Size
Both `require('mime')` and `require('mime/lite')` return instances of the MIME
class, documented below.

Note: Inputs to this API are case-insensitive. Outputs (returned values) will
be lowercase.

### new Mime(typeMap, ... more maps)

Most users of this module will not need to create Mime instances directly.
Expand Down
3 changes: 3 additions & 0 deletions src/README_js.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ Module | Size
Both `require('mime')` and `require('mime/lite')` return instances of the MIME
class, documented below.

Note: Inputs to this API are case-insensitive. Outputs (returned values) will
be lowercase.

### new Mime(typeMap, ... more maps)

Most users of this module will not need to create Mime instances directly.
Expand Down
18 changes: 18 additions & 0 deletions src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ describe('class Mime', function() {
});
});

it ('case-insensitive', function() {
var Mime = require('../Mime');
const mime = new Mime({
'TEXT/UPPER': ['UP'],
'text/lower': ['low'],
});

assert.equal(mime.getType('test.up'), 'text/upper');
assert.equal(mime.getType('test.UP'), 'text/upper');
assert.equal(mime.getType('test.low'), 'text/lower');
assert.equal(mime.getType('test.LOW'), 'text/lower');

assert.equal(mime.getExtension('text/upper'), 'up');
assert.equal(mime.getExtension('text/lower'), 'low');
assert.equal(mime.getExtension('TEXT/UPPER'), 'up');
assert.equal(mime.getExtension('TEXT/LOWER'), 'low');
});

it('getType()', function() {
// Upper/lower case
assert.equal(mime.getType('text.txt'), 'text/plain');
Expand Down

0 comments on commit 639c913

Please sign in to comment.