Socket
Socket
Sign inDemoInstall

axios-curlirize

Package Overview
Dependencies
0
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.5 to 1.3.6

codecov.yml

5

dist/curlirize.js

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

"use strict";
'use strict';

@@ -7,5 +7,4 @@ Object.defineProperty(exports, "__esModule", {

var _CurlHelper = require("./lib/CurlHelper");
var _CurlHelper = require('./lib/CurlHelper');
// thanks to https://github.com/uyu423
function defaultLogCallback(curlResult, err) {

@@ -12,0 +11,0 @@ var command = curlResult.command;

15

dist/lib/CurlHelper.js

@@ -53,3 +53,5 @@ "use strict";

value: function getBody() {
if (typeof this.request.data !== "undefined" && this.request.data !== "" && Object.keys(this.request.data).length && this.request.method.toUpperCase() !== "GET") {
if (typeof this.request.data !== "undefined" && this.request.data !== "" && this.request.data !== null &&
//Object.keys(this.request.data).length &&
this.request.method.toUpperCase() !== "GET") {
var data = _typeof(this.request.data) === "object" || Object.prototype.toString.call(this.request.data) === "[object Array]" ? JSON.stringify(this.request.data) : this.request.data;

@@ -64,2 +66,5 @@ return ("--data '" + data + "'").trim();

value: function getUrl() {
if (this.request.baseURL) {
return this.request.baseURL + "/" + this.request.url;
}
return this.request.url;

@@ -74,7 +79,3 @@ }

for (var param in this.request.params) {
if (i != 0) {
params += "&" + param + "=" + this.request.params[param];
} else {
params = "?" + param + "=" + this.request.params[param];
}
params += i != 0 ? "&" + param + "=" + this.request.params[param] : "?" + param + "=" + this.request.params[param];
i++;

@@ -91,3 +92,3 @@ }

if (this.getQueryString() != "") {
url = url.charAt(url.length - 1) == '/' ? url.substr(0, url.length - 1) : url;
url = url.charAt(url.length - 1) == "/" ? url.substr(0, url.length - 1) : url;
url += this.getQueryString();

@@ -94,0 +95,0 @@ }

@@ -65,3 +65,3 @@ 'use strict';

it('should return the generated command with headers specified on method call', function (done) {
_axios2.default.post('http://localhost:7500/', {}, { headers: { Authorization: 'Bearer 123', testHeader: 'Testing' } }).then(function (res) {
_axios2.default.post('http://localhost:7500/', null, { headers: { Authorization: 'Bearer 123', testHeader: 'Testing' } }).then(function (res) {
(0, _expect2.default)(res.config.curlCommand).toBeDefined();

@@ -76,3 +76,3 @@ (0, _expect2.default)(res.config.curlCommand).toBe('curl -X POST -H \"Content-Type:application/x-www-form-urlencoded\" -H \"Authorization:Bearer 123\" -H \"testHeader:Testing\" "http://localhost:7500/"');

it('should return the generated command with a queryString specified in the URL', function (done) {
_axios2.default.post('http://localhost:7500/', {}, { params: { test: 1 } }).then(function (res) {
_axios2.default.post('http://localhost:7500/', null, { params: { test: 1 } }).then(function (res) {
(0, _expect2.default)(res.config.curlCommand).toBeDefined();

@@ -169,3 +169,3 @@ (0, _expect2.default)(res.config.curlCommand).toBe('curl -X POST -H \"Content-Type:application/x-www-form-urlencoded\" "http://localhost:7500?test=1"');

it('should return an empty string if data is == {}', function (done) {
it('should return {} as --data if req data is == {}', function (done) {
var emptyConfig = {

@@ -194,3 +194,3 @@ adapter: function adapter() {

var emptyDataCurl = new _CurlHelper.CurlHelper(emptyConfig);
(0, _expect2.default)(emptyDataCurl.getBody()).toBe('');
(0, _expect2.default)(emptyDataCurl.getBody()).toBe("--data '{}'");
done();

@@ -197,0 +197,0 @@ });

{
"name": "axios-curlirize",
"version": "1.3.5",
"version": "1.3.6",
"description": "Axios third-party module to print all axios requests as curl commands in the console. This repository is forked from axios-curlirize <https://www.npmjs.com/package/axios-curlirize> and supports use with Node JS without having to enable ES6 imports. This repo was inspired by an issue <https://github.com/delirius325/axios-curlirize/issues/20> raised on the origional repository <https://github.com/delirius325/axios-curlirize>. Special thanks to Anthony Gauthier <https://github.com/delirius325>, the author of axios-curlirize",

@@ -5,0 +5,0 @@ "main": "index.js",

import { CurlHelper } from './lib/CurlHelper';
// thanks to https://github.com/uyu423
function defaultLogCallback(curlResult, err) {

@@ -5,0 +4,0 @@ const { command } = curlResult;

@@ -42,3 +42,3 @@ export class CurlHelper {

this.request.data !== "" &&
Object.keys(this.request.data).length &&
this.request.data !== null &&
this.request.method.toUpperCase() !== "GET"

@@ -61,3 +61,3 @@ ) {

}
return this.request.url
return this.request.url;
}

@@ -70,7 +70,6 @@

for (let param in this.request.params) {
if (i != 0) {
params += `&${param}=${this.request.params[param]}`;
} else {
params = `?${param}=${this.request.params[param]}`;
}
params +=
i != 0
? `&${param}=${this.request.params[param]}`
: `?${param}=${this.request.params[param]}`;
i++;

@@ -86,3 +85,3 @@ }

if (this.getQueryString() != "") {
url = (url.charAt(url.length - 1) == '/') ? url.substr(0, url.length - 1) : url;
url = url.charAt(url.length - 1) == "/" ? url.substr(0, url.length - 1) : url;
url += this.getQueryString();

@@ -89,0 +88,0 @@ }

@@ -60,3 +60,3 @@ import expect from 'expect';

it('should return the generated command with headers specified on method call', done => {
axios.post('http://localhost:7500/', {}, {headers: {Authorization: 'Bearer 123', testHeader: 'Testing'}})
axios.post('http://localhost:7500/', null, {headers: {Authorization: 'Bearer 123', testHeader: 'Testing'}})
.then(res => {

@@ -73,3 +73,3 @@ expect(res.config.curlCommand).toBeDefined();

it('should return the generated command with a queryString specified in the URL', done => {
axios.post('http://localhost:7500/', {}, {params: {test: 1}})
axios.post('http://localhost:7500/', null, {params: {test: 1}})
.then(res => {

@@ -144,3 +144,3 @@ expect(res.config.curlCommand).toBeDefined();

it('should return an empty string if data is == {}', done => {
it('should return {} as --data if req data is == {}', done => {
let emptyConfig = {

@@ -161,3 +161,3 @@ adapter: () => { return 'dummy' },

const emptyDataCurl = new CurlHelper(emptyConfig);
expect(emptyDataCurl.getBody()).toBe('');
expect(emptyDataCurl.getBody()).toBe("--data '{}'");
done();

@@ -164,0 +164,0 @@ });

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc