broofa / mime

Mime types for JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add `getExtensions()` method that returns all extensions for a given mime type

ssougnez opened this issue · comments

Some content type have multiple associated extensions. For example: https://github.com/jshttp/mime-db/blob/master/db.json#L7571

Calling getExtension should return ['html', 'htm', 'shtml'] instead, it returns only 'html'.

Therefore, it would make sense that this method was renamed in "getExtensions" and returned an array.

What do you think?

[My apologies for the late reply. This module is pretty stable these days, so I tend not to pay too much attention to it.]

Edited title to reflect the fact changing the behavior of getExtension() would be a breaking change, and I won't be doing that. Rather, if I were to take this it would be as an addition to the current API, (most likely as getExtensions()).

That said, I'm struggling to convince myself this is a good idea. I know it seems like a trivial change, but hear me out...

For starters, you can get this information w/out having to make this change. E.g. require('mime-types').extensions will give you what you're after. Or, in this module, require('mime/types/standard') and require('mime/types/other') will give you similar data, although I don't really recommend those as they're not part of the official API for this module and may break w/out warning... but as I've said, this module is pretty stable so not likely to break in the near future. Worst case, you can always hit up mime-db, which is the source of truth for both mime and mime-types.

There's also the question of whether enough people care about this to justify expanding the API surface. E.g. jshttp/mime-types#33 has been up for four years. 3-4 people have commented or liked that issue, but that's not a lot of activity for a project that has ~1,000 stars, 10M dependent projects in github, and 10M's downloads/week on NPM.

I'm also a little concerned that, in providing access to "all extensions", users are going to expect all of the extensions that might represent a given type. In looking at the list of types that have > 1 extension (below), I worry that it's not as comprehensive as it should be. E.g. The extensions for text/plain, application/msword, application/xml are more a "sampling" of extensions than a canonical list. (Which makes sense, given the nature of the sources from which mime-db data is pulled.)

I suspect there are a lot more extensions in the wild than are actually listed here, which means this could become a source of Issue reports that aren't actionable. (This is already a bit of a sore point for the mime* projects, as fixing these sorts of issues has to happen at IANA, Apache, or NGINX, where the mime mappings are pulled from.)


Standard types w/ > 1 extension (57):

script: ecma,es
application/inkml+xml: ink,inkml
application/java-archive: jar,war,ear
application/javascript: js,mjs
application/json: json,map
application/mathematica: ma,nb,mb
application/mp21: m21,mp21
application/mp4: mp4s,m4p
application/msword: doc,dot
application/octet-stream: bin,dms,lrf,mar,so,dist,distz,pkg,bpk,dump,elc,deploy,exe,dll,deb,dmg,iso,img,msi,msp,msm,buffer
application/onenote: onetoc,onetoc2,onetmp,onepkg
application/pgp-signature: asc,sig
application/pkcs7-mime: p7m,p7c
application/postscript: ai,eps,ps
application/rdf+xml: rdf,owl
application/sieve: siv,sieve
application/smil+xml: smi,smil
application/tei+xml: tei,teicorpus
application/xhtml+xml: xhtml,xht
application/xml: xml,xsl,xsd,rng
application/xslt+xml: *xsl,xslt
application/xv+xml: mxml,xhvml,xvml,xvm
audio/basic: au,snd
audio/midi: mid,midi,kar,rmi
audio/mp4: m4a,mp4a
audio/mpeg: mpga,mp2,mp2a,mp3,m2a,m3a
audio/ogg: oga,ogg,spx,opus
image/jp2: jp2,jpg2
image/jpeg: jpeg,jpg,jpe
image/jpx: jpx,jpf
image/svg+xml: svg,svgz
image/tiff: tif,tiff
message/rfc822: eml,mime
model/iges: igs,iges
model/mesh: msh,mesh,silo
model/vrml: wrl,vrml
model/x3d+binary: *x3db,x3dbz
model/x3d+vrml: *x3dv,x3dvz
model/x3d+xml: x3d,x3dz
text/cache-manifest: appcache,manifest
text/calendar: ics,ifb
text/coffeescript: coffee,litcoffee
text/html: html,htm,shtml
text/markdown: markdown,md
text/plain: txt,text,conf,def,list,log,in,ini
text/sgml: sgml,sgm
text/slim: slim,slm
text/stylus: stylus,styl
text/troff: t,tr,roff,man,me,ms
text/uri-list: uri,uris,urls
text/yaml: yaml,yml
video/3gpp: 3gp,3gpp
video/jpm: *jpm,jpgm
video/mj2: mj2,mjp2
video/mp4: mp4,mp4v,mpg4
video/mpeg: mpeg,mpg,mpe,m1v,m2v
video/quicktime: qt,mov

