Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.68 KB | None | 0 0
  1.  
  2. const applicationTypesExt = {
  3. 'a' : 'application/octet-stream',
  4. 'ai' : 'application/postscript',
  5. 'bin' : 'application/octet-stream',
  6. 'cdf' : 'application/x-cdf',
  7. 'csh' : 'application/x-csh',
  8. 'dll' : 'application/octet-stream',
  9. 'doc' : 'application/msword',
  10. 'dot' : 'application/msword',
  11. 'dvi' : 'application/x-dvi',
  12. 'eps' : 'application/postscript',
  13. 'exe' : 'application/octet-stream',
  14. 'gtar' : 'application/x-gtar',
  15. 'hdf' : 'application/x-hdf',
  16. 'js' : 'application/x-javascript',
  17. 'latex' : 'application/x-latex',
  18. 'man' : 'application/x-troff-man',
  19. 'me' : 'application/x-troff-me',
  20. 'mif' : 'application/x-mif',
  21. 'ms' : 'application/x-troff-ms',
  22. 'nc' : 'application/x-netcdf',
  23. 'o' : 'application/octet-stream',
  24. 'obj' : 'application/octet-stream',
  25. 'oda' : 'application/oda',
  26. 'pdf' : 'application/pdf',
  27. 'pfx' : 'application/x-pkcs12',
  28. 'pot' : 'application/vnd.ms-powerpoint',
  29. 'ppa' : 'application/vnd.ms-powerpoint',
  30. 'pps' : 'application/vnd.ms-powerpoint',
  31. 'ppt' : 'application/vnd.ms-powerpoint',
  32. 'pptx' : 'application/vnd.ms-powerpoint',
  33. 'ps' : 'application/postscript',
  34. 'pwz' : 'application/vnd.ms-powerpoint',
  35. 'pyc' : 'application/x-python-code',
  36. 'pyo' : 'application/x-python-code',
  37. 'ram' : 'application/x-pn-realaudio',
  38. 'roff' : 'application/x-troff',
  39. 'so' : 'application/octet-stream',
  40. 'src' : 'application/x-wais-source',
  41. 'swf' : 'application/x-shockwave-flash',
  42. 't' : 'application/x-troff',
  43. 'tar' : 'application/x-tar',
  44. 'tcl' : 'application/x-tcl',
  45. 'tex' : 'application/x-tex',
  46. 'texi' : 'application/x-texinfo',
  47. 'texinfo': 'application/x-texinfo',
  48. 'rdf' : 'application/xml',
  49. 'sh' : 'application/x-sh',
  50. 'shar' : 'application/x-shar',
  51. 'tr' : 'application/x-troff',
  52. 'ustar' : 'application/x-ustar',
  53. 'wiz' : 'application/msword',
  54. 'wsdl' : 'application/xml',
  55. 'xlb' : 'application/vnd.ms-excel',
  56. 'xls' : 'application/vnd.ms-excel',
  57. 'xlsx' : 'application/vnd.ms-excel',
  58. 'xpdl' : 'application/xml',
  59. 'xsl' : 'application/xml',
  60. 'zip' : 'application/zip',
  61. };
  62.  
  63. const applicationTypes = makeUniqueArrayOfValues(applicationTypesExt);
  64.  
  65. const audioTypesExt = {
  66. 'aif' : 'audio/x-aiff',
  67. 'aifc' : 'audio/x-aiff',
  68. 'aiff' : 'audio/x-aiff',
  69. 'au' : 'audio/basic',
  70. 'mp2' : 'audio/mpeg',
  71. 'mp3' : 'audio/mpeg',
  72. 'ra' : 'audio/x-pn-realaudio',
  73. 'snd' : 'audio/basic',
  74. 'wav' : 'audio/x-wav',
  75. };
  76.  
  77. const audioTypes = makeUniqueArrayOfValues(audioTypesExt);
  78.  
  79. const videoTypesExt = {
  80. 'avi' : 'video/x-msvideo',
  81. 'm1v' : 'video/mpeg',
  82. 'mov' : 'video/quicktime',
  83. 'movie' : 'video/x-sgi-movie',
  84. 'mp4' : 'video/mp4',
  85. 'mpa' : 'video/mpeg',
  86. 'mpe' : 'video/mpeg',
  87. 'mpeg' : 'video/mpeg',
  88. 'mpg' : 'video/mpeg',
  89. 'qt' : 'video/quicktime',
  90. };
  91.  
  92. const videoTypes = makeUniqueArrayOfValues(videoTypesExt);
  93.  
  94. const textTypesExt = {
  95. 'bat' : 'text/plain',
  96. 'c' : 'text/plain',
  97. 'css' : 'text/css',
  98. 'etx' : 'text/x-setext',
  99. 'h' : 'text/plain',
  100. 'htm' : 'text/html',
  101. 'html' : 'text/html',
  102. 'ksh' : 'text/plain',
  103. 'py' : 'text/x-python',
  104. 'rtx' : 'text/richtext',
  105. 'sgm' : 'text/x-sgml',
  106. 'sgml' : 'text/x-sgml',
  107. 'tsv' : 'text/tab-separated-values',
  108. 'txt' : 'text/plain',
  109. 'vcf' : 'text/x-vcard',
  110. 'xml' : 'text/xml',
  111. };
  112.  
  113. const textTypes = makeUniqueArrayOfValues(textTypesExt);
  114.  
  115. const imageTypesExt = {
  116. 'bmp' : 'image/x-ms-bmp',
  117. 'gif' : 'image/gif',
  118. 'jpe' : 'image/jpeg',
  119. 'jpeg' : 'image/jpeg',
  120. 'jpg' : 'image/jpeg',
  121. 'pbm' : 'image/x-portable-bitmap',
  122. 'pgm' : 'image/x-portable-graymap',
  123. 'png' : 'image/png',
  124. 'pnm' : 'image/x-portable-anymap',
  125. 'ppm' : 'image/x-portable-pixmap',
  126. 'ras' : 'image/x-cmu-raster',
  127. 'rgb' : 'image/x-rgb',
  128. 'tif' : 'image/tiff',
  129. 'tiff' : 'image/tiff',
  130. 'xbm' : 'image/x-xbitmap',
  131. 'xpm' : 'image/x-xpixmap',
  132. 'xwd' : 'image/x-xwindowdump',
  133. };
  134.  
  135. const imageTypes = makeUniqueArrayOfValues(imageTypesExt);
  136.  
  137. const messageTypesExt = {
  138. 'eml' : 'message/rfc822',
  139. 'mht' : 'message/rfc822',
  140. 'mhtml' : 'message/rfc822',
  141. 'nws' : 'message/rfc822',
  142. };
  143.  
  144. const messageTypes = makeUniqueArrayOfValues(messageTypesExt);
  145.  
  146. function concatObjects(objects){
  147. let finalObj = {};
  148. objects.forEach(function(obj){
  149. for(let key in obj){
  150. finalObj[key] = obj[key];
  151. }
  152. });
  153. return finalObj;
  154. }
  155.  
  156. function makeUniqueArrayOfValues(obj){
  157. let unique = [];
  158. for(let key in obj){
  159. if(unique.indexOf(obj[key]) === -1){
  160. unique.push(obj[key]);
  161. }
  162. }
  163. return unique;
  164. }
  165.  
  166. const extensions = {
  167. application: applicationTypesExt,
  168. audio: audioTypesExt,
  169. video: videoTypesExt,
  170. text: textTypesExt,
  171. image: imageTypesExt,
  172. message: messageTypesExt
  173. };
  174. const kinds = {
  175. application: applicationTypes,
  176. audio: audioTypes,
  177. video: videoTypes,
  178. text: textTypes,
  179. image: imageTypes,
  180. message: messageTypes
  181. };
  182. const fullExtension = concatObjects([applicationTypesExt, audioTypesExt, videoTypesExt, textTypesExt, imageTypesExt, messageTypesExt])
  183.  
  184. class MimeTypes {
  185.  
  186. static get extensions(){
  187. return extensions;
  188. }
  189.  
  190. static get kinds() {
  191. return kinds;
  192. }
  193.  
  194. static get fullExtension() {
  195. return fullExtension;
  196. }
  197.  
  198. static isKind(kind, mimeType){
  199. return MimeTypes.kinds[kind].indexOf(mimeType) > -1;
  200. }
  201.  
  202. static getMimeType(extension){
  203. return MimeTypes.fullExtension[extension];
  204. }
  205.  
  206. static getKind(mimeType) {
  207. for(let key in MimeTypes.kinds){
  208. if(MimeTypes.isKind(key, mimeType)){
  209. return key;
  210. }
  211. }
  212. }
  213. }
  214.  
  215. export default MimeTypes;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement