html-get
Version:
Get the HTML from any website, fine-tuned for correction & speed
31 lines (22 loc) • 702 B
JavaScript
const { parse } = require('content-type')
const CACHE = Object.create(null)
const parseContentType = contentType =>
typeof contentType === 'string'
? parse(contentType)
: { type: undefined, parameters: {} }
const contentType = headers => {
const contentType = headers['content-type']
return (
CACHE[contentType] || (CACHE[contentType] = parseContentType(contentType))
)
}
const getContentType = headers => contentType(headers).type
const getCharset = headers =>
contentType(headers).parameters.charset?.toLowerCase()
const getContentLength = headers => Number(headers['content-length'])
module.exports = {
getCharset,
getContentLength,
getContentType
}