mine-type

1.0.0 • Public • Published

mine-type

Nodejs服务端,根据请求地址中的文件后缀获取 Content-Type

Installation

$ npm install mine-type

API

var mineType = require('mine-type')

mineType.getContentType(string)

根据文件后缀名返回对应 Content-Type

var htmlType = mineType.getContentType('html')
var pngType = mineType.getContentType('png')
// htmlType = "text/html"
// pngType = "image/png"

mineType.getFileType(string)

根据Content-Type(不能包含其他参数,比如 "; charset=uft-8")返回文件类型。 返回的数据类型是数组,可能返回多个后缀名,如果没找到则返回空数组

var htmlSuffix = mineType.getFileType('text/html')
var pngSuffix = mineType.getFileType('image/png')
// htmlSuffix = [ 'body', 'htm', 'html' ]
// pngSuffix = [ 'png' ]

License

MIT

Package Sidebar

Install

npm i mine-type

Weekly Downloads

6

Version

1.0.0

License

MIT

Unpacked Size

96.7 kB

Total Files

12

Last publish

Collaborators

  • chaingree