Skip to content

Commit

Permalink
Fix cc4374a to work on all types.
Browse files Browse the repository at this point in the history
Also adds some code comments
See #15
  • Loading branch information
Fishrock123 committed Sep 2, 2014
1 parent eb36464 commit 0f6628b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 8 additions & 1 deletion index.js
Expand Up @@ -25,8 +25,15 @@ module.exports = compressible

function compressible(type) {
if (!type || typeof type !== "string") return false

// Strip charset
var i = type.indexOf(';')
if (~i) type = type.slice(0, i)
var mime = db[type.toLowerCase().trim()]

// handle types that have capitals or excess space
type = type.trim().toLowerCase()

// attempt to look up from database; fallback to regex if not found
var mime = db[type]
return mime ? mime.compressible : /^text\/|\+json$|\+text$|\+xml$/.test(type)
}
7 changes: 4 additions & 3 deletions test/test.js
Expand Up @@ -6,10 +6,11 @@ var compressible = require('../')
var example_types = [
{ type: 'text/penguins', should: true },
{ type: 'something/text', should: false },
{ type: 'something/frog+text', should: true },
{ type: 'type/json', should: false },
{ type: 'something/frog+TEXT', should: true },
{ type: 'type/json;askjkl+json', should: false },
{ type: 'type/+json', should: true },
{ type: 'data/beans+xml', should: true },
{ type: 'data/beans+xml ; charset="utf-8"', should: true },
{ type: 'can/worms+xml;blaaaah', should: true },
{ type: 'data/xml', should: false },
{ type: 'asdf/nope', should: false },
{ type: 'cats', should: false }
Expand Down

0 comments on commit 0f6628b

Please sign in to comment.