@coolio/http
Version:
HTTP networking client
12 lines • 852 B
JavaScript
import { Buffer } from 'buffer';
export const getEncodingFromHeaders = (headers, 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(element => element.trim().startsWith('charset'))) === null || _c === void 0 ? void 0 : _c.split('=')[1]) !== null && _d !== void 0 ? _d : fallback).trim().toLowerCase();
};
export const encodeArrayBuffer = (data = '', encoding = 'utf8') => typeof data === 'string'
? new Uint8Array(Buffer.from(data, encoding))
: new Uint8Array(Buffer.from(data));
export const encodeText = (buffer, encoding = 'utf8') => {
return Buffer.from(buffer).toString(encoding);
};
//# sourceMappingURL=encoder.helper.js.map