Skip to content

Commit 634d6bc

Browse files
author
Manu de Bump
committed
Fix quotes
1 parent 4622cc2 commit 634d6bc

10 files changed

Lines changed: 59 additions & 59 deletions

File tree

dist/curl-generator.cjs.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,28 @@ function rawBodyToString(body) {
1919
return body.content;
2020
}
2121
function rawBodyToCommand(body) {
22-
return "-d \"" + rawBodyToString(body) + "\"";
22+
return "-d '" + rawBodyToString(body) + "'";
2323
}
2424

2525
function isCurlJsonBody(body) {
2626
return typeof body === "object" && body !== null && "type" in body && body.type === "json" && "content" in body;
2727
}
2828
function jsonContentToString(content) {
29-
return JSON.stringify(content).replace(/([\\"])/g, "\\$1");
29+
return JSON.stringify(content).replace(/([\\'])/g, "\\$1");
3030
}
3131
function jsonBodyToString(body) {
3232
return jsonContentToString(body.content);
3333
}
3434
function jsonBodyToCommand(body) {
35-
return "-d \"" + jsonBodyToString(body) + "\"";
35+
return "-d '" + jsonBodyToString(body) + "'";
3636
}
3737

3838
function isCurlFormBody(body) {
3939
return typeof body === "object" && body !== null && "type" in body && body.type === "form" && "content" in body;
4040
}
4141
function formBodyToCommand(body) {
4242
if (body.content instanceof URLSearchParams) {
43-
return "-d \"" + body.content.toString() + "\"";
43+
return "-d '" + body.content.toString() + "'";
4444
}
4545
return Object.entries(body.content)
4646
.map(function (_a) {
@@ -61,10 +61,10 @@ function formBodyToCommand(body) {
6161

6262
function bodyToCommand(body) {
6363
if (typeof body === "string") {
64-
return "-d \"" + body + "\"";
64+
return "-d '" + body + "'";
6565
}
6666
else if (body instanceof URLSearchParams) {
67-
return "-d \"" + body.toString() + "\"";
67+
return "-d '" + body.toString() + "'";
6868
}
6969
else if (isCurlFileBody(body)) {
7070
return fileBodyToCommand(body);
@@ -79,7 +79,7 @@ function bodyToCommand(body) {
7979
return formBodyToCommand(body);
8080
}
8181
else if (typeof body === "object") {
82-
return "-d \"" + jsonContentToString(body) + "\"";
82+
return "-d '" + jsonContentToString(body) + "'";
8383
}
8484
throw new Error("Invalid body type: " + body);
8585
}
@@ -113,7 +113,7 @@ var getCurlHeaders = function (headers) {
113113
var result = "";
114114
if (headers) {
115115
Object.keys(headers).map(function (val) {
116-
result += "" + slash + newLine + " -H \"" + val + ": " + headers[val].replace(/(\\|")/g, "\\$1") + "\"";
116+
result += "" + slash + newLine + " -H '" + val + ": " + headers[val].replace(/(\\|')/g, "\\$1") + "'";
117117
});
118118
}
119119
return result;

dist/curl-generator.esm.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,28 @@ function rawBodyToString(body) {
1515
return body.content;
1616
}
1717
function rawBodyToCommand(body) {
18-
return "-d \"" + rawBodyToString(body) + "\"";
18+
return "-d '" + rawBodyToString(body) + "'";
1919
}
2020

2121
function isCurlJsonBody(body) {
2222
return typeof body === "object" && body !== null && "type" in body && body.type === "json" && "content" in body;
2323
}
2424
function jsonContentToString(content) {
25-
return JSON.stringify(content).replace(/([\\"])/g, "\\$1");
25+
return JSON.stringify(content).replace(/([\\'])/g, "\\$1");
2626
}
2727
function jsonBodyToString(body) {
2828
return jsonContentToString(body.content);
2929
}
3030
function jsonBodyToCommand(body) {
31-
return "-d \"" + jsonBodyToString(body) + "\"";
31+
return "-d '" + jsonBodyToString(body) + "'";
3232
}
3333

3434
function isCurlFormBody(body) {
3535
return typeof body === "object" && body !== null && "type" in body && body.type === "form" && "content" in body;
3636
}
3737
function formBodyToCommand(body) {
3838
if (body.content instanceof URLSearchParams) {
39-
return "-d \"" + body.content.toString() + "\"";
39+
return "-d '" + body.content.toString() + "'";
4040
}
4141
return Object.entries(body.content)
4242
.map(function (_a) {
@@ -57,10 +57,10 @@ function formBodyToCommand(body) {
5757

5858
function bodyToCommand(body) {
5959
if (typeof body === "string") {
60-
return "-d \"" + body + "\"";
60+
return "-d '" + body + "'";
6161
}
6262
else if (body instanceof URLSearchParams) {
63-
return "-d \"" + body.toString() + "\"";
63+
return "-d '" + body.toString() + "'";
6464
}
6565
else if (isCurlFileBody(body)) {
6666
return fileBodyToCommand(body);
@@ -75,7 +75,7 @@ function bodyToCommand(body) {
7575
return formBodyToCommand(body);
7676
}
7777
else if (typeof body === "object") {
78-
return "-d \"" + jsonContentToString(body) + "\"";
78+
return "-d '" + jsonContentToString(body) + "'";
7979
}
8080
throw new Error("Invalid body type: " + body);
8181
}
@@ -109,7 +109,7 @@ var getCurlHeaders = function (headers) {
109109
var result = "";
110110
if (headers) {
111111
Object.keys(headers).map(function (val) {
112-
result += "" + slash + newLine + " -H \"" + val + ": " + headers[val].replace(/(\\|")/g, "\\$1") + "\"";
112+
result += "" + slash + newLine + " -H '" + val + ": " + headers[val].replace(/(\\|')/g, "\\$1") + "'";
113113
});
114114
}
115115
return result;

dist/curl-generator.umd.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,28 @@
2121
return body.content;
2222
}
2323
function rawBodyToCommand(body) {
24-
return "-d \"" + rawBodyToString(body) + "\"";
24+
return "-d '" + rawBodyToString(body) + "'";
2525
}
2626

2727
function isCurlJsonBody(body) {
2828
return typeof body === "object" && body !== null && "type" in body && body.type === "json" && "content" in body;
2929
}
3030
function jsonContentToString(content) {
31-
return JSON.stringify(content).replace(/([\\"])/g, "\\$1");
31+
return JSON.stringify(content).replace(/([\\'])/g, "\\$1");
3232
}
3333
function jsonBodyToString(body) {
3434
return jsonContentToString(body.content);
3535
}
3636
function jsonBodyToCommand(body) {
37-
return "-d \"" + jsonBodyToString(body) + "\"";
37+
return "-d '" + jsonBodyToString(body) + "'";
3838
}
3939

4040
function isCurlFormBody(body) {
4141
return typeof body === "object" && body !== null && "type" in body && body.type === "form" && "content" in body;
4242
}
4343
function formBodyToCommand(body) {
4444
if (body.content instanceof URLSearchParams) {
45-
return "-d \"" + body.content.toString() + "\"";
45+
return "-d '" + body.content.toString() + "'";
4646
}
4747
return Object.entries(body.content)
4848
.map(function (_a) {
@@ -63,10 +63,10 @@
6363

6464
function bodyToCommand(body) {
6565
if (typeof body === "string") {
66-
return "-d \"" + body + "\"";
66+
return "-d '" + body + "'";
6767
}
6868
else if (body instanceof URLSearchParams) {
69-
return "-d \"" + body.toString() + "\"";
69+
return "-d '" + body.toString() + "'";
7070
}
7171
else if (isCurlFileBody(body)) {
7272
return fileBodyToCommand(body);
@@ -81,7 +81,7 @@
8181
return formBodyToCommand(body);
8282
}
8383
else if (typeof body === "object") {
84-
return "-d \"" + jsonContentToString(body) + "\"";
84+
return "-d '" + jsonContentToString(body) + "'";
8585
}
8686
throw new Error("Invalid body type: " + body);
8787
}
@@ -115,7 +115,7 @@
115115
var result = "";
116116
if (headers) {
117117
Object.keys(headers).map(function (val) {
118-
result += "" + slash + newLine + " -H \"" + val + ": " + headers[val].replace(/(\\|")/g, "\\$1") + "\"";
118+
result += "" + slash + newLine + " -H '" + val + ": " + headers[val].replace(/(\\|')/g, "\\$1") + "'";
119119
});
120120
}
121121
return result;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "curl-generator",
33
"author": "albertodeagostini.dev@gmail.com",
4-
"version": "0.4.1",
4+
"version": "0.4.2",
55
"main": "dist/curl-generator.cjs.js",
66
"module": "dist/curl-generator.esm.js",
77
"browser": "dist/curl-generator.umd.js",
@@ -39,4 +39,4 @@
3939
"url": "https://github.com/albertodeago/curl-generator/issues"
4040
},
4141
"homepage": "https://github.com/albertodeago/curl-generator"
42-
}
42+
}

src/bodies/body.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ export function bodyToString(body: CurlBody): string {
3636

3737
export function bodyToCommand(body: CurlBody): string {
3838
if (typeof body === "string") {
39-
return `-d "${body}"`;
39+
return `-d '${body}'`;
4040
} else if (body instanceof URLSearchParams) {
41-
return `-d "${body.toString()}"`;
41+
return `-d '${body.toString()}'`;
4242
} else if (isCurlFileBody(body)) {
4343
return fileBodyToCommand(body);
4444
} else if (isCurlRawBody(body)) {
@@ -48,8 +48,8 @@ export function bodyToCommand(body: CurlBody): string {
4848
} else if (isCurlFormBody(body)) {
4949
return formBodyToCommand(body);
5050
} else if (typeof body === "object") {
51-
return `-d "${jsonContentToString(body)}"`;
51+
return `-d '${jsonContentToString(body)}'`;
5252
}
5353

5454
throw new Error(`Invalid body type: ${body}`);
55-
}
55+
}

src/bodies/form-body.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function isCurlFormBody(body: unknown): body is CurlFormBody {
4444

4545
export function formBodyToCommand(body: CurlFormBody): string {
4646
if (body.content instanceof URLSearchParams) {
47-
return `-d "${body.content.toString()}"`;
47+
return `-d '${body.content.toString()}'`;
4848
}
4949

5050
return Object.entries(body.content)

src/bodies/json-body.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function isCurlJsonBody(body: unknown): body is CurlJsonBody {
1717

1818
export function jsonContentToString(content: Record<string | number | symbol, unknown>): string {
1919
return JSON.stringify(content).replace(
20-
/([\\"])/g,
20+
/([\\'])/g,
2121
"\\$1"
2222
);
2323
}
@@ -27,5 +27,5 @@ export function jsonBodyToString(body: CurlJsonBody): string {
2727
}
2828

2929
export function jsonBodyToCommand(body: CurlJsonBody): string {
30-
return `-d "${jsonBodyToString(body)}"`;
30+
return `-d '${jsonBodyToString(body)}'`;
3131
}

src/bodies/raw-body.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ export function rawBodyToString(body: CurlRawBody): string {
2020
}
2121

2222
export function rawBodyToCommand(body: CurlRawBody): string {
23-
return `-d "${rawBodyToString(body)}"`;
23+
return `-d '${rawBodyToString(body)}'`;
2424
}

src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ const getCurlHeaders = function (headers?: StringMap): string {
8686
let result = "";
8787
if (headers) {
8888
Object.keys(headers).map((val) => {
89-
result += `${slash}${newLine} -H "${val}: ${headers[val].replace(
90-
/(\\|")/g,
89+
result += `${slash}${newLine} -H '${val}: ${headers[val].replace(
90+
/(\\|')/g,
9191
"\\$1"
92-
)}"`;
92+
)}'`;
9393
});
9494
}
9595
return result;

test/__snapshots__/main.test.ts.snap

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,36 @@ exports[`del1 1`] = `
88
exports[`fileBody 1`] = `
99
"curl https://jsonplaceholder.typicode.com/posts \\
1010
-X POST \\
11-
-H "Content-Type: application/json" \\
11+
-H 'Content-Type: application/json' \\
1212
--data-binary @data.json"
1313
`;
1414

1515
exports[`formBody1 1`] = `
1616
"curl https://jsonplaceholder.typicode.com/posts \\
1717
-X POST \\
18-
-H "Content-Type: application/x-www-form-urlencoded" \\
18+
-H 'Content-Type: application/x-www-form-urlencoded' \\
1919
-F name=foo"
2020
`;
2121

2222
exports[`formBody2 1`] = `
2323
"curl https://jsonplaceholder.typicode.com/posts \\
2424
-X POST \\
25-
-H "Content-Type: multipart/form-data" \\
25+
-H 'Content-Type: multipart/form-data' \\
2626
-F file1=@data.json"
2727
`;
2828

2929
exports[`formBody3 1`] = `
3030
"curl https://jsonplaceholder.typicode.com/posts \\
3131
-X POST \\
32-
-H "Content-Type: application/x-www-form-urlencoded" \\
32+
-H 'Content-Type: application/x-www-form-urlencoded' \\
3333
-F file1=string data"
3434
`;
3535

3636
exports[`formBody4 1`] = `
3737
"curl https://jsonplaceholder.typicode.com/posts \\
3838
-X POST \\
39-
-H "Content-Type: application/x-www-form-urlencoded" \\
40-
-d "key1=value+1""
39+
-H 'Content-Type: application/x-www-form-urlencoded' \\
40+
-d 'key1=value+1'"
4141
`;
4242

4343
exports[`get1 1`] = `"curl https://jsonplaceholder.typicode.com/posts/101 \\"`;
@@ -50,20 +50,20 @@ exports[`get2 1`] = `
5050
exports[`getEscapeHeaders 1`] = `
5151
"curl https://jsonplaceholder.typicode.com/todos/1 \\
5252
-X GET \\
53-
-H "key: a \\"strange\\" value""
53+
-H 'key: a "strange" value'"
5454
`;
5555

5656
exports[`getWithHeaders 1`] = `
5757
"curl https://jsonplaceholder.typicode.com/todos/1 \\
5858
-X GET \\
59-
-H "Content-Type: application/json""
59+
-H 'Content-Type: application/json'"
6060
`;
6161

6262
exports[`jsonBody 1`] = `
6363
"curl https://jsonplaceholder.typicode.com/posts \\
6464
-X POST \\
65-
-H "Content-Type: application/json" \\
66-
-d "{\\"name\\":\\"foo\\"}""
65+
-H 'Content-Type: application/json' \\
66+
-d '{"name":"foo"}'"
6767
`;
6868

6969
exports[`opt1 1`] = `
@@ -81,41 +81,41 @@ exports[`opt2 1`] = `
8181
exports[`patch1 1`] = `
8282
"curl https://jsonplaceholder.typicode.com/posts/1 \\
8383
-X PATCH \\
84-
-H "Content-type: application/json; charset=UTF-8" \\
85-
-d "{\\"title\\":\\"foo patched\\"}""
84+
-H 'Content-type: application/json; charset=UTF-8' \\
85+
-d '{"title":"foo patched"}'"
8686
`;
8787

8888
exports[`post1 1`] = `
8989
"curl https://jsonplaceholder.typicode.com/posts \\
9090
-X POST \\
91-
-H "Content-type: application/json; charset=UTF-8" \\
92-
-d "{\\"id\\":\\"123-456-789\\",\\"key1\\":\\"value 1\\",\\"key2\\":\\"a \\\\\\"complex\\\\\\" value\\"}""
91+
-H 'Content-type: application/json; charset=UTF-8' \\
92+
-d '{"id":"123-456-789","key1":"value 1","key2":"a \\\\"complex\\\\" value"}'"
9393
`;
9494

9595
exports[`put1 1`] = `
9696
"curl https://jsonplaceholder.typicode.com/posts/1 \\
9797
-X PUT \\
98-
-H "Content-type: application/json; charset=UTF-8" \\
99-
-d "{\\"id\\":1,\\"title\\":\\"foo\\",\\"body\\":\\"barzzz\\",\\"userId\\":1}""
98+
-H 'Content-type: application/json; charset=UTF-8' \\
99+
-d '{"id":1,"title":"foo","body":"barzzz","userId":1}'"
100100
`;
101101

102102
exports[`rawBody1 1`] = `
103103
"curl https://jsonplaceholder.typicode.com/posts \\
104104
-X POST \\
105-
-H "Content-Type: text/plain" \\
106-
-d "string data""
105+
-H 'Content-Type: text/plain' \\
106+
-d 'string data'"
107107
`;
108108

109109
exports[`rawBody2 1`] = `
110110
"curl https://jsonplaceholder.typicode.com/posts \\
111111
-X POST \\
112-
-H "Content-Type: text/plain" \\
113-
-d "string data""
112+
-H 'Content-Type: text/plain' \\
113+
-d 'string data'"
114114
`;
115115

116116
exports[`searchParamsBody 1`] = `
117117
"curl https://jsonplaceholder.typicode.com/posts \\
118118
-X POST \\
119-
-H "Content-Type: text/plain" \\
120-
-d "key1=value+1""
119+
-H 'Content-Type: text/plain' \\
120+
-d 'key1=value+1'"
121121
`;

0 commit comments

Comments
 (0)