[Pkg-javascript-commits] [node-compressible] 01/02: Imported Upstream version 1.1.0

Leo Iannacone l3on-guest at moszumanska.debian.org
Sat Jun 14 13:49:29 UTC 2014


This is an automated email from the git hooks/post-receive script.

l3on-guest pushed a commit to branch master
in repository node-compressible.

commit 241421ee2ac5ec5ad41127bc0fe8723b7d3cc01b
Author: Leo Iannacone <l3on at ubuntu.com>
Date:   Sat Jun 14 15:43:20 2014 +0200

    Imported Upstream version 1.1.0
---
 .npmignore          |   9 +
 .travis.yml         |   9 +
 README.md           |  58 +++++++
 index.js            |  30 ++++
 package.json        |  38 +++++
 specifications.json | 473 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/test.js        |  90 ++++++++++
 7 files changed, 707 insertions(+)

diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..f8b959f
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1,9 @@
+test
+.travis.yml
+
+npm-debug.log
+
+# Sublime Text #
+##############
+*.sublime-project
+*.sublime-workspace
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..65cf4bc
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,9 @@
+language: node_js
+node_js:
+  - "0.8"
+  - "0.10"
+  - "0.11"
+matrix:
+  allow_failures:
+    - node_js: "0.11"
+  fast_finish: true
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7df7ab0
--- /dev/null
+++ b/README.md
@@ -0,0 +1,58 @@
+# compressible
+
+[![Build Status](https://travis-ci.org/expressjs/compressible.svg?branch=master)](https://travis-ci.org/expressjs/compressible)
+[![NPM Version](https://badge.fury.io/js/compressible.svg)](https://badge.fury.io/js/compressible)
+
+Compressible `Content-Type` / `mime` checking.
+
+```sh
+$ npm install compressible
+```
+
+## API
+
+### compressible(type)
+
+```js
+var compressible = require('compressible')
+compressible('text/html') // => true
+compressible('image/png') // => false
+```
+
+### compressible.get(type)
+
+Returns the specifications object associated with the given `Content-Type`.
+Generates an object using the regex if none is found.
+
+### compressible.specs
+
+Exports `specifications.json`.
+
+### compressible.regex
+
+The regular expression that checks the `Content-Type`.
+However, you should use `compressible(type)` instead of this regular expression due to additional non-regex checks.
+
+## License
+
+The MIT License (MIT)
+
+Copyright (c) 2013 Jonathan Ong me at 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.
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..cb5f18f
--- /dev/null
+++ b/index.js
@@ -0,0 +1,30 @@
+module.exports = compressible
+
+compressible.specs =
+compressible.specifications = require('./specifications.json')
+
+compressible.regex =
+compressible.regexp = /json|text|xml/
+
+compressible.get = get
+
+function compressible(type) {
+  if (!type || typeof type !== "string") return false
+  var i = type.indexOf(';')
+    , spec = compressible.specs[~i ? type.slice(0, i) : type]
+  return spec ? spec.compressible : compressible.regex.test(type)
+}
+
+function get(type) {
+  if (!type || typeof type !== "string") return {
+    compressible: false,
+    notes: "Invalid type."
+  }
+  var i = type.indexOf(';')
+    , spec = compressible.specs[~i ? type.slice(0, i) : type]
+  return spec ? spec : {
+    compressible: compressible.regex.test(type),
+    sources: ["compressible.regex"],
+    notes: "Automatically generated via regex."
+  }
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..67ef52e
--- /dev/null
+++ b/package.json
@@ -0,0 +1,38 @@
+{
+  "name": "compressible",
+  "description": "Compressible Content-Type / mime checking",
+  "version": "1.1.0",
+  "author": {
+    "name": "Jonathan Ong",
+    "email": "me at jongleberry.com",
+    "url": "http://jongleberry.com",
+    "twitter": "https://twitter.com/jongleberry"
+  },
+  "contributors": [{
+    "name": "Jeremiah Senkpiel",
+    "email": "fishrock123 at rocketmail.com",
+    "url": "https://searchbeam.jit.su",
+    "twitter": "https://twitter.com/fishrock123"
+  }],
+  "license": "MIT",
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/expressjs/compressible.git"
+  },
+  "bugs": {
+    "mail": "me at jongleberry.com",
+    "url": "https://github.com/expressjs/compressible/issues"
+  },
+  "keywords": [
+    "compress",
+    "gzip",
+    "mime",
+    "content-type"
+  ],
+  "devDependencies": {
+    "mocha": "~1.20.1"
+  },
+  "scripts": {
+    "test": "mocha --reporter spec test/"
+  }
+}
diff --git a/specifications.json b/specifications.json
new file mode 100644
index 0000000..71ef402
--- /dev/null
+++ b/specifications.json
@@ -0,0 +1,473 @@
+{
+  "application/atom+xml": {
+    "compressible": true,
+    "sources": [
+      "http://en.wikipedia.org/wiki/Atom_(standard)"
+    ]
+  },
+  "application/dart": {
+    "compressible": true
+  },
+  "application/EDI-X12": {
+    "compressible": false
+  },
+  "application/EDIFACT": {
+    "compressible": false
+  },
+  "application/ecmascript": {
+    "compressible": true
+  },
+  "application/font-woff": {
+    "compressible": false
+  },
+  "application/gzip": {
+    "compressible": false
+  },
+  "application/java-archive": {
+    "compressible": false
+  },
+  "application/java-serialized-object": {
+    "compressible": false
+  },
+  "application/java-vm": {
+    "compressible": false
+  },
+  "application/javascript": {
+    "compressible": true
+  },
+  "application/json": {
+    "compressible": true
+  },
+  "application/msword": {
+    "compressible": false
+  },
+  "application/octet-stream": {
+    "compressible": false,
+    "sources": [
+      "https://github.com/broofa/node-mime/blob/master/types/mime.types#L154"
+    ]
+  },
+  "application/ogg": {
+    "compressible": false
+  },
+  "application/pdf": {
+    "compressible": false
+  },
+  "application/pgp-encrypted": {
+    "compressible": false
+  },
+  "application/postscript": {
+    "compressible": true
+  },
+  "application/rdf+xml": {
+    "compressible": true,
+    "sources": [
+      "http://en.wikipedia.org/wiki/RDF/XML"
+    ]
+  },
+  "application/rss+xml": {
+    "compressible": true
+  },
+  "application/rtf": {
+    "compressible": true
+  },
+  "application/soap+xml": {
+    "compressible": true,
+    "sources": [
+      "http://en.wikipedia.org/wiki/SOAP"
+    ]
+  },
+  "application/tar": {
+    "compressible": true
+  },
+  "application/vnd.android.package-archive": {
+    "compressible": false
+  },
+  "application/vnd.dart": {
+    "compressible": true
+  },
+  "application/vnd.google-earth.kml+xml": {
+    "compressible": true,
+    "sources": [
+      "https://developers.google.com/kml/documentation/kml_tut"
+    ]
+  },
+  "application/vnd.google-earth.kmz": {
+    "compressible": false
+  },
+  "application/vnd.mozilla.xul+xml": {
+    "compressible": true,
+    "sources": [
+      "http://en.wikipedia.org/wiki/XUL"
+    ]
+  },
+  "application/vnd.ms-excel": {
+    "compressible": false
+  },
+  "application/vnd.ms-fontobject": {
+    "compressible": true,
+    "sources": [
+      "http://www.phpied.com/gzip-your-font-face-files/"
+    ]
+  },
+  "application/vnd.ms-opentype": {
+    "compressible": true,
+    "sources": [
+      "http://www.phpied.com/gzip-your-font-face-files/"
+    ]
+  },
+  "application/vnd.ms-powerpoint": {
+    "compressible": false
+  },
+  "application/vnd.ms-xpsdocument": {
+    "compressible": false
+  },
+  "application/vnd.oasis.opendocument.graphics": {
+    "compressible": false
+  },
+  "application/vnd.oasis.opendocument.presentation": {
+    "compressible": false
+  },
+  "application/vnd.oasis.opendocument.spreadsheet": {
+    "compressible": false
+  },
+  "application/vnd.oasis.opendocument.text": {
+    "compressible": false,
+    "sources": [
+      "http://en.wikipedia.org/wiki/OpenDocument_technical_specification#File_types"
+    ]
+  },
+  "application/vnd.openxmlformats-officedocument.presentationml.presentation": {
+    "compressible": false
+  },
+  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
+    "compressible": false
+  },
+  "application/vnd.openxmlformats-officedocument.wordprocessingml.document": {
+    "compressible": false
+  },
+  "application/x-7z-compressed": {
+    "compressible": false
+  },
+  "application/x-bzip": {
+    "compressible": false
+  },
+  "application/x-bzip2": {
+    "compressible": false
+  },
+  "application/x-deb": {
+    "compressible": false
+  },
+  "application/x-dvi": {
+    "compressible": false
+  },
+  "application/x-font-otf": {
+    "compressible": true,
+    "sources": [
+      "http://www.phpied.com/gzip-your-font-face-files/"
+    ]
+  },
+  "application/x-font-ttf": {
+    "compressible": true,
+    "sources": [
+      "http://www.phpied.com/gzip-your-font-face-files/"
+    ]
+  },
+  "application/x-java-jnlp-file": {
+    "compressible": false
+  },
+  "application/x-javascript": {
+    "compressible": true
+  },
+  "application/x-latex": {
+    "compressible": false
+  },
+  "application/x-mpegURL": {
+    "compressible": false
+  },
+  "application/x-pkcs12": {
+    "compressible": false
+  },
+  "application/x-rar-compressed": {
+    "compressible": false
+  },
+  "application/x-sh": {
+    "compressible": true
+  },
+  "application/x-shockwave-flash": {
+    "compressible": false
+  },
+  "application/x-stuffit": {
+    "compressible": false
+  },
+  "application/x-tar": {
+    "compressible": true
+  },
+  "application/x-www-form-urlencode": {
+    "compressible": false
+  },
+  "application/x-xpinstall": {
+    "compressible": false
+  },
+  "application/xhtml+xml": {
+    "compressible": true
+  },
+  "application/xml": {
+    "compressible": true
+  },
+  "application/xml-dtd": {
+    "compressible": true,
+    "sources": [
+      "http://en.wikipedia.org/wiki/Document_type_definition"
+    ]
+  },
+  "application/xop+xml": {
+    "compressible": true
+  },
+  "application/zip": {
+    "compressible": false
+  },
+  "audio/L24": {
+    "compressible": false
+  },
+  "audio/basic": {
+    "compressible": false
+  },
+  "audio/mp4": {
+    "compressible": false
+  },
+  "audio/mpeg": {
+    "compressible": false
+  },
+  "audio/ogg": {
+    "compressible": false
+  },
+  "audio/vnd.rn-realaudio": {
+    "compressible": false
+  },
+  "audio/vnd.wave": {
+    "compressible": false
+  },
+  "audio/vorbis": {
+    "compressible": false
+  },
+  "audio/webm": {
+    "compressible": false
+  },
+  "audio/x-aac": {
+    "compressible": false
+  },
+  "audio/x-caf": {
+    "compressible": false
+  },
+  "font/opentype": {
+    "compressible": true,
+    "sources": [
+      "http://www.phpied.com/gzip-your-font-face-files/"
+    ]
+  },
+  "image/bmp": {
+    "compressible": true,
+    "sources": [
+      "http://stackoverflow.com/a/12770116"
+    ]
+  },
+  "image/gif": {
+    "compressible": false
+  },
+  "image/jpeg": {
+    "compressible": false
+  },
+  "image/pjpeg": {
+    "compressible": false
+  },
+  "image/png": {
+    "compressible": false
+  },
+  "image/svg+xml": {
+    "compressible": true
+  },
+  "image/tiff": {
+    "compressible": false,
+    "sources": [
+      "http://stackoverflow.com/a/12770116"
+    ],
+    "notes": "Gains insignificant in testing."
+  },
+  "image/vnd.adobe.photoshop": {
+    "compressible": true
+  },
+  "image/x-icon": {
+    "compressible": true,
+    "sources": [
+      "http://en.wikipedia.org/wiki/ICO_(file_format)"
+    ],
+    "notes": "Usually a wrapper for .bmp formated images."
+  },
+  "image/x-xcf": {
+    "compressible": false
+  },
+  "message/http": {
+    "compressible": false,
+    "sources": [
+      "http://stackoverflow.com/a/1450163"
+    ],
+    "notes": "It is safest to leave these uncompressed."
+  },
+  "message/imdn+xml": {
+    "compressible": true,
+    "sources": [
+      "http://tools.ietf.org/html/rfc5438"
+    ]
+  },
+  "message/partial": {
+    "compressible": false
+  },
+  "message/rfc822": {
+    "compressible": true,
+    "sources": [
+      "http://en.wikipedia.org/wiki/MIME#Multipart_subtypes"
+    ]
+  },
+  "model/example": {
+    "compressible": false
+  },
+  "model/iges": {
+    "compressible": false
+  },
+  "model/mesh": {
+    "compressible": false
+  },
+  "model/vrml": {
+    "compressible": false
+  },
+  "model/x3d+binary": {
+    "compressible": false
+  },
+  "model/x3d+vrml": {
+    "compressible": false
+  },
+  "model/x3d+xml": {
+    "compressible": true,
+    "sources": [
+      "http://edutechwiki.unige.ch/en/X3D_file_structure"
+    ]
+  },
+  "multipart/alternative": {
+    "compressible": false
+  },
+  "multipart/encrypted": {
+    "compressible": false
+  },
+  "multipart/form-data": {
+    "compressible": false
+  },
+  "multipart/mixed": {
+    "compressible": false
+  },
+  "multipart/related": {
+    "compressible": false
+  },
+  "multipart/signed": {
+    "compressible": false
+  },
+  "text/cache-manifest": {
+    "compressible": true,
+    "sources": [
+      "https://bugzilla.mozilla.org/show_bug.cgi?id=715191#c2"
+    ],
+    "notes": "I think so."
+  },
+  "text/calender": {
+    "compressible": true,
+    "sources": [
+      "http://en.wikipedia.org/wiki/ICalendar"
+    ],
+    "notes": "Probably needs to be uncompressed before sent to iCalender."
+  },
+  "text/cmd": {
+    "compressible": true
+  },
+  "text/css": {
+    "compressible": true
+  },
+  "text/csv": {
+    "compressible": true
+  },
+  "text/html": {
+    "compressible": true
+  },
+  "text/javascript": {
+    "compressible": true
+  },
+  "text/n3": {
+    "compressible": true,
+    "sources": [
+      "http://en.wikipedia.org/wiki/Notation3"
+    ]
+  },
+  "text/plain": {
+    "compressible": true
+  },
+  "text/richtext": {
+    "compressible": true
+  },
+  "text/tab-separated-values": {
+    "compressible": true
+  },
+  "text/uri-list": {
+    "compressible": true
+  },
+  "text/vcard": {
+    "compressible": true
+  },
+  "text/x-gwt-rpc": {
+    "compressible": true
+  },
+  "text/x-jquery-tmpl": {
+    "compressible": true
+  },
+  "text/x-markdown": {
+    "compressible": true
+  },
+  "text/xml": {
+    "compressible": true
+  },
+  "video/mp4": {
+    "compressible": false
+  },
+  "video/mpeg": {
+    "compressible": false
+  },
+  "video/ogg": {
+    "compressible": false
+  },
+  "video/quicktime": {
+    "compressible": false
+  },
+  "video/webm": {
+    "compressible": false
+  },
+  "video/x-flv": {
+    "compressible": false
+  },
+  "video/x-matroska": {
+    "compressible": false
+  },
+  "video/x-ms-wmv": {
+    "compressible": false
+  },
+  "x-shader/x-fragment": {
+    "compressible": true,
+    "sources": [
+      "https://developer.mozilla.org/en-US/docs/Web/WebGL/Adding_2D_content_to_a_WebGL_context",
+      "https://bugzilla.mozilla.org/show_bug.cgi?id=715191#c2"
+    ]
+  },
+  "x-shader/x-vertex": {
+    "compressible": true,
+    "sources": [
+      "https://developer.mozilla.org/en-US/docs/Web/WebGL/Adding_2D_content_to_a_WebGL_context"
+    ]
+  }
+}
diff --git a/test/test.js b/test/test.js
new file mode 100644
index 0000000..976e061
--- /dev/null
+++ b/test/test.js
@@ -0,0 +1,90 @@
+var assert = require('assert')
+
+var specifications = require('../specifications.json')
+var compressible = require('../')
+
+// None of these should be actual types so that the lookup will never include them.
+var example_types = [
+  { type: 'something/text', should: true },
+  { type: 'type/json', should: true },
+  { type: 'data/beans+xml', should: true },
+  { type: 'asdf/nope', should: false },
+  { type: 'cats', should: false }
+]
+
+var invalid_types = [
+  undefined,
+  null,
+  0,
+  1,
+  false,
+  true
+]
+
+var object_true = {
+  compressible: true,
+  sources: ["compressible.regex"],
+  notes: "Automatically generated via regex."
+}, object_false = {
+  compressible: false,
+  sources: ["compressible.regex"],
+  notes: "Automatically generated via regex."
+}
+
+describe('Testing if spec lookups are correct.', function () {
+  for (var type in specifications) {
+    var value = specifications[type].compressible
+    it(type + ' should' + (value ? ' ' : ' not ') + 'be compressible', function () {
+      assert.equal(compressible(type), value)
+    })
+  }
+})
+
+describe('Testing if the regex works as intended.', function () {
+  example_types.forEach(function (example) {
+    it(example.type + ' should' + (example.should ? ' ' : ' not ') + 'be compressible', function () {
+      assert.equal(compressible(example.type), example.should)
+    })
+  })
+})
+
+describe('Testing if getter returns the correct objects.', function () {
+  it('All spec objects should be get-able', function () {
+    for (var type in specifications) {
+      assert.equal(compressible.get(type), specifications[type])
+    }
+  })
+  example_types.forEach(function (example) {
+    it(example.type + ' should generate a ' + (example.should ? 'true' : 'false') + ' object', function () {
+      assert.deepEqual(compressible.get(example.type), example.should ? object_true: object_false)
+    })
+  })
+})
+
+describe('Testing if charsets are handled correctly.', function () {
+  it('Charsets should be stripped off without issue', function () {
+    for (var type in specifications) {
+      var value = specifications[type].compressible
+      assert.equal(compressible(type + '; charset=utf-8'), value)
+    }
+  })
+  it('Types with charsets should be get-able', function () {
+    for (var type in specifications) {
+      assert.equal(compressible.get(type + '; charset=utf-8'), specifications[type])
+    }
+  })
+})
+
+describe('Ensuring invalid types do not cause errors.', function () {
+  it('No arguments should return false without error', function () {
+    assert.equal(compressible(), false)
+  })
+
+  invalid_types.forEach(function (invalid) {
+    it(invalid + ' should return false without error', function () {
+      assert.doesNotThrow(function () {
+        assert.equal(compressible(invalid), false)
+      })
+    })
+  })
+})

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-compressible.git



More information about the Pkg-javascript-commits mailing list