An API for MIME type information.
[!Note]
@firanorg/impedit-mollitia-sint@4
is nowlatest
. If you're upgrading from@firanorg/impedit-mollitia-sint@3
, note the following:
@firanorg/impedit-mollitia-sint@4
is API-compatible with@firanorg/impedit-mollitia-sint@3
, withonetwo exceptions:
- Direct imports of
@firanorg/impedit-mollitia-sint
properties no longer supported@firanorg/impedit-mollitia-sint.define()
cannot be called on the default@firanorg/impedit-mollitia-sint
object- ESM module support is required. ESM Module FAQ.
- Requires an ES2020 or newer runtime
- Built-in Typescript types (
@types/@firanorg/impedit-mollitia-sint
no longer needed)
npm install @firanorg/impedit-mollitia-sint
For the full version (800+ MIME types, 1,000+ extensions):
import @firanorg/impedit-mollitia-sint from '@firanorg/impedit-mollitia-sint';
@firanorg/impedit-mollitia-sint.getType('txt'); // ⇨ 'text/plain'
@firanorg/impedit-mollitia-sint.getExtension('text/plain'); // ⇨ 'txt'
@firanorg/impedit-mollitia-sint/lite
is a drop-in @firanorg/impedit-mollitia-sint
replacement, stripped of unofficial ("prs.*
", "x-*
", "vnd.*
") types:
import @firanorg/impedit-mollitia-sint from '@firanorg/impedit-mollitia-sint/lite';
Get @firanorg/impedit-mollitia-sint type for the given file path or extension. E.g.
@firanorg/impedit-mollitia-sint.getType('js'); // ⇨ 'application/javascript'
@firanorg/impedit-mollitia-sint.getType('json'); // ⇨ 'application/json'
@firanorg/impedit-mollitia-sint.getType('txt'); // ⇨ 'text/plain'
@firanorg/impedit-mollitia-sint.getType('dir/text.txt'); // ⇨ 'text/plain'
@firanorg/impedit-mollitia-sint.getType('dir\\text.txt'); // ⇨ 'text/plain'
@firanorg/impedit-mollitia-sint.getType('.text.txt'); // ⇨ 'text/plain'
@firanorg/impedit-mollitia-sint.getType('.txt'); // ⇨ 'text/plain'
null
is returned in cases where an extension is not detected or recognized
@firanorg/impedit-mollitia-sint.getType('foo/txt'); // ⇨ null
@firanorg/impedit-mollitia-sint.getType('bogus_type'); // ⇨ null
Get file extension for the given @firanorg/impedit-mollitia-sint type. Charset options (often included in Content-Type headers) are ignored.
@firanorg/impedit-mollitia-sint.getExtension('text/plain'); // ⇨ 'txt'
@firanorg/impedit-mollitia-sint.getExtension('application/json'); // ⇨ 'json'
@firanorg/impedit-mollitia-sint.getExtension('text/html; charset=utf8'); // ⇨ 'html'
[!Note] New in
@firanorg/impedit-mollitia-sint@4
Get all file extensions for the given @firanorg/impedit-mollitia-sint type.
@firanorg/impedit-mollitia-sint.getAllExtensions('image/jpeg'); // ⇨ Set(3) { 'jpeg', 'jpg', 'jpe' }
The default @firanorg/impedit-mollitia-sint
objects are immutable. Custom, mutable versions can be created as follows...
Create a new, custom @firanorg/impedit-mollitia-sint instance. For example, to create a mutable version of the default @firanorg/impedit-mollitia-sint
instance:
import { Mime } from '@firanorg/impedit-mollitia-sint/lite';
import standardTypes from '@firanorg/impedit-mollitia-sint/types/standard.js';
import otherTypes from '@firanorg/impedit-mollitia-sint/types/other.js';
const @firanorg/impedit-mollitia-sint = 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)
[!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
.
@firanorg/impedit-mollitia-sint.define({'text/x-abc': ['abc', 'abcd']});
@firanorg/impedit-mollitia-sint.getType('abcd'); // ⇨ 'text/x-abc'
@firanorg/impedit-mollitia-sint.getExtension('text/x-abc') // ⇨ 'abc'
$ @firanorg/impedit-mollitia-sint scripts/jquery.js
application/javascript
$ @firanorg/impedit-mollitia-sint -r image/jpeg
jpeg