pax_global_header00006660000000000000000000000064134601600510014506gustar00rootroot0000000000000052 comment=57985690741c2670fb5c171bdefb07114ce1a63f compressible-2.0.17/000077500000000000000000000000001346016005100142645ustar00rootroot00000000000000compressible-2.0.17/.eslintignore000066400000000000000000000000421346016005100167630ustar00rootroot00000000000000.nyc_output coverage node_modules compressible-2.0.17/.eslintrc.yml000066400000000000000000000000351346016005100167060ustar00rootroot00000000000000root: true extends: standard compressible-2.0.17/.gitignore000066400000000000000000000001021346016005100162450ustar00rootroot00000000000000.nyc_output coverage node_modules npm-debug.log package-lock.json compressible-2.0.17/.travis.yml000066400000000000000000000057371346016005100164110ustar00rootroot00000000000000language: node_js node_js: - "0.6" - "0.8" - "0.10" - "0.12" - "1.8" - "2.5" - "3.3" - "4.9" - "5.12" - "6.17" - "7.10" - "8.15" - "9.11" - "10.15" - "11.12" - "12.0" sudo: false dist: trusty env: global: # Suppress Node.js 0.6 compile warnings - "CXXCOM='$CXX -o $TARGET -c $CXXFLAGS $CCFLAGS -Wno-unused-local-typedefs -Wno-maybe-uninitialized -Wno-narrowing -Wno-strict-overflow $_CCCOMCOM $SOURCES'" cache: directories: - node_modules before_install: - | # Setup utility functions function node_version_lt () { [[ "$(v "$TRAVIS_NODE_VERSION")" -lt "$(v "${1}")" ]] } function npm_module_installed () { npm -lsp ls | grep -Fq "$(pwd)/node_modules/${1}:${1}@" } function npm_remove_module_re () { node -e ' fs = require("fs"); p = JSON.parse(fs.readFileSync("package.json", "utf8")); r = RegExp(process.argv[1]); for (k in p.devDependencies) { if (r.test(k)) delete p.devDependencies[k]; } fs.writeFileSync("package.json", JSON.stringify(p, null, 2) + "\n"); ' "$@" } function npm_use_module () { node -e ' fs = require("fs"); p = JSON.parse(fs.readFileSync("package.json", "utf8")); p.devDependencies[process.argv[1]] = process.argv[2]; fs.writeFileSync("package.json", JSON.stringify(p, null, 2) + "\n"); ' "$@" } function v () { tr '.' '\n' <<< "${1}" \ | awk '{ printf "%03d", $0 }' \ | sed 's/^0*//' } # Configure npm - | # Skip updating shrinkwrap / lock npm config set shrinkwrap false # Setup Node.js version-specific dependencies - | # Configure eslint for linting if node_version_lt '6.0'; then npm_remove_module_re '^eslint(-|$)' fi - | # Configure mocha for testing if node_version_lt '0.8' ; then npm_use_module 'mocha' '1.21.5' elif node_version_lt '0.10'; then npm_use_module 'mocha' '2.5.3' elif node_version_lt '4.0' ; then npm_use_module 'mocha' '3.5.3' elif node_version_lt '6.0' ; then npm_use_module 'mocha' '5.2.0' fi - | # Configure nyc for testing if node_version_lt '0.10'; then npm_remove_module_re '^nyc$' elif node_version_lt '4.0' ; then npm_use_module 'nyc' '10.3.2' elif node_version_lt '6.0' ; then npm_use_module 'nyc' '11.9.0' fi # Update Node.js modules - | # Prune & rebuild node_modules if [[ -d node_modules ]]; then npm prune npm rebuild fi before_script: - | # Contents of node_modules npm -s ls ||: script: - | # Run test script if npm_module_installed 'nyc'; then npm run-script test-travis else npm test fi - | # Run linting, if eslint exists if npm_module_installed 'eslint'; then npm run-script lint fi after_script: - | # Upload coverage to coveralls, if exists if [[ -d .nyc_output ]]; then npm install --save-dev coveralls@2 nyc report --reporter=text-lcov | coveralls fi compressible-2.0.17/HISTORY.md000066400000000000000000000034251346016005100157530ustar00rootroot000000000000002.0.17 / 2019-04-24 =================== * deps: mime-db@'>= 1.40.0 < 2' 2.0.16 / 2019-02-18 =================== * deps: mime-db@'>= 1.38.0 < 2' - Mark `text/less` as compressible 2.0.15 / 2018-09-17 =================== * deps: mime-db@'>= 1.36.0 < 2' 2.0.14 / 2018-06-05 =================== * deps: mime-db@'>= 1.34.0 < 2' - Mark all XML-derived types as compressible 2.0.13 / 2018-02-17 =================== * deps: mime-db@'>= 1.33.0 < 2' 2.0.12 / 2017-10-20 =================== * deps: mime-db@'>= 1.30.0 < 2' 2.0.11 / 2017-07-27 =================== * deps: mime-db@'>= 1.29.0 < 2' 2.0.10 / 2017-03-23 =================== * deps: mime-db@'>= 1.27.0 < 2' 2.0.9 / 2016-10-31 ================== * Fix regex fallback to not override `compressible: false` in db * deps: mime-db@'>= 1.24.0 < 2' 2.0.8 / 2016-05-12 ================== * deps: mime-db@'>= 1.23.0 < 2' 2.0.7 / 2016-01-18 ================== * deps: mime-db@'>= 1.21.0 < 2' 2.0.6 / 2015-09-29 ================== * deps: mime-db@'>= 1.19.0 < 2' 2.0.5 / 2015-07-30 ================== * deps: mime-db@'>= 1.16.0 < 2' 2.0.4 / 2015-07-01 ================== * deps: mime-db@'>= 1.14.0 < 2' * perf: enable strict mode 2.0.3 / 2015-06-08 ================== * Fix regex fallback to work if type exists, but is undefined * perf: hoist regex declaration * perf: use regex to extract mime * deps: mime-db@'>= 1.13.0 < 2' 2.0.2 / 2015-01-31 ================== * deps: mime-db@'>= 1.1.2 < 2' 2.0.1 / 2014-09-28 ================== * deps: mime-db@1.x - Add new mime types - Add additional compressible - Update charsets 2.0.0 / 2014-09-02 ================== * use mime-db * remove .get() * specifications are now private * regex is now private * stricter regex compressible-2.0.17/LICENSE000066400000000000000000000023211346016005100152670ustar00rootroot00000000000000(The MIT License) Copyright (c) 2013 Jonathan Ong Copyright (c) 2014 Jeremiah Senkpiel Copyright (c) 2015 Douglas Christopher Wilson 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. compressible-2.0.17/README.md000066400000000000000000000034051346016005100155450ustar00rootroot00000000000000# compressible [![NPM Version][npm-version-image]][npm-url] [![NPM Downloads][npm-downloads-image]][npm-url] [![Node.js Version][node-version-image]][node-version-url] [![Build Status][travis-image]][travis-url] [![Test Coverage][coveralls-image]][coveralls-url] Compressible `Content-Type` / `mime` checking. ## Installation ```sh $ npm install compressible ``` ## API ```js var compressible = require('compressible') ``` ### compressible(type) Checks if the given `Content-Type` is compressible. The `type` argument is expected to be a value MIME type or `Content-Type` string, though no validation is performed. The MIME is looked up in the [`mime-db`](https://www.npmjs.com/package/mime-db) and if there is compressible information in the database entry, that is returned. Otherwise, this module will fallback to `true` for the following types: * `text/*` * `*/*+json` * `*/*+text` * `*/*+xml` If this module is not sure if a type is specifically compressible or specifically uncompressible, `undefined` is returned. ```js compressible('text/html') // => true compressible('image/png') // => false ``` ## License [MIT](LICENSE) [coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/compressible/master [coveralls-url]: https://coveralls.io/r/jshttp/compressible?branch=master [node-version-image]: https://badgen.net/npm/node/compressible [node-version-url]: https://nodejs.org/en/download [npm-downloads-image]: https://badgen.net/npm/dm/compressible [npm-url]: https://npmjs.org/package/compressible [npm-version-image]: https://badgen.net/npm/v/compressible [travis-image]: https://badgen.net/travis/jshttp/compressible/master [travis-url]: https://travis-ci.org/jshttp/compressible compressible-2.0.17/index.js000066400000000000000000000020161346016005100157300ustar00rootroot00000000000000/*! * compressible * Copyright(c) 2013 Jonathan Ong * Copyright(c) 2014 Jeremiah Senkpiel * Copyright(c) 2015 Douglas Christopher Wilson * MIT Licensed */ 'use strict' /** * Module dependencies. * @private */ var db = require('mime-db') /** * Module variables. * @private */ var COMPRESSIBLE_TYPE_REGEXP = /^text\/|\+(?:json|text|xml)$/i var EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/ /** * Module exports. * @public */ module.exports = compressible /** * Checks if a type is compressible. * * @param {string} type * @return {Boolean} compressible * @public */ function compressible (type) { if (!type || typeof type !== 'string') { return false } // strip parameters var match = EXTRACT_TYPE_REGEXP.exec(type) var mime = match && match[1].toLowerCase() var data = db[mime] // return database information if (data && data.compressible !== undefined) { return data.compressible } // fallback to regexp or unknown return COMPRESSIBLE_TYPE_REGEXP.test(mime) || undefined } compressible-2.0.17/package.json000066400000000000000000000024371346016005100165600ustar00rootroot00000000000000{ "name": "compressible", "description": "Compressible Content-Type / mime checking", "version": "2.0.17", "contributors": [ "Douglas Christopher Wilson ", "Jonathan Ong (http://jongleberry.com)", "Jeremiah Senkpiel (https://searchbeam.jit.su)" ], "license": "MIT", "repository": "jshttp/compressible", "keywords": [ "compress", "gzip", "mime", "content-type" ], "dependencies": { "mime-db": ">= 1.40.0 < 2" }, "devDependencies": { "eslint": "5.15.2", "eslint-config-standard": "12.0.0", "eslint-plugin-import": "2.16.0", "eslint-plugin-markdown": "1.0.0", "eslint-plugin-node": "8.0.1", "eslint-plugin-promise": "4.0.1", "eslint-plugin-standard": "4.0.0", "mocha": "6.1.4", "nyc": "14.0.0" }, "engines": { "node": ">= 0.6" }, "files": [ "HISTORY.md", "LICENSE", "README.md", "index.js" ], "scripts": { "lint": "eslint --plugin markdown --ext js,md .", "test": "mocha --reporter spec --bail --check-leaks test/", "test-cov": "nyc --reporter=html --reporter=text npm test", "test-travis": "nyc --reporter=text npm test", "version": "node scripts/version-history.js && git add HISTORY.md" } } compressible-2.0.17/scripts/000077500000000000000000000000001346016005100157535ustar00rootroot00000000000000compressible-2.0.17/scripts/version-history.js000066400000000000000000000027771346016005100215120ustar00rootroot00000000000000'use strict' var fs = require('fs') var path = require('path') var HISTORY_FILE_PATH = path.join(__dirname, '..', 'HISTORY.md') var MD_HEADER_REGEXP = /^====*$/ var VERSION = process.env.npm_package_version var VERSION_PLACEHOLDER_REGEXP = /^(?:unreleased|(\d+\.)+x)$/ var historyFileLines = fs.readFileSync(HISTORY_FILE_PATH, 'utf-8').split('\n') if (!MD_HEADER_REGEXP.test(historyFileLines[1])) { console.error('Missing header in HISTORY.md') process.exit(1) } if (!VERSION_PLACEHOLDER_REGEXP.test(historyFileLines[0])) { console.error('Missing placegolder version in HISTORY.md') process.exit(1) } if (historyFileLines[0].indexOf('x') !== -1) { var versionCheckRegExp = new RegExp('^' + historyFileLines[0].replace('x', '.+') + '$') if (!versionCheckRegExp.test(VERSION)) { console.error('Version %s does not match placeholder %s', VERSION, historyFileLines[0]) process.exit(1) } } historyFileLines[0] = VERSION + ' / ' + getLocaleDate() historyFileLines[1] = repeat('=', historyFileLines[0].length) fs.writeFileSync(HISTORY_FILE_PATH, historyFileLines.join('\n')) function getLocaleDate () { var now = new Date() return zeroPad(now.getFullYear(), 4) + '-' + zeroPad(now.getMonth() + 1, 2) + '-' + zeroPad(now.getDate(), 2) } function repeat (str, length) { var out = '' for (var i = 0; i < length; i++) { out += str } return out } function zeroPad (number, length) { var num = number.toString() while (num.length < length) { num = '0' + num } return num } compressible-2.0.17/test/000077500000000000000000000000001346016005100152435ustar00rootroot00000000000000compressible-2.0.17/test/.eslintrc.yml000066400000000000000000000000231346016005100176620ustar00rootroot00000000000000env: mocha: true compressible-2.0.17/test/test.js000066400000000000000000000051101346016005100165550ustar00rootroot00000000000000var assert = require('assert') var db = require('mime-db') var compressible = require('../') // None of these should be actual types so that the lookup will never include them. var EXAMPLE_TYPES = [ { type: 'text/penguins', should: true }, { type: 'text/html', should: true }, { type: 'text/plain', should: true }, { type: 'text/jade', should: true }, { type: 'something/text', should: undefined }, { type: 'something/frog+TEXT', should: true }, { type: 'type/json;askjkl+json', should: undefined }, { type: 'type/+json', should: true }, { type: 'data/beans+xml ; charset="utf-8"', should: true }, { type: 'can/worms+xml;blaaaah', should: true }, { type: 'data/xml', should: undefined }, { type: 'asdf/nope', should: undefined }, { type: 'cats', should: undefined } ] var INVALID_TYPES = [ undefined, null, 0, 1, false, true ] describe('Testing if spec lookups are correct.', function () { it('All DB `compressible` types should reflect in compressible', function () { for (var type in db) { if (db[type].compressible !== undefined) { assert.strictEqual(compressible(type), db[type].compressible) } } }) }) 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.strictEqual(compressible(example.type), example.should) }) }) }) describe('Testing if charsets are handled correctly.', function () { it('Charsets should be stripped off without issue', function () { for (var type in db) { if (db[type].compressible !== undefined) { assert.strictEqual(compressible(type + '; charset=utf-8'), db[type].compressible) } } }) }) describe('Ensuring invalid types do not cause errors.', function () { it('No arguments should return false without error', function () { assert.strictEqual(compressible(), false) }) INVALID_TYPES.forEach(function (invalid) { it(invalid + ' should return false without error', function () { assert.doesNotThrow(function () { assert.strictEqual(compressible(invalid), false) }) }) }) }) describe('Ensuring types are always stripped correctly.', function () { it('Uppercase types should work', function () { assert.strictEqual(compressible('TEXT/HTML'), true) assert.strictEqual(compressible('TEXT/plain; charset="utf-8"'), true) }) it('White-spaced types should work', function () { assert.strictEqual(compressible('application/json ; charset="utf-8"'), true) }) })