{"library":"media-typer","title":"RFC 6838 Media Type Parser and Formatter","description":"media-typer is a focused JavaScript utility designed for strictly parsing and formatting media types according to RFC 6838. It enables developers to deconstruct media type strings (e.g., \"image/svg+xml\") into their `type`, `subtype`, and optional `suffix` components, and conversely, to construct canonical media type strings from these parts. A key differentiator of this package is its explicit design choice to *not* handle media type parameters (such as `charset=utf-8`) or to parse full HTTP `Content-Type` headers, directing users to the `content-type` module for such broader parsing needs. The current stable version is 1.1.0. While releases are infrequent, this indicates a mature, stable, and narrowly scoped utility that receives updates primarily for maintenance or minor feature enhancements like the `test()` function.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install media-typer"],"cli":null},"imports":["const typer = require('media-typer')","const typer = require('media-typer');\nconst parsed = typer.parse('image/jpeg');","const typer = require('media-typer');\nconst formatted = typer.format({ type: 'text', subtype: 'html' });"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const typer = require('media-typer');\n\n// 1. Parsing a media type string into its components\nconst parsedType = typer.parse('application/vnd.apple.mpegurl+json');\nconsole.log('Parsed Type:', parsedType); // { type: 'application', subtype: 'vnd.apple.mpegurl', suffix: 'json' }\n\n// 2. Formatting an object of components back into a media type string\nconst formattedType = typer.format({ type: 'text', subtype: 'html', suffix: null });\nconsole.log('Formatted Type:', formattedType); // text/html\n\n// 3. Validating a media type string\nconst isValid1 = typer.test('audio/ogg');\nconsole.log('Is \"audio/ogg\" valid?', isValid1); // true\n\nconst isValid2 = typer.test('invalid-type');\nconsole.log('Is \"invalid-type\" valid?', isValid2); // false\n\n// 4. Demonstrating normalization (parse then format)\nconst normalizedType = typer.format(typer.parse('IMAGE/JPEG'));\nconsole.log('Normalized \"IMAGE/JPEG\":', normalizedType); // image/jpeg\n\n// 5. Important: This module does NOT handle media type parameters (e.g., charset=utf-8)\n// Attempting to parse with parameters will throw an error.\ntry {\n  typer.parse('text/plain; charset=utf-8');\n} catch (e) {\n  console.warn('As expected, parsing with parameters throws:', e.message);\n}","lang":"javascript","description":"This quickstart demonstrates how to parse, format, and validate media type strings, showcasing the core API and clarifying its scope regarding media type parameters.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}