Ein Projekt das es ermöglicht Beerpong über das Internet von zwei unabhängigen positionen aus zu spielen. Entstehung im Rahmen einer Praktikumsaufgabe im Fach Interaktion.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. var db = require('mime-db')
  2. // types[extension] = type
  3. exports.types = Object.create(null)
  4. // extensions[type] = [extensions]
  5. exports.extensions = Object.create(null)
  6. Object.keys(db).forEach(function (name) {
  7. var mime = db[name]
  8. var exts = mime.extensions
  9. if (!exts || !exts.length) return
  10. exports.extensions[name] = exts
  11. exts.forEach(function (ext) {
  12. exports.types[ext] = name
  13. })
  14. })
  15. exports.lookup = function (string) {
  16. if (!string || typeof string !== "string") return false
  17. // remove any leading paths, though we should just use path.basename
  18. string = string.replace(/.*[\.\/\\]/, '').toLowerCase()
  19. if (!string) return false
  20. return exports.types[string] || false
  21. }
  22. exports.extension = function (type) {
  23. if (!type || typeof type !== "string") return false
  24. // to do: use media-typer
  25. type = type.match(/^\s*([^;\s]*)(?:;|\s|$)/)
  26. if (!type) return false
  27. var exts = exports.extensions[type[1].toLowerCase()]
  28. if (!exts || !exts.length) return false
  29. return exts[0]
  30. }
  31. // type has to be an exact mime type
  32. exports.charset = function (type) {
  33. var mime = db[type]
  34. if (mime && mime.charset) return mime.charset
  35. // default text/* to utf-8
  36. if (/^text\//.test(type)) return 'UTF-8'
  37. return false
  38. }
  39. // backwards compatibility
  40. exports.charsets = {
  41. lookup: exports.charset
  42. }
  43. // to do: maybe use set-type module or something
  44. exports.contentType = function (type) {
  45. if (!type || typeof type !== "string") return false
  46. if (!~type.indexOf('/')) type = exports.lookup(type)
  47. if (!type) return false
  48. if (!~type.indexOf('charset')) {
  49. var charset = exports.charset(type)
  50. if (charset) type += '; charset=' + charset.toLowerCase()
  51. }
  52. return type
  53. }