MCPcopy
hub / github.com/di-sukharev/opencommit / convertBody

Function convertBody

out/cli.cjs:6283–6319  ·  view source on GitHub ↗
(buffer, headers)

Source from the content-addressed store, hash-verified

6281 });
6282 }
6283 function convertBody(buffer, headers) {
6284 if (typeof convert !== "function") {
6285 throw new Error("The package `encoding` must be installed to use the textConverted() function");
6286 }
6287 const ct2 = headers.get("content-type");
6288 let charset = "utf-8";
6289 let res, str2;
6290 if (ct2) {
6291 res = /charset=([^;]*)/i.exec(ct2);
6292 }
6293 str2 = buffer.slice(0, 1024).toString();
6294 if (!res && str2) {
6295 res = /<meta.+?charset=(['"])(.+?)\1/i.exec(str2);
6296 }
6297 if (!res && str2) {
6298 res = /<meta[\s]+?http-equiv=(['"])content-type\1[\s]+?content=(['"])(.+?)\2/i.exec(str2);
6299 if (!res) {
6300 res = /<meta[\s]+?content=(['"])(.+?)\1[\s]+?http-equiv=(['"])content-type\3/i.exec(str2);
6301 if (res) {
6302 res.pop();
6303 }
6304 }
6305 if (res) {
6306 res = /charset=(.*)/i.exec(res.pop());
6307 }
6308 }
6309 if (!res && str2) {
6310 res = /<\?xml.+?encoding=(['"])(.+?)\1/i.exec(str2);
6311 }
6312 if (res) {
6313 charset = res.pop();
6314 if (charset === "gb2312" || charset === "gbk") {
6315 charset = "gb18030";
6316 }
6317 }
6318 return convert(buffer, "UTF-8", charset).toString();
6319 }
6320 function isURLSearchParams2(obj) {
6321 if (typeof obj !== "object" || typeof obj.append !== "function" || typeof obj.delete !== "function" || typeof obj.get !== "function" || typeof obj.getAll !== "function" || typeof obj.has !== "function" || typeof obj.set !== "function") {
6322 return false;

Callers 1

textConvertedFunction · 0.85

Calls 3

getMethod · 0.45
toStringMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…