Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/mimePublic
forked frombroofa/mime

Mime types for JavaScript

License

NotificationsYou must be signed in to change notification settings

brev/mime

 
 

Repository files navigation

NPM downloadsMime CI

An API for MIME type information.

  • Allmime-db types
  • Compact and dependency-freemime's badge
  • Full TS support

Note

mime@4 is nowlatest. If you're upgrading frommime@3, note the following:

  • mime@4 is API-compatible withmime@3, with one exception:mime.define() cannot be called on the defaultmime object.
  • ESM module support is required.ESM Module FAQ.
  • Requires anES2020 or newer runtime
  • Built-in Typescript types (@types/mime no longer needed)

Installation

npm install mime

Quick Start

For the full version (800+ MIME types, 1,000+ extensions):

importmimefrom'mime';mime.getType('txt');// ⇨ 'text/plain'mime.getExtension('text/plain');// ⇨ 'txt'

Lite Versionmime/lite's badge

mime/lite is a drop-inmime replacement, stripped of unofficial ("prs.*", "x-*", "vnd.*") types:

importmimefrom'mime/lite';

API

mime.getType(pathOrExtension)

Get mime type for the given file path or extension. E.g.

mime.getType('js');// ⇨ 'application/javascript'mime.getType('json');// ⇨ 'application/json'mime.getType('txt');// ⇨ 'text/plain'mime.getType('dir/text.txt');// ⇨ 'text/plain'mime.getType('dir\\text.txt');// ⇨ 'text/plain'mime.getType('.text.txt');// ⇨ 'text/plain'mime.getType('.txt');// ⇨ 'text/plain'

null is returned in cases where an extension is not detected or recognized

mime.getType('foo/txt');// ⇨ nullmime.getType('bogus_type');// ⇨ null

mime.getExtension(type)

Get file extension for the given mime type. Charset options (often included in Content-Type headers) are ignored.

mime.getExtension('text/plain');// ⇨ 'txt'mime.getExtension('application/json');// ⇨ 'json'mime.getExtension('text/html; charset=utf8');// ⇨ 'html'

mime.getAllExtensions(type)

Note

New inmime@4

Get all file extensions for the given mime type.

mime.getAllExtensions('image/jpeg');// ⇨ Set(3) { 'jpeg', 'jpg', 'jpe' }

CustomMime instances

The defaultmime objects are immutable. Custom, mutable versions can be created as follows...

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

Create a new, custom mime instance. For example, to create a mutable version of the defaultmime instance:

import{Mime}from'mime/lite';importstandardTypesfrom'mime/types/standard.js';importotherTypesfrom'mime/types/other.js';constmime=newMime(standardTypes,otherTypes);

Each argument is passed to thedefine() method, below. For examplenew Mime(standardTypes, otherTypes) is synonomous withnew Mime().define(standardTypes).define(otherTypes)

mime.define(type map [, force = false])

Note

Only available on customMime instances

Define MIME type -> extensions.

Attempting to map a type to an already-defined extension willthrow unless theforce argument is set totrue.

mime.define({'text/x-abc':['abc','abcd']});mime.getType('abcd');// ⇨ 'text/x-abc'mime.getExtension('text/x-abc')// ⇨ 'abc'

Command Line

Extension -> type

$ mime scripts/jquery.jsapplication/javascript

Type -> extension

$ mime -r image/jpegjpeg

About

Mime types for JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript69.2%
  • JavaScript30.8%

[8]ページ先頭

©2009-2025 Movatter.jp