Sha256: b0b0983e39f433b0164cef6707e42c580a427a5b27f3d0d423a022b2e3228478

Contents?: true

Size: 1.92 KB

Versions: 34

Compression:

Stored size: 1.92 KB

Contents

// types[extension] = type
exports.types = Object.create(null)
// extensions[type] = [extensions]
exports.extensions = Object.create(null)
// define more mime types
exports.define = define

// store the json files
exports.json = {
  mime: require('./mime.json'),
  node: require('./node.json'),
  custom: require('./custom.json'),
}

exports.lookup = function (string) {
  if (!string || typeof string !== "string") return false
  string = string.replace(/.*[\.\/\\]/, '').toLowerCase()
  if (!string) return false
  return exports.types[string] || false
}

exports.extension = function (type) {
  if (!type || typeof type !== "string") return false
  type = type.match(/^\s*([^;\s]*)(?:;|\s|$)/)
  if (!type) return false
  var exts = exports.extensions[type[1].toLowerCase()]
  if (!exts || !exts.length) return false
  return exts[0]
}

// type has to be an exact mime type
exports.charset = function (type) {
  // special cases
  switch (type) {
    case 'application/json': return 'UTF-8'
    case 'application/javascript': return 'UTF-8'
  }

  // default text/* to utf-8
  if (/^text\//.test(type)) return 'UTF-8'

  return false
}

// backwards compatibility
exports.charsets = {
  lookup: exports.charset
}

exports.contentType = function (type) {
  if (!type || typeof type !== "string") return false
  if (!~type.indexOf('/')) type = exports.lookup(type)
  if (!type) return false
  if (!~type.indexOf('charset')) {
    var charset = exports.charset(type)
    if (charset) type += '; charset=' + charset.toLowerCase()
  }
  return type
}

define(exports.json.mime)
define(exports.json.node)
define(exports.json.custom)

function define(json) {
  Object.keys(json).forEach(function (type) {
    var exts = json[type] || []
    exports.extensions[type] = exports.extensions[type] || []
    exts.forEach(function (ext) {
      if (!~exports.extensions[type].indexOf(ext)) exports.extensions[type].push(ext)
      exports.types[ext] = type
    })
  })
}

Version data entries

34 entries across 20 versions & 3 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/node_modules/request/node_modules/mime-types/lib/index.js
hooch-0.4.1 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/node_modules/request/node_modules/mime-types/lib/index.js
hooch-0.4.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/node_modules/request/node_modules/mime-types/lib/index.js
gulp_assets-1.0.0.pre.5 template/node_modules/gulp-sass/node_modules/node-sass/node_modules/pangyp/node_modules/request/node_modules/mime-types/lib/index.js
gulp_assets-1.0.0.pre.4 template/node_modules/gulp-sass/node_modules/node-sass/node_modules/pangyp/node_modules/request/node_modules/mime-types/lib/index.js
gulp_assets-1.0.0.pre.3 template/node_modules/gulp-sass/node_modules/node-sass/node_modules/pangyp/node_modules/request/node_modules/mime-types/lib/index.js
hooch-0.3.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/node_modules/request/node_modules/mime-types/lib/index.js
hooch-0.2.1 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/node_modules/request/node_modules/mime-types/lib/index.js
hooch-0.2.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/node_modules/request/node_modules/mime-types/lib/index.js
hooch-0.1.0 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/node_modules/request/node_modules/mime-types/lib/index.js
hooch-0.0.8 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/node_modules/request/node_modules/mime-types/lib/index.js
hooch-0.0.7 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/node_modules/request/node_modules/mime-types/lib/index.js
hooch-0.0.6 jasmine/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/node_modules/request/node_modules/mime-types/lib/index.js
entangled-0.0.16 spec/dummy/public/node_modules/bower/node_modules/bower-registry-client/node_modules/request/node_modules/mime-types/lib/index.js
entangled-0.0.16 spec/dummy/public/node_modules/phantomjs/node_modules/request/node_modules/mime-types/lib/index.js
entangled-0.0.16 spec/dummy/public/node_modules/bower/node_modules/request/node_modules/mime-types/lib/index.js
entangled-0.0.15 spec/dummy/public/node_modules/phantomjs/node_modules/request/node_modules/mime-types/lib/index.js
entangled-0.0.15 spec/dummy/public/node_modules/bower/node_modules/bower-registry-client/node_modules/request/node_modules/mime-types/lib/index.js
entangled-0.0.15 spec/dummy/public/node_modules/bower/node_modules/request/node_modules/mime-types/lib/index.js
entangled-0.0.14 spec/dummy/public/node_modules/phantomjs/node_modules/request/node_modules/mime-types/lib/index.js