[github地址:https://github.com/ABCDdouyae...]javascript
http響應頭部工具包, 基於mime-types包,對結果進行了緩存
const getType = require('cache-content-type'); const contentType = getType('html'); console.log(contentType);//text/html; charset=utf-8
mime.lookup('json') // 'application/json' mime.lookup('.md') // 'text/markdown' mime.lookup('file.html') // 'text/html' mime.lookup('folder/file.js') // 'application/javascript' mime.lookup('folder/.htaccess') // false mime.lookup('cats') // false
mime.contentType('markdown') // 'text/x-markdown; charset=utf-8' mime.contentType('file.json') // 'application/json; charset=utf-8' // from a full path mime.contentType(path.extname('/path/to/file.json')) // 'application/json; charset=utf-8'
mime.extension('application/octet-stream') // 'bin'
mime.charset('text/markdown') // 'UTF-8'