【逐日一包0028】cache-content-type,mime-types

[github地点:https://github.com/ABCDdouyae…]

cache-content-type(koa2源码依靠)

http相应头部工具包, 基于mime-types包,对效果进行了缓存

const getType = require('cache-content-type');

const contentType = getType('html');

console.log(contentType);//text/html; charset=utf-8

mime-types

mime.lookup(path)
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(type) 猎取完成的头部
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(type) 猎取范例的默许扩展名
mime.extension('application/octet-stream') // 'bin'
mime.charset(type) 猎取默许字符编码
mime.charset('text/markdown') // 'UTF-8'
    原文作者:王炜
    原文地址: https://segmentfault.com/a/1190000017313501
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