@contentful/mimetype

2.3.0 • Public • Published

contentful-mimetype [CircleCI] codecov

Mimetype handling and identification

This is mostly used by the UI to figure out which icons to show for different filetypes.

It does a best effort guess to figure out which icon to show, which might not always come out very accurate.

It should be updated over time with relevant file types and mime types and it is by no means a definitive representation of all available file types.

Glossary

  • type - A media/MIME type http://en.wikipedia.org/wiki/Internet_media_type
  • group - A group of types that corresponds to a more global type of media (ex: plaintext, image, video, audio, etc)
  • group name - the display name for a given group
  • group label - the label used to identify a group in fileGroups.json and groupNames.json

API

Options object used by various methods

The methods that take this object as a parameter will always try to use the type if available. If the type is not available or is undefined, it will use the file extension as a fallback. You can also provide a fallback file name from which the extension will be extracted if not provided.

/**
 * @typedef {object} mimetypeParams
 * @prop {string} type Content MIME type
 * @prop {string} fallbackExt Fallback extension
 * @prop {string} fallbackFileName Fallback file name
*/

getGroupNames

  /**
   * Gets list of names for groups of mimetypes
   *
   * @returns {object}
  */

getGroupName

  /**
   * Gets name of group file belongs to
   *
   * @param {mimetypeParams} mimetypeParams MIME type parameters
   * @returns {string}
  */

getGroupLabels

  /**
   * Gets list of labels for groups
   *
   * @returns {array}
  */

getGroupLabel

  /**
   * Gets label for group the file belongs to
   *
   * @param {mimetypeParams} mimetypeParams MIME type parameters
   * @returns {string}
  */

getExtension

  /**
   * Gets extension for a given filename
   *
   * @param {string} fileName
   * @returns {string} Extracted extension
   */

getTypesForGroup

  /**
   * Gets list of mimetypes for a group
   *
   * @param {string} groupLabel
   * @returns {array}
  */

hasPreview

  /**
   * Checks if file type is considered previewable
   *
   * @param {mimetypeParams} mimetypeParams MIME type parameters
   * @returns {boolean}
  */

typeExists

  /**
   * Checks if type exists
   *
   * @param {mimetypeParams} mimetypeParams MIME type parameters
   * @returns {boolean}
  */

getValidTypes

  /**
   * Gets list of types for all groups
   *
   * @returns {array}
  */

License

This repository is published under the MIT license.

Readme

Keywords

Package Sidebar

Install

npm i @contentful/mimetype

Weekly Downloads

9,716

Version

2.3.0

License

MIT

Unpacked Size

93.3 kB

Total Files

14

Last publish

Collaborators

  • eozelius
  • fisher-contentful
  • jonathanstoye
  • trburgess
  • 2wce
  • tnugmanov-contentful
  • primeinteger
  • david-shibley-contentful
  • jjolton_contentful
  • nealdavies
  • dkim-cf
  • t-col
  • chasepoirier
  • ryunsong-contentful
  • elylucas
  • fidanism
  • jsdalton
  • lewiscowper
  • rafafelix0
  • felixboenke
  • lillianbitner
  • mateojgordo
  • brettjackson
  • brnrossi
  • julija.a
  • doetter
  • jose.medrano
  • jonathan-contentful
  • georgechios.contentful
  • inbal.gordon
  • anwar.ahmad
  • ghepting
  • camposcontentful
  • benjaminrobertlees
  • whitelisab
  • mgoudy_contentful
  • marcopieatcontentful
  • jbcontentful
  • floriank
  • pkeavenycontentful
  • msieroslawska
  • miguelcrespo
  • chrishelgert
  • cdun.ctfl
  • asleepysamurai
  • budimir.budimir.cf
  • seth-carter-contentful
  • bhekanik
  • konstantinminster
  • invalid_json
  • douglasnsovenhi
  • dropecostareis
  • lorenzonibrunno
  • baskiers
  • dancontentful
  • ivo-contentful
  • thy.pham
  • adrian-contentful
  • alvinometric
  • dimitrycf
  • cormac.debarra
  • jites
  • nhanlon-cf
  • cbentham-cf
  • cempesket
  • jfctfl
  • nkoyo.ating
  • evgeniip
  • max.cheremisin
  • sofia_margariti
  • dineshswamy_paranthaman
  • dmytro.filippov
  • arjun-londhey
  • eric-miller2129
  • liamstokingercontentful
  • aodhagan-cf
  • vikaskumr
  • dennise917
  • alicankargin
  • cf-aleks
  • bvkr
  • ebctfl
  • sjouli
  • mayakarabula
  • cf-engit
  • harshil1712
  • paradoja
  • mattvanvoorst-contentful
  • holgerstorm
  • cf-remylenoir
  • mayagillilan
  • ahsen
  • mar.contentful
  • rowadz_contentful
  • kiyutink_contentful
  • roosterhack
  • kurtulus-contentful
  • omasopust-cf
  • cemre.yuksel
  • peacemukke
  • sophiiistika
  • stephanleece
  • dogukano
  • 3b3ziz
  • or_yoffe_contentful
  • hennadii.shymanskyi
  • m.bensalem
  • sxagoraris
  • stathis.xagoraris
  • andreascful
  • richard_moran
  • yvesrijckaert_contentful
  • mehdi_contentful
  • georgpanok
  • riqwan.thahamir
  • piotr.ciazynski
  • farruco.sanjurjo
  • ronaldronson
  • silhoue
  • phbschmidt
  • kathrinholzmann
  • poberherr
  • mikita.savanovich
  • laurenceb
  • elblivion
  • fabianheymann
  • it-internal
  • sbezludny
  • medturki
  • danwe
  • yann-cf
  • makinwa37
  • diacono
  • whydah-gally
  • tauraz
  • cakejelly
  • martin3walker
  • argvk_cf
  • yiotis
  • leonardofreitass
  • hwartig
  • davidfateh
  • dvasylenko
  • ruderngespra
  • mshaaban0
  • kdamball
  • marcolink
  • gosiaszporer
  • z0al
  • mspagnolo
  • thomas.spiesser
  • anho
  • didi96
  • fs
  • cgrabo
  • dana_grn
  • andipaetzold-cf
  • denkristoffer
  • luizfonseca
  • juliabiro
  • vinz93
  • jbourne
  • 0mathcrap
  • damienxy
  • roryscarson
  • m99coder-cf
  • loweisz
  • thomas.contentful
  • marceltoben
  • massao
  • bohdan.hutsol
  • contentful-ecosystem
  • vida.momenzadeh
  • yuri.mazursky
  • rebecca.koenig
  • annmary