@firanorg/impedit-mollitia-sint

2.4.30 • Public • Published

Mime

NPM downloads Mime CI

An API for MIME type information.

  • All @firanorg/impedit-mollitia-sint-db types
  • Compact and dependency-free @firanorg/impedit-mollitia-sint's badge
  • Full TS support

[!Note] @firanorg/impedit-mollitia-sint@4 is now latest. 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, with one two 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)

Installation

npm install @firanorg/impedit-mollitia-sint

Quick Start

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'

Lite Version @firanorg/impedit-mollitia-sint/lite's badge

@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';

API

@firanorg/impedit-mollitia-sint.getType(pathOrExtension)

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

@firanorg/impedit-mollitia-sint.getExtension(type)

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'

@firanorg/impedit-mollitia-sint.getAllExtensions(type)

[!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' }

Custom Mime instances

The default @firanorg/impedit-mollitia-sint objects are immutable. Custom, mutable versions can be created as follows...

new Mime(type map [, type map, ...])

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)

@firanorg/impedit-mollitia-sint.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.

@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'

Command Line

Extension -> type

$ @firanorg/impedit-mollitia-sint scripts/jquery.js
application/javascript

Type -> extension

$ @firanorg/impedit-mollitia-sint -r image/jpeg
jpeg

Readme

Keywords

Package Sidebar

Install

npm i @firanorg/impedit-mollitia-sint

Weekly Downloads

299

Version

2.4.30

License

MIT

Unpacked Size

41 kB

Total Files

77

Last publish

Collaborators

  • firanroundta