scraperapi-sdk
Version:
Node.js SDK for ScraperAPI.com
22 lines • 1.11 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var getHeaderValue_1 = __importDefault(require("./getHeaderValue"));
var DEFAULT_ENCODING = 'utf8';
/**
* A function to determine the content charset from the response headers.
*/
function getContentCharset(headers) {
var _a, _b;
var contentType = (0, getHeaderValue_1.default)(headers, 'content-type');
if (typeof contentType !== 'string') {
return DEFAULT_ENCODING;
}
var contentTypeParts = contentType.split(';').map(function (part) { return part.trim(); });
var charsetPart = contentTypeParts.find(function (part) { return part.toLowerCase().startsWith('charset='); });
return (_b = (_a = charsetPart === null || charsetPart === void 0 ? void 0 : charsetPart.split('=')[1]) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : DEFAULT_ENCODING;
}
exports.default = getContentCharset;
//# sourceMappingURL=getContentCharset.js.map
;