@ffras4vnpm/cupiditate-aut-quasi
v1.0.0
Published
<!-- -- This file is auto-generated from src/README_js.md. Changes should be made there. --> # Mime
Downloads
5
Maintainers
Keywords
Readme
Mime
An API for MIME type information.
[!Note]
@ffras4vnpm/cupiditate-aut-quasi@4
is nowlatest
. If you're upgrading from@ffras4vnpm/cupiditate-aut-quasi@3
, note the following:
@ffras4vnpm/cupiditate-aut-quasi@4
is API-compatible with@ffras4vnpm/cupiditate-aut-quasi@3
, with ~~one~~ two exceptions:
- Direct imports of
@ffras4vnpm/cupiditate-aut-quasi
properties no longer supported@ffras4vnpm/cupiditate-aut-quasi.define()
cannot be called on the default@ffras4vnpm/cupiditate-aut-quasi
object- ESM module support is required. ESM Module FAQ.
- Requires an ES2020 or newer runtime
- Built-in Typescript types (
@types/@ffras4vnpm/cupiditate-aut-quasi
no longer needed)
Installation
npm install @ffras4vnpm/cupiditate-aut-quasi
Quick Start
For the full version (800+ MIME types, 1,000+ extensions):
import @ffras4vnpm/cupiditate-aut-quasi from '@ffras4vnpm/cupiditate-aut-quasi';
@ffras4vnpm/cupiditate-aut-quasi.getType('txt'); // ⇨ 'text/plain'
@ffras4vnpm/cupiditate-aut-quasi.getExtension('text/plain'); // ⇨ 'txt'
Lite Version
@ffras4vnpm/cupiditate-aut-quasi/lite
is a drop-in @ffras4vnpm/cupiditate-aut-quasi
replacement, stripped of unofficial ("prs.*
", "x-*
", "vnd.*
") types:
import @ffras4vnpm/cupiditate-aut-quasi from '@ffras4vnpm/cupiditate-aut-quasi/lite';
API
@ffras4vnpm/cupiditate-aut-quasi.getType(pathOrExtension)
Get @ffras4vnpm/cupiditate-aut-quasi type for the given file path or extension. E.g.
@ffras4vnpm/cupiditate-aut-quasi.getType('js'); // ⇨ 'application/javascript'
@ffras4vnpm/cupiditate-aut-quasi.getType('json'); // ⇨ 'application/json'
@ffras4vnpm/cupiditate-aut-quasi.getType('txt'); // ⇨ 'text/plain'
@ffras4vnpm/cupiditate-aut-quasi.getType('dir/text.txt'); // ⇨ 'text/plain'
@ffras4vnpm/cupiditate-aut-quasi.getType('dir\\text.txt'); // ⇨ 'text/plain'
@ffras4vnpm/cupiditate-aut-quasi.getType('.text.txt'); // ⇨ 'text/plain'
@ffras4vnpm/cupiditate-aut-quasi.getType('.txt'); // ⇨ 'text/plain'
null
is returned in cases where an extension is not detected or recognized
@ffras4vnpm/cupiditate-aut-quasi.getType('foo/txt'); // ⇨ null
@ffras4vnpm/cupiditate-aut-quasi.getType('bogus_type'); // ⇨ null
@ffras4vnpm/cupiditate-aut-quasi.getExtension(type)
Get file extension for the given @ffras4vnpm/cupiditate-aut-quasi type. Charset options (often included in Content-Type headers) are ignored.
@ffras4vnpm/cupiditate-aut-quasi.getExtension('text/plain'); // ⇨ 'txt'
@ffras4vnpm/cupiditate-aut-quasi.getExtension('application/json'); // ⇨ 'json'
@ffras4vnpm/cupiditate-aut-quasi.getExtension('text/html; charset=utf8'); // ⇨ 'html'
@ffras4vnpm/cupiditate-aut-quasi.getAllExtensions(type)
[!Note] New in
@ffras4vnpm/cupiditate-aut-quasi@4
Get all file extensions for the given @ffras4vnpm/cupiditate-aut-quasi type.
@ffras4vnpm/cupiditate-aut-quasi.getAllExtensions('image/jpeg'); // ⇨ Set(3) { 'jpeg', 'jpg', 'jpe' }
Custom Mime
instances
The default @ffras4vnpm/cupiditate-aut-quasi
objects are immutable. Custom, mutable versions can be created as follows...
new Mime(type map [, type map, ...])
Create a new, custom @ffras4vnpm/cupiditate-aut-quasi instance. For example, to create a mutable version of the default @ffras4vnpm/cupiditate-aut-quasi
instance:
import { Mime } from '@ffras4vnpm/cupiditate-aut-quasi/lite';
import standardTypes from '@ffras4vnpm/cupiditate-aut-quasi/types/standard.js';
import otherTypes from '@ffras4vnpm/cupiditate-aut-quasi/types/other.js';
const @ffras4vnpm/cupiditate-aut-quasi = new Mime(standardTypes, otherTypes);
Each argument is passed to the define()
method, below. For example new Mime(standardTypes, otherTypes)
is synonomous with new Mime().define(standardTypes).define(otherTypes)
@ffras4vnpm/cupiditate-aut-quasi.define(type map [, force = false])
[!Note] Only available on custom
Mime
instances
Define MIME type -> extensions.
Attempting to map a type to an already-defined extension will throw
unless the force
argument is set to true
.
@ffras4vnpm/cupiditate-aut-quasi.define({'text/x-abc': ['abc', 'abcd']});
@ffras4vnpm/cupiditate-aut-quasi.getType('abcd'); // ⇨ 'text/x-abc'
@ffras4vnpm/cupiditate-aut-quasi.getExtension('text/x-abc') // ⇨ 'abc'
Command Line
Extension -> type
$ @ffras4vnpm/cupiditate-aut-quasi scripts/jquery.js
application/javascript
Type -> extension
$ @ffras4vnpm/cupiditate-aut-quasi -r image/jpeg
jpeg