UNPKG

@coolio/http

Version:
20 lines 1.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var buffer_1 = require("buffer"); exports.getEncodingFromHeaders = function (headers, fallback) { if (fallback === void 0) { fallback = 'utf8'; } var _a, _b, _c, _d; return ((_d = (_c = (_b = (_a = headers === null || headers === void 0 ? void 0 : headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')) === null || _b === void 0 ? void 0 : _b.find(function (element) { return element.trim().startsWith('charset'); })) === null || _c === void 0 ? void 0 : _c.split('=')[1]) !== null && _d !== void 0 ? _d : fallback).trim().toLowerCase(); }; exports.encodeArrayBuffer = function (data, encoding) { if (data === void 0) { data = ''; } if (encoding === void 0) { encoding = 'utf8'; } return typeof data === 'string' ? new Uint8Array(buffer_1.Buffer.from(data, encoding)) : new Uint8Array(buffer_1.Buffer.from(data)); }; exports.encodeText = function (buffer, encoding) { if (encoding === void 0) { encoding = 'utf8'; } return buffer_1.Buffer.from(buffer).toString(encoding); }; //# sourceMappingURL=encoder.helper.js.map