Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

index.js 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*!
  2. * compressible
  3. * Copyright(c) 2013 Jonathan Ong
  4. * Copyright(c) 2014 Jeremiah Senkpiel
  5. * Copyright(c) 2015 Douglas Christopher Wilson
  6. * MIT Licensed
  7. */
  8. 'use strict'
  9. /**
  10. * Module dependencies.
  11. * @private
  12. */
  13. var db = require('mime-db')
  14. /**
  15. * Module variables.
  16. * @private
  17. */
  18. var COMPRESSIBLE_TYPE_REGEXP = /^text\/|\+(?:json|text|xml)$/i
  19. var EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/
  20. /**
  21. * Module exports.
  22. * @public
  23. */
  24. module.exports = compressible
  25. /**
  26. * Checks if a type is compressible.
  27. *
  28. * @param {string} type
  29. * @return {Boolean} compressible
  30. * @public
  31. */
  32. function compressible (type) {
  33. if (!type || typeof type !== 'string') {
  34. return false
  35. }
  36. // strip parameters
  37. var match = EXTRACT_TYPE_REGEXP.exec(type)
  38. var mime = match && match[1].toLowerCase()
  39. var data = db[mime]
  40. // return database information
  41. if (data && data.compressible !== undefined) {
  42. return data.compressible
  43. }
  44. // fallback to regexp or unknown
  45. return COMPRESSIBLE_TYPE_REGEXP.test(mime) || undefined
  46. }