Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

http-to-curl

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-to-curl - npm Package Compare versions

Comparing version 1.2.5 to 1.3.0

2

lib/bundle.js

@@ -1,1 +0,1 @@

"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"));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]}" `),"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="/"}=a;return`"${b}//${c}${d}"`}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),console.log(`${chalk.black.bgYellow.bold(" http-to-curl ")}\n ${e}\n `),e}function requestPatch(b,c,d,e){const f=[],g=c(d,e);return monkeypatch(g,"write",(a,b,c,d)=>(f.push(b),a(b,c,d))),monkeypatch(g,"end",(e,g,h,a)=>{let c="";return g&&f.push(g),0<f.length&&(c=Buffer.concat(f).toString()),curlGenerator(d,c,b),e(g,h,a)}),g}function httpToCurl(a=""){monkeypatch(http,"request",(b,c,d)=>requestPatch(a,b,c,d))}exports.generateMethod=generateMethod,exports.generateHeader=generateHeader,exports.generateUrl=generateUrl,exports.generateBody=generateBody,exports.generateCompress=generateCompress,exports.curlGenerator=curlGenerator,exports.requestPatch=requestPatch,exports.default=httpToCurl;
"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"));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="/"}=a;return`"${b}//${c}${d}"`}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),console.log(`${chalk.black.bgYellow.bold(" http-to-curl ")}\n ${e}\n `),e}function requestPatch(b,c,d,e){const f=[],g=c(d,e);return monkeypatch(g,"write",(a,b,c,d)=>(f.push(b),a(b,c,d))),monkeypatch(g,"end",(e,g,h,a)=>{let c="";return g&&f.push(g),0<f.length&&(c=Buffer.concat(f).toString()),curlGenerator(d,c,b),e(g,h,a)}),g}function httpToCurl(a=""){monkeypatch(http,"request",(b,c,d)=>requestPatch(a,b,c,d))}exports.generateMethod=generateMethod,exports.generateHeader=generateHeader,exports.generateUrl=generateUrl,exports.generateBody=generateBody,exports.generateCompress=generateCompress,exports.curlGenerator=curlGenerator,exports.requestPatch=requestPatch,exports.default=httpToCurl;
{
"name": "http-to-curl",
"version": "1.2.5",
"version": "1.3.0",
"description": "Convert node HTTP request to curl",

@@ -5,0 +5,0 @@ "main": "lib/bundle.js",

@@ -5,2 +5,3 @@

![Depedencies](https://david-dm.org/drgx/http-to-curl.svg)
# Node js HTTP request to cURL

@@ -24,2 +25,3 @@

httpToCurl();
// Traditional way

@@ -57,2 +59,2 @@ const httpToCurl = require('http-to-curl').default;

## Contributing
We'd ❤️ to have your helping hand on http-to-curl! Feel free to PR's, add issues or give feedback! Happy Hacking!! 😎
We'd ❤️ to have your helping hand on http-to-curl! Feel free to PR's, add issues or give feedback! Happy Hacking!! 😎
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc