在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:broofa/mime开源软件地址:https://github.com/broofa/mime开源编程语言:JavaScript 100.0%开源软件介绍:MimeA comprehensive, compact MIME type module. InstallNPM
BrowserIt is recommended that you use a bundler such as webpack or browserify to package your code. However, browser-ready versions are available via skypack.dev as follows:
Quick StartFor the full version (800+ MIME types, 1,000+ extensions): const mime = require('mime');
mime.getType('txt'); // ⇨ 'text/plain'
mime.getExtension('text/plain'); // ⇨ 'txt' See Mime API below for API details. Lite VersionThe "lite" version of this module omits vendor-specific ( const mime = require('mime/lite'); Mime .vs. mime-types .vs. mime-db modulesFor those of you wondering about the difference between these [popular] NPM modules, here's a brief rundown ...
Mime APIBoth Note: Inputs to this API are case-insensitive. Outputs (returned values) will be lowercase. new Mime(typeMap, ... more maps)Most users of this module will not need to create Mime instances directly. However if you would like to create custom mappings, you may do so as follows ... // Require Mime class
const Mime = require('mime/Mime');
// Define mime type -> extensions map
const typeMap = {
'text/abc': ['abc', 'alpha', 'bet'],
'text/def': ['leppard']
};
// Create and use Mime instance
const myMime = new Mime(typeMap);
myMime.getType('abc'); // ⇨ 'text/abc'
myMime.getExtension('text/def'); // ⇨ 'leppard' If more than one map argument is provided, each map is mime.getType(pathOrExtension)Get mime type for the given 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'
mime.getType('foo/txt'); // ⇨ null
mime.getType('bogus_type'); // ⇨ null mime.getExtension(type)Get 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.define(typeMap[, force = false])Define [more] type mappings.
By default this method will throw an error if you try to map a type to an
extension that is already assigned to another type. Passing mime.define({'text/x-abc': ['abc', 'abcd']});
mime.getType('abcd'); // ⇨ 'text/x-abc'
mime.getExtension('text/x-abc') // ⇨ 'abc' Command Line
E.g.
Markdown generated from src/README_js.md by |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论