"Other" types with > 1 extension (77):

application/vnd.acucorp: atc,acutc
application/vnd.adobe.fxp: fxp,fxpl
application/vnd.clonk.c4group: c4g,c4d,c4f,c4p,c4u
application/vnd.dece.data: uvf,uvvf,uvd,uvvd
application/vnd.dece.ttml+xml: uvt,uvvt
application/vnd.dece.unspecified: uvx,uvvx
application/vnd.dece.zip: uvz,uvvz
application/vnd.eszigno3+xml: es3,et3
application/vnd.fdsn.seed: seed,dataless
application/vnd.framemaker: fm,frame,maker,book
application/vnd.geometry-explorer: gex,gre
application/vnd.grafeq: gqf,gqs
application/vnd.ibm.modcap: afp,listafp,list3820
application/vnd.iccprofile: icc,icm
application/vnd.intercon.formnet: xpw,xpx
application/vnd.kahootz: ktz,ktr
application/vnd.kde.kpresenter: kpr,kpt
application/vnd.kde.kword: kwd,kwt
application/vnd.kinar: kne,knp
application/vnd.koan: skp,skd,skt,skm
application/vnd.ms-excel: xls,xlm,xla,xlc,xlt,xlw
application/vnd.ms-powerpoint: ppt,pps,pot
application/vnd.ms-project: mpp,mpt
application/vnd.ms-works: wps,wks,wcm,wdb
application/vnd.nitf: ntf,nitf
application/vnd.palm: pdb,pqa,oprc
application/vnd.quark.quarkxpress: qxd,qxt,qwd,qwt,qxl,qxb
application/vnd.simtech-mindmapper: twd,twds
application/vnd.solent.sdkm+xml: sdkm,sdkd
application/vnd.stardivision.writer: sdw,vor
application/vnd.sus-calendar: sus,susp
application/vnd.symbian.install: sis,sisx
application/vnd.tcpdump.pcap: pcap,cap,dmp
application/vnd.ufdl: ufd,ufdl
application/vnd.visio: vsd,vst,vss,vsw
application/vnd.zul: zir,zirz
application/x-authorware-bin: aab,x32,u32,vox
application/x-blorb: blb,blorb
application/x-bzip2: bz2,boz
application/x-cbr: cbr,cba,cbt,cbz,cb7
application/x-debian-package: *deb,udeb
application/x-director: dir,dcr,dxr,cst,cct,cxt,w3d,fgd,swa
application/x-font-type1: pfa,pfb,pfm,afm
application/x-lzh-compressed: lzh,lha
application/x-mobipocket-ebook: prc,mobi
application/x-msdownload: *exe,*dll,com,bat,*msi
application/x-msmediaview: mvb,m13,m14
application/x-msmetafile: *wmf,*wmz,*emf,emz
application/x-netcdf: nc,cdf
application/x-perl: pl,pm
application/x-pilot: *prc,*pdb
application/x-pkcs12: p12,pfx
application/x-pkcs7-certificates: p7b,spc
application/x-tcl: tcl,tk
application/x-texinfo: texinfo,texi
application/x-x509-ca-cert: der,crt,pem
application/x-zmachine: z1,z2,z3,z4,z5,z6,z7,z8
audio/vnd.dece.audio: uva,uvva
audio/x-aiff: aif,aiff,aifc
audio/x-pn-realaudio: ram,ra
image/vnd.dece.graphic: uvi,uvvi,uvg,uvvg
image/vnd.djvu: djvu,djv
image/x-freehand: fh,fhc,fh4,fh5,fh7
image/x-pict: pic,pct
text/x-asm: s,asm
text/x-c: c,cc,cxx,cpp,h,hh,dic
text/x-fortran: f,for,f77,f90
text/x-pascal: p,pas
video/vnd.dece.hd: uvh,uvvh
video/vnd.dece.mobile: uvm,uvvm
video/vnd.dece.pd: uvp,uvvp
video/vnd.dece.sd: uvs,uvvs
video/vnd.dece.video: uvv,uvvv
video/vnd.mpegurl: mxu,m4u
video/vnd.uvvu.mp4: uvu,uvvu
video/x-matroska: mkv,mk3d,mks
video/x-ms-asf: asf,asx

Closing. mime@4 (just published beta) adds a getAllExtensions() method.