1.1.0 • Published 5 years ago

media-typer v1.1.0

Weekly downloads
16,242,190
License
MIT
Repository
github
Last release
5 years ago

media-typer

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Simple RFC 6838 media type parser.

This module will parse a given media type into it's component parts, like type, subtype, and suffix. A formatter is also provided to put them back together and the two can be combined to normalize media types into a canonical form.

If you are looking to parse the string that represents a media type and it's parameters in HTTP (for example, the Content-Type header), use the content-type module.

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install media-typer

API

var typer = require('media-typer')

typer.parse(string)

var obj = typer.parse('image/svg+xml')

Parse a media type string. This will return an object with the following properties (examples are shown for the string 'image/svg+xml; charset=utf-8'):

  • type: The type of the media type (always lower case). Example: 'image'

  • subtype: The subtype of the media type (always lower case). Example: 'svg'

  • suffix: The suffix of the media type (always lower case). Example: 'xml'

If the given type string is invalid, then a TypeError is thrown.

typer.format(obj)

var obj = typer.format({ type: 'image', subtype: 'svg', suffix: 'xml' })

Format an object into a media type string. This will return a string of the mime type for the given object. For the properties of the object, see the documentation for typer.parse(string).

If any of the given object values are invalid, then a TypeError is thrown.

typer.test(string)

var valid = typer.test('image/svg+xml')

Validate a media type string. This will return true is the string is a well- formatted media type, or false otherwise.

License

MIT

type-isbihua-noderedcomponennenttchinjowwchinjowvuedragdropuploadimagesextensible-node-servernode-red-contrib-fv-cloud-tools@arisageha/react-lazyload@arisageha/react-lazyload-fixranac-bodybb-chat@frxf/frxf@texttree/demo-bsa-reference-rclnode-red-node-alexaanime-randomeni-chat@l1nyanm1ng/react-picture-viewercthpb-plugin-social@fetch-plus/pluginsexpress-easy-staticlinkletlevibestliblevibestlib2levilibtest19levilibtest24levilibtest25levilibtest26levilibtest27levilibtest28levilibtest29nodejs-fileshareunblock-block-save-variableshexa-node-common@infinitebrahmanuniverse/nolb-medilitespeedcclibyarntest@saaspe/componentshyperpass-sdkexpress-api-pack-tropea-bootstraaplizeknushiliyahaotadiesklif-ui-kitsklif-api@everything-registry/sub-chunk-2150@314oner_npm/universal-components-libraryondp149-tablesklif-uidirectus-extension-delete-users-with-filesdecredmg-fury-adapter-swaggerdnr-editordemo02design-system-fitbank-450dgt-nodesdid-medical-record-management-server-linkeasyplayer-mydynamic-ui-practicedynamics-contracts-xemily-webpackdrift-npmvue-dev-clonevue-button-test1evenodd12pckhtml-ipfs-data-attributesnextjs-storiesexpress-filer@cleveradssolutions/cas.cordova.facebookdemopaqdemo-hfgfhgfghghfdemo-jjskkwsidiiwdemo-karryyueyuedfeuk-frontenddfeuk-frontend-manualdigital-keyboard-demoszona-xzijinxml-parser-middlewarequdratic-ui@novembrecom/zxcvbn@podlubnaja/ui-kit@nodulus/shell@shyam-red/node-red@olympfin/olymp-swap-lib@snailcode.net/basic-stathap.io@test-my-node-red/nodes@silver0542/directus-extension-cma-components-editor@sinch/node-red-sinch-utility@plogg/threereact-lightbox-pack-18supportreact-misc-toolbox@shivarajapple/first-libraryreact-form-component-libraryhar-sanitizerreact-ang-notifications-honey-comb-setupgdphpttprogram-editprogram-editor
1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.3.0

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago

0.0.0

10 years ago