text: "use strict";function _interopDefault(a){return a&&"object"==typeof a&&"default"in a?a.default:a}Object.defineProperty(exports,"__esModule",{value:!0});var monkeypatch=_interopDefault(require("monkeypatch")),http=_interopDefault(require("http")),https=_interopDefault(require("https"));require("buffer");var chalk=_interopDefault(require("chalk"));function generateMethod(a){const b=a.method;if(!b)return"";const c={GET:"-X GET",POST:"-X POST",PUT:"-X PUT",PATCH:"-X PATCH",DELETE:"-X DELETE"}[b.toUpperCase()];return c||""}function generateHeader(a){const b=a.headers;let c=!1;if(!b)return"";let d="";return Object.keys(b).map((a)=>{"content-length"!==a.toLocaleLowerCase()&&(d+=`-H "${a}: ${b[a].replace(/(\\|")/g,"\\$1")}" `),"accept-encoding"===a.toLocaleLowerCase()&&(c=!0)}),{params:d.trim(),isEncode:c}}function generateUrl(a={}){if(!a)return"";const{protocol:b="http:",hostname:c="localhost",pathname:d="/",search:f=""}=a;return`"${b}//${c}${d}${f}"`}function generateBody(a){return a?`--data-binary ${JSON.stringify(a)}`:""}function generateCompress(a){return a?"--compressed":""}function curlGenerator(b,c="",d){let e="curl ";const f=generateHeader(b),g=generateUrl(b);if(d){let a=d;if(Array.isArray(d)||(a=[d]),0===a.filter((a)=>g.match(a)).length)return""}return e+=g+" ",e+=generateMethod(b)+" ",e+=f.params+" ",e+=generateBody(c)+" ",e+=generateCompress(f.isEncode)}function requestPatch(b,d,e,f,g){const h=[],a=d(e,f);return monkeypatch(a,"write",(a,b,c,d)=>(h.push(b),a(b,c,d))),monkeypatch(a,"end",(a,d,f,c)=>{let i="";("function"==typeof d?d():d)&&h.push(d),0<h.length&&(i=Buffer.concat(h).toString());const j=curlGenerator(e,i,b);return console.log(`${chalk.black.bgYellow.bold(" http-to-curl ")}\n    ${j}\n    `),g(j),a(d,f,c)}),a}function httpToCurl(a){monkeyPatchHttp(http,a),monkeyPatchHttp(https,a)}function monkeyPatchHttp(a,b={filter:"",customCallback:()=>{}}){monkeypatch(a,"request",(c,d,e)=>{const{filter:f,customCallback:g}=b;return requestPatch(f,c,d,e,g)})}exports.generateMethod=generateMethod,exports.generateHeader=generateHeader,exports.generateUrl=generateUrl,exports.generateBody=generateBody,exports.generateCompress=generateCompress,exports.curlGenerator=curlGenerator,exports.requestPatch=requestPatch,exports.default=httpToCurl;
  