Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
const got = require('got');
const isURL = require('is-url');
const binaryExtensions = require('binary-extensions');
const isHTML = require('is-html');
const cheerio = require('cheerio');
const jschardet = require('jschardet');
const iconv = require('iconv-lite');
const binaries = new RegExp(`(${binaryExtensions.map(ext => `.${ext}`).join('|')})$`);
const getBody = response => {
const headers = response.headers || {};
const body = response.body || '';
const contentType = headers['content-type'] || '';
const matches = contentType.match(/charset=(?.+)/);
if (matches !== null) {
return iconv.decode(body, matches[1]);
}
const result = jschardet.detect(body);
if (result && result.encoding && (result.confidence || 0) >= 0.99) {
return iconv.decode(body, result.encoding);
}