@scalar/snippetz 0.7.4 → 0.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/clients/index.js +168 -169
- package/dist/httpsnippet-lite/helpers/code-builder.js +86 -74
- package/dist/httpsnippet-lite/helpers/escape.js +69 -44
- package/dist/httpsnippet-lite/helpers/headers.js +17 -14
- package/dist/httpsnippet-lite/helpers/reducer.js +1 -1
- package/dist/httpsnippet-lite/helpers/shell.js +13 -13
- package/dist/httpsnippet-lite/helpers/snippet-request.js +1 -1
- package/dist/httpsnippet-lite/helpers/url.js +4 -8
- package/dist/httpsnippet-lite/targets/c/libcurl/client.js +69 -67
- package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js +165 -154
- package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js +35 -38
- package/dist/httpsnippet-lite/targets/go/native/client.js +151 -147
- package/dist/httpsnippet-lite/targets/java/asynchttp/client.js +32 -35
- package/dist/httpsnippet-lite/targets/java/nethttp/client.js +40 -39
- package/dist/httpsnippet-lite/targets/java/okhttp/client.js +83 -73
- package/dist/httpsnippet-lite/targets/java/unirest/client.js +41 -34
- package/dist/httpsnippet-lite/targets/javascript/axios/client.js +81 -76
- package/dist/httpsnippet-lite/targets/javascript/jquery/client.js +77 -71
- package/dist/httpsnippet-lite/targets/javascript/xhr/client.js +73 -71
- package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js +83 -73
- package/dist/httpsnippet-lite/targets/node/axios/client.js +74 -69
- package/dist/httpsnippet-lite/targets/objc/helpers.js +52 -33
- package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js +123 -121
- package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js +60 -49
- package/dist/httpsnippet-lite/targets/powershell/common.js +46 -56
- package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js +9 -13
- package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js +9 -13
- package/dist/httpsnippet-lite/targets/python/python3/client.js +85 -68
- package/dist/httpsnippet-lite/targets/r/httr/client.js +114 -95
- package/dist/httpsnippet-lite/targets/ruby/native/client.js +66 -70
- package/dist/httpsnippet-lite/targets/shell/httpie/client.js +121 -107
- package/dist/httpsnippet-lite/targets/shell/wget/client.js +48 -43
- package/dist/httpsnippet-lite/targets/swift/helpers.js +62 -44
- package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js +126 -112
- package/dist/httpsnippet-lite/targets/target.js +1 -1
- package/dist/index.js +2 -9
- package/dist/libs/http.js +68 -56
- package/dist/libs/javascript.js +77 -60
- package/dist/libs/php.js +59 -49
- package/dist/libs/rust.js +60 -33
- package/dist/libs/shell.js +14 -5
- package/dist/plugins/c/libcurl/index.js +1 -5
- package/dist/plugins/c/libcurl/libcurl.js +13 -13
- package/dist/plugins/clojure/clj_http/clj_http.js +13 -13
- package/dist/plugins/clojure/clj_http/index.js +1 -5
- package/dist/plugins/csharp/httpclient/httpclient.js +206 -150
- package/dist/plugins/csharp/httpclient/index.js +1 -5
- package/dist/plugins/csharp/restsharp/index.js +1 -5
- package/dist/plugins/csharp/restsharp/restsharp.js +13 -13
- package/dist/plugins/dart/http/http.js +95 -93
- package/dist/plugins/dart/http/index.js +1 -5
- package/dist/plugins/fsharp/httpclient/httpclient.js +169 -122
- package/dist/plugins/fsharp/httpclient/index.js +1 -5
- package/dist/plugins/go/native/index.js +1 -5
- package/dist/plugins/go/native/native.js +13 -13
- package/dist/plugins/http/http11/http11.d.ts.map +1 -1
- package/dist/plugins/http/http11/http11.js +104 -85
- package/dist/plugins/http/http11/index.js +1 -5
- package/dist/plugins/java/asynchttp/asynchttp.js +13 -13
- package/dist/plugins/java/asynchttp/index.js +1 -5
- package/dist/plugins/java/nethttp/index.js +1 -5
- package/dist/plugins/java/nethttp/nethttp.js +13 -13
- package/dist/plugins/java/okhttp/index.js +1 -5
- package/dist/plugins/java/okhttp/okhttp.js +13 -13
- package/dist/plugins/java/unirest/index.js +1 -5
- package/dist/plugins/java/unirest/unirest.js +13 -13
- package/dist/plugins/js/axios/axios.js +13 -13
- package/dist/plugins/js/axios/index.js +1 -5
- package/dist/plugins/js/fetch/fetch.js +82 -68
- package/dist/plugins/js/fetch/index.js +1 -5
- package/dist/plugins/js/jquery/index.js +1 -5
- package/dist/plugins/js/jquery/jquery.js +13 -13
- package/dist/plugins/js/ofetch/index.js +1 -5
- package/dist/plugins/js/ofetch/ofetch.js +61 -48
- package/dist/plugins/js/xhr/index.js +1 -5
- package/dist/plugins/js/xhr/xhr.js +13 -13
- package/dist/plugins/kotlin/okhttp/index.js +1 -5
- package/dist/plugins/kotlin/okhttp/okhttp.js +13 -13
- package/dist/plugins/node/axios/axios.js +13 -13
- package/dist/plugins/node/axios/index.js +1 -5
- package/dist/plugins/node/fetch/fetch.js +86 -74
- package/dist/plugins/node/fetch/index.js +1 -5
- package/dist/plugins/node/ofetch/index.js +1 -5
- package/dist/plugins/node/ofetch/ofetch.js +61 -48
- package/dist/plugins/node/undici/index.js +1 -5
- package/dist/plugins/node/undici/undici.js +60 -47
- package/dist/plugins/objc/nsurlsession/index.js +1 -5
- package/dist/plugins/objc/nsurlsession/nsurlsession.js +13 -13
- package/dist/plugins/ocaml/cohttp/cohttp.js +13 -13
- package/dist/plugins/ocaml/cohttp/index.js +1 -5
- package/dist/plugins/php/curl/curl.js +143 -101
- package/dist/plugins/php/curl/index.js +1 -5
- package/dist/plugins/php/guzzle/guzzle.d.ts.map +1 -1
- package/dist/plugins/php/guzzle/guzzle.js +109 -83
- package/dist/plugins/php/guzzle/index.js +1 -5
- package/dist/plugins/powershell/restmethod/index.js +1 -5
- package/dist/plugins/powershell/restmethod/restmethod.js +13 -13
- package/dist/plugins/powershell/webrequest/index.js +1 -5
- package/dist/plugins/powershell/webrequest/webrequest.js +13 -13
- package/dist/plugins/python/httpx/async.js +17 -15
- package/dist/plugins/python/httpx/index.js +2 -7
- package/dist/plugins/python/httpx/sync.js +11 -12
- package/dist/plugins/python/python3/index.js +1 -5
- package/dist/plugins/python/python3/python3.js +13 -13
- package/dist/plugins/python/requests/index.js +1 -5
- package/dist/plugins/python/requests/requests.js +11 -12
- package/dist/plugins/python/requestsLike.d.ts.map +1 -1
- package/dist/plugins/python/requestsLike.js +145 -112
- package/dist/plugins/r/httr/httr.js +13 -13
- package/dist/plugins/r/httr/index.js +1 -5
- package/dist/plugins/ruby/native/index.js +1 -5
- package/dist/plugins/ruby/native/native.js +13 -13
- package/dist/plugins/rust/reqwest/index.js +1 -5
- package/dist/plugins/rust/reqwest/reqwest.js +126 -83
- package/dist/plugins/shell/curl/curl.d.ts.map +1 -1
- package/dist/plugins/shell/curl/curl.js +129 -97
- package/dist/plugins/shell/curl/index.js +1 -5
- package/dist/plugins/shell/httpie/httpie.js +13 -13
- package/dist/plugins/shell/httpie/index.js +1 -5
- package/dist/plugins/shell/wget/index.js +1 -5
- package/dist/plugins/shell/wget/wget.js +13 -13
- package/dist/plugins/swift/nsurlsession/index.js +1 -5
- package/dist/plugins/swift/nsurlsession/nsurlsession.js +13 -13
- package/dist/snippetz.js +25 -28
- package/dist/utils/convertWithHttpSnippetLite.js +100 -96
- package/dist/utils/index.js +1 -5
- package/package.json +8 -12
- package/dist/clients/index.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/code-builder.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/escape.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/headers.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/reducer.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/shell.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/snippet-request.js.map +0 -7
- package/dist/httpsnippet-lite/helpers/url.js.map +0 -7
- package/dist/httpsnippet-lite/targets/c/libcurl/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/go/native/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/asynchttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/nethttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/okhttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/java/unirest/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/axios/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/jquery/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/javascript/xhr/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/node/axios/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/objc/helpers.js.map +0 -7
- package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/common.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/python/python3/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/r/httr/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/ruby/native/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/shell/httpie/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/shell/wget/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/swift/helpers.js.map +0 -7
- package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js.map +0 -7
- package/dist/httpsnippet-lite/targets/target.js.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/libs/http.js.map +0 -7
- package/dist/libs/javascript.js.map +0 -7
- package/dist/libs/php.js.map +0 -7
- package/dist/libs/rust.js.map +0 -7
- package/dist/libs/shell.js.map +0 -7
- package/dist/plugins/c/libcurl/index.js.map +0 -7
- package/dist/plugins/c/libcurl/libcurl.js.map +0 -7
- package/dist/plugins/clojure/clj_http/clj_http.js.map +0 -7
- package/dist/plugins/clojure/clj_http/index.js.map +0 -7
- package/dist/plugins/csharp/httpclient/httpclient.js.map +0 -7
- package/dist/plugins/csharp/httpclient/index.js.map +0 -7
- package/dist/plugins/csharp/restsharp/index.js.map +0 -7
- package/dist/plugins/csharp/restsharp/restsharp.js.map +0 -7
- package/dist/plugins/dart/http/http.js.map +0 -7
- package/dist/plugins/dart/http/index.js.map +0 -7
- package/dist/plugins/fsharp/httpclient/httpclient.js.map +0 -7
- package/dist/plugins/fsharp/httpclient/index.js.map +0 -7
- package/dist/plugins/go/native/index.js.map +0 -7
- package/dist/plugins/go/native/native.js.map +0 -7
- package/dist/plugins/http/http11/http11.js.map +0 -7
- package/dist/plugins/http/http11/index.js.map +0 -7
- package/dist/plugins/java/asynchttp/asynchttp.js.map +0 -7
- package/dist/plugins/java/asynchttp/index.js.map +0 -7
- package/dist/plugins/java/nethttp/index.js.map +0 -7
- package/dist/plugins/java/nethttp/nethttp.js.map +0 -7
- package/dist/plugins/java/okhttp/index.js.map +0 -7
- package/dist/plugins/java/okhttp/okhttp.js.map +0 -7
- package/dist/plugins/java/unirest/index.js.map +0 -7
- package/dist/plugins/java/unirest/unirest.js.map +0 -7
- package/dist/plugins/js/axios/axios.js.map +0 -7
- package/dist/plugins/js/axios/index.js.map +0 -7
- package/dist/plugins/js/fetch/fetch.js.map +0 -7
- package/dist/plugins/js/fetch/index.js.map +0 -7
- package/dist/plugins/js/jquery/index.js.map +0 -7
- package/dist/plugins/js/jquery/jquery.js.map +0 -7
- package/dist/plugins/js/ofetch/index.js.map +0 -7
- package/dist/plugins/js/ofetch/ofetch.js.map +0 -7
- package/dist/plugins/js/xhr/index.js.map +0 -7
- package/dist/plugins/js/xhr/xhr.js.map +0 -7
- package/dist/plugins/kotlin/okhttp/index.js.map +0 -7
- package/dist/plugins/kotlin/okhttp/okhttp.js.map +0 -7
- package/dist/plugins/node/axios/axios.js.map +0 -7
- package/dist/plugins/node/axios/index.js.map +0 -7
- package/dist/plugins/node/fetch/fetch.js.map +0 -7
- package/dist/plugins/node/fetch/index.js.map +0 -7
- package/dist/plugins/node/ofetch/index.js.map +0 -7
- package/dist/plugins/node/ofetch/ofetch.js.map +0 -7
- package/dist/plugins/node/undici/index.js.map +0 -7
- package/dist/plugins/node/undici/undici.js.map +0 -7
- package/dist/plugins/objc/nsurlsession/index.js.map +0 -7
- package/dist/plugins/objc/nsurlsession/nsurlsession.js.map +0 -7
- package/dist/plugins/ocaml/cohttp/cohttp.js.map +0 -7
- package/dist/plugins/ocaml/cohttp/index.js.map +0 -7
- package/dist/plugins/php/curl/curl.js.map +0 -7
- package/dist/plugins/php/curl/index.js.map +0 -7
- package/dist/plugins/php/guzzle/guzzle.js.map +0 -7
- package/dist/plugins/php/guzzle/index.js.map +0 -7
- package/dist/plugins/powershell/restmethod/index.js.map +0 -7
- package/dist/plugins/powershell/restmethod/restmethod.js.map +0 -7
- package/dist/plugins/powershell/webrequest/index.js.map +0 -7
- package/dist/plugins/powershell/webrequest/webrequest.js.map +0 -7
- package/dist/plugins/python/httpx/async.js.map +0 -7
- package/dist/plugins/python/httpx/index.js.map +0 -7
- package/dist/plugins/python/httpx/sync.js.map +0 -7
- package/dist/plugins/python/python3/index.js.map +0 -7
- package/dist/plugins/python/python3/python3.js.map +0 -7
- package/dist/plugins/python/requests/index.js.map +0 -7
- package/dist/plugins/python/requests/requests.js.map +0 -7
- package/dist/plugins/python/requestsLike.js.map +0 -7
- package/dist/plugins/r/httr/httr.js.map +0 -7
- package/dist/plugins/r/httr/index.js.map +0 -7
- package/dist/plugins/ruby/native/index.js.map +0 -7
- package/dist/plugins/ruby/native/native.js.map +0 -7
- package/dist/plugins/rust/reqwest/index.js.map +0 -7
- package/dist/plugins/rust/reqwest/reqwest.js.map +0 -7
- package/dist/plugins/shell/curl/curl.js.map +0 -7
- package/dist/plugins/shell/curl/index.js.map +0 -7
- package/dist/plugins/shell/httpie/httpie.js.map +0 -7
- package/dist/plugins/shell/httpie/index.js.map +0 -7
- package/dist/plugins/shell/wget/index.js.map +0 -7
- package/dist/plugins/shell/wget/wget.js.map +0 -7
- package/dist/plugins/swift/nsurlsession/index.js.map +0 -7
- package/dist/plugins/swift/nsurlsession/nsurlsession.js.map +0 -7
- package/dist/snippetz.js.map +0 -7
- package/dist/utils/convertWithHttpSnippetLite.js.map +0 -7
- package/dist/utils/index.js.map +0 -7
|
@@ -1,110 +1,124 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
if (opts.verbose) {
|
|
41
|
-
flags.push(opts.short ? "-v" : "--verbose");
|
|
42
|
-
}
|
|
43
|
-
if (opts.print) {
|
|
44
|
-
flags.push(`${opts.short ? "-p" : "--print"}=${opts.print}`);
|
|
45
|
-
}
|
|
46
|
-
if (opts.verify) {
|
|
47
|
-
flags.push(`--verify=${opts.verify}`);
|
|
48
|
-
}
|
|
49
|
-
if (opts.cert) {
|
|
50
|
-
flags.push(`--cert=${opts.cert}`);
|
|
51
|
-
}
|
|
52
|
-
if (opts.pretty) {
|
|
53
|
-
flags.push(`--pretty=${opts.pretty}`);
|
|
54
|
-
}
|
|
55
|
-
if (opts.style) {
|
|
56
|
-
flags.push(`--style=${opts.style}`);
|
|
57
|
-
}
|
|
58
|
-
if (opts.timeout) {
|
|
59
|
-
flags.push(`--timeout=${opts.timeout}`);
|
|
60
|
-
}
|
|
61
|
-
if (opts.queryParams) {
|
|
62
|
-
Object.keys(queryObj).forEach((name) => {
|
|
63
|
-
const value = queryObj[name];
|
|
64
|
-
if (Array.isArray(value)) {
|
|
65
|
-
value.forEach((val) => {
|
|
66
|
-
push(`${name}==${shellQuote(val)}`);
|
|
67
|
-
});
|
|
68
|
-
} else {
|
|
69
|
-
push(`${name}==${shellQuote(value)}`);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
Object.keys(allHeaders).sort().forEach((key) => {
|
|
74
|
-
push(`${key}:${shellQuote(allHeaders[key])}`);
|
|
75
|
-
});
|
|
76
|
-
if ((postData === null || postData === void 0 ? void 0 : postData.mimeType) === "application/x-www-form-urlencoded") {
|
|
77
|
-
if (postData.params?.length) {
|
|
78
|
-
flags.push(opts.short ? "-f" : "--form");
|
|
79
|
-
postData.params.forEach((param) => {
|
|
80
|
-
push(`${param.name}=${shellQuote(param.value)}`);
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* HTTP code snippet generator for the Shell using HTTPie.
|
|
4
|
+
*
|
|
5
|
+
* @author
|
|
6
|
+
* @AhmadNassri
|
|
7
|
+
*
|
|
8
|
+
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
9
|
+
*/
|
|
10
|
+
import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
|
|
11
|
+
import { shellQuote } from '../../../../httpsnippet-lite/helpers/shell.js';
|
|
12
|
+
export const httpie = {
|
|
13
|
+
info: {
|
|
14
|
+
key: 'httpie',
|
|
15
|
+
title: 'HTTPie',
|
|
16
|
+
link: 'http://httpie.org/',
|
|
17
|
+
description: 'a CLI, cURL-like tool for humans',
|
|
18
|
+
},
|
|
19
|
+
convert: ({ allHeaders, postData, queryObj, fullUrl, method, url }, options) => {
|
|
20
|
+
const opts = {
|
|
21
|
+
body: false,
|
|
22
|
+
cert: false,
|
|
23
|
+
headers: false,
|
|
24
|
+
indent: ' ',
|
|
25
|
+
pretty: false,
|
|
26
|
+
print: false,
|
|
27
|
+
queryParams: false,
|
|
28
|
+
short: false,
|
|
29
|
+
style: false,
|
|
30
|
+
timeout: false,
|
|
31
|
+
verbose: false,
|
|
32
|
+
verify: false,
|
|
33
|
+
...options,
|
|
34
|
+
};
|
|
35
|
+
const { push, join, unshift } = new CodeBuilder({
|
|
36
|
+
indent: opts.indent,
|
|
37
|
+
// @ts-expect-error SEEMS LEGIT
|
|
38
|
+
join: opts.indent !== false ? ` \\\n${opts.indent}` : ' ',
|
|
81
39
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
push(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
40
|
+
let raw = false;
|
|
41
|
+
const flags = [];
|
|
42
|
+
if (opts.headers) {
|
|
43
|
+
flags.push(opts.short ? '-h' : '--headers');
|
|
44
|
+
}
|
|
45
|
+
if (opts.body) {
|
|
46
|
+
flags.push(opts.short ? '-b' : '--body');
|
|
47
|
+
}
|
|
48
|
+
if (opts.verbose) {
|
|
49
|
+
flags.push(opts.short ? '-v' : '--verbose');
|
|
50
|
+
}
|
|
51
|
+
if (opts.print) {
|
|
52
|
+
flags.push(`${opts.short ? '-p' : '--print'}=${opts.print}`);
|
|
53
|
+
}
|
|
54
|
+
if (opts.verify) {
|
|
55
|
+
flags.push(`--verify=${opts.verify}`);
|
|
56
|
+
}
|
|
57
|
+
if (opts.cert) {
|
|
58
|
+
flags.push(`--cert=${opts.cert}`);
|
|
59
|
+
}
|
|
60
|
+
if (opts.pretty) {
|
|
61
|
+
flags.push(`--pretty=${opts.pretty}`);
|
|
62
|
+
}
|
|
63
|
+
if (opts.style) {
|
|
64
|
+
flags.push(`--style=${opts.style}`);
|
|
65
|
+
}
|
|
66
|
+
if (opts.timeout) {
|
|
67
|
+
flags.push(`--timeout=${opts.timeout}`);
|
|
68
|
+
}
|
|
69
|
+
// construct query params
|
|
70
|
+
if (opts.queryParams) {
|
|
71
|
+
Object.keys(queryObj).forEach((name) => {
|
|
72
|
+
const value = queryObj[name];
|
|
73
|
+
if (Array.isArray(value)) {
|
|
74
|
+
value.forEach((val) => {
|
|
75
|
+
push(`${name}==${shellQuote(val)}`);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
push(`${name}==${shellQuote(value)}`);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
// construct headers
|
|
84
|
+
Object.keys(allHeaders)
|
|
85
|
+
.sort()
|
|
86
|
+
.forEach((key) => {
|
|
87
|
+
push(`${key}:${shellQuote(allHeaders[key])}`);
|
|
92
88
|
});
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
89
|
+
if ((postData === null || postData === void 0 ? void 0 : postData.mimeType) === 'application/x-www-form-urlencoded') {
|
|
90
|
+
// construct post params
|
|
91
|
+
if (postData.params?.length) {
|
|
92
|
+
flags.push(opts.short ? '-f' : '--form');
|
|
93
|
+
postData.params.forEach((param) => {
|
|
94
|
+
push(`${param.name}=${shellQuote(param.value)}`);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else if ((postData === null || postData === void 0 ? void 0 : postData.mimeType) === 'multipart/form-data') {
|
|
99
|
+
// construct multipart form data
|
|
100
|
+
if (postData?.params?.length) {
|
|
101
|
+
flags.push('--multipart');
|
|
102
|
+
postData.params.forEach((param) => {
|
|
103
|
+
if (param.fileName) {
|
|
104
|
+
push(`${param.name}@${shellQuote(param.fileName)}`);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
push(`${param.name}='${shellQuote(param.value)}'`);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
raw = true;
|
|
114
|
+
}
|
|
115
|
+
const cliFlags = flags.length ? `${flags.join(' ')} ` : '';
|
|
116
|
+
url = shellQuote(opts.queryParams ? url : fullUrl);
|
|
117
|
+
unshift(`http ${cliFlags}${method} ${url}`);
|
|
118
|
+
if (raw && (postData === null || postData === void 0 ? void 0 : postData.text)) {
|
|
119
|
+
const postDataText = shellQuote(postData.text);
|
|
120
|
+
unshift(`echo ${postDataText} | `);
|
|
121
|
+
}
|
|
122
|
+
return join();
|
|
123
|
+
},
|
|
109
124
|
};
|
|
110
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1,44 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* HTTP code snippet generator for the Shell using Wget.
|
|
4
|
+
*
|
|
5
|
+
* @author
|
|
6
|
+
* @AhmadNassri
|
|
7
|
+
*
|
|
8
|
+
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
9
|
+
*/
|
|
10
|
+
import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
|
|
11
|
+
import { shellEscape, shellQuote } from '../../../../httpsnippet-lite/helpers/shell.js';
|
|
12
|
+
export const wget = {
|
|
13
|
+
info: {
|
|
14
|
+
key: 'wget',
|
|
15
|
+
title: 'Wget',
|
|
16
|
+
link: 'https://www.gnu.org/software/wget/',
|
|
17
|
+
description: 'a free software package for retrieving files using HTTP, HTTPS',
|
|
18
|
+
},
|
|
19
|
+
convert: ({ method, postData, allHeaders, fullUrl }, options) => {
|
|
20
|
+
const opts = {
|
|
21
|
+
indent: ' ',
|
|
22
|
+
short: false,
|
|
23
|
+
verbose: false,
|
|
24
|
+
...options,
|
|
25
|
+
};
|
|
26
|
+
const { push, join } = new CodeBuilder({
|
|
27
|
+
indent: opts.indent,
|
|
28
|
+
// @ts-expect-error SEEMS LEGIT
|
|
29
|
+
join: opts.indent !== false ? ` \\\n${opts.indent}` : ' ',
|
|
30
|
+
});
|
|
31
|
+
if (opts.verbose) {
|
|
32
|
+
push(`wget ${opts.short ? '-v' : '--verbose'}`);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
push(`wget ${opts.short ? '-q' : '--quiet'}`);
|
|
36
|
+
}
|
|
37
|
+
push(`--method ${shellQuote(method)}`);
|
|
38
|
+
Object.keys(allHeaders).forEach((key) => {
|
|
39
|
+
const header = `${key}: ${allHeaders[key]}`;
|
|
40
|
+
push(`--header ${shellQuote(header)}`);
|
|
41
|
+
});
|
|
42
|
+
if (postData === null || postData === void 0 ? void 0 : postData.text) {
|
|
43
|
+
push(`--body-data ${shellEscape(shellQuote(postData.text))}`);
|
|
44
|
+
}
|
|
45
|
+
push(opts.short ? '-O' : '--output-document');
|
|
46
|
+
push(`- ${shellQuote(fullUrl)}`);
|
|
47
|
+
return join();
|
|
48
|
+
},
|
|
40
49
|
};
|
|
41
|
-
export {
|
|
42
|
-
wget
|
|
43
|
-
};
|
|
44
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1,52 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create an string of given length filled with blank spaces
|
|
3
|
+
*
|
|
4
|
+
* @param length Length of the array to return
|
|
5
|
+
* @param str String to pad out with
|
|
6
|
+
*/
|
|
1
7
|
const buildString = (length, str) => str.repeat(length);
|
|
8
|
+
/**
|
|
9
|
+
* Create a string corresponding to a Dictionary or Array literal representation with pretty option and indentation.
|
|
10
|
+
*/
|
|
2
11
|
const concatArray = (arr, pretty, indentation, indentLevel) => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
${
|
|
10
|
-
${closingBraceIndent}]`;
|
|
11
|
-
}
|
|
12
|
-
return `[${arr.join(join)}]`;
|
|
12
|
+
const currentIndent = buildString(indentLevel, indentation);
|
|
13
|
+
const closingBraceIndent = buildString(indentLevel - 1, indentation);
|
|
14
|
+
const join = pretty ? `,\n${currentIndent}` : ', ';
|
|
15
|
+
if (pretty) {
|
|
16
|
+
return `[\n${currentIndent}${arr.join(join)}\n${closingBraceIndent}]`;
|
|
17
|
+
}
|
|
18
|
+
return `[${arr.join(join)}]`;
|
|
13
19
|
};
|
|
14
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Create a string corresponding to a valid declaration and initialization of a Swift array or dictionary literal
|
|
22
|
+
*
|
|
23
|
+
* @param name Desired name of the instance
|
|
24
|
+
* @param parameters Key-value object of parameters to translate to a Swift object literal
|
|
25
|
+
* @param opts Target options
|
|
26
|
+
* @return {string}
|
|
27
|
+
*/
|
|
28
|
+
export const literalDeclaration = (name, parameters, opts) => `let ${name} = ${literalRepresentation(parameters, opts)}`;
|
|
29
|
+
/**
|
|
30
|
+
* Create a valid Swift string of a literal value according to its type.
|
|
31
|
+
*
|
|
32
|
+
* @param value Any JavaScript literal
|
|
33
|
+
* @param opts Target options
|
|
34
|
+
*/
|
|
15
35
|
const literalRepresentation = (value, opts, indentLevelInput) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
36
|
+
const indentLevel = indentLevelInput === undefined ? 1 : indentLevelInput + 1;
|
|
37
|
+
switch (Object.prototype.toString.call(value)) {
|
|
38
|
+
case '[object Number]':
|
|
39
|
+
return value;
|
|
40
|
+
case '[object Array]': {
|
|
41
|
+
// Don't prettify arrays to avoid taking too much space
|
|
42
|
+
let pretty = false;
|
|
43
|
+
const valuesRepresentation = value.map((v) => {
|
|
44
|
+
// Switch to prettify if the value is a dictionary with multiple keys
|
|
45
|
+
if (Object.prototype.toString.call(v) === '[object Object]') {
|
|
46
|
+
pretty = Object.keys(v).length > 1;
|
|
47
|
+
}
|
|
48
|
+
return literalRepresentation(v, opts, indentLevel);
|
|
49
|
+
});
|
|
50
|
+
return concatArray(valuesRepresentation, pretty, opts.indent, indentLevel);
|
|
25
51
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
keyValuePairs.push(`"${key}": ${literalRepresentation(_value[key], opts, indentLevel)}`);
|
|
52
|
+
case '[object Object]': {
|
|
53
|
+
const keyValuePairs = [];
|
|
54
|
+
const _value = value;
|
|
55
|
+
for (const key in _value) {
|
|
56
|
+
if (Object.hasOwn(_value, key)) {
|
|
57
|
+
keyValuePairs.push(`"${key}": ${literalRepresentation(_value[key], opts, indentLevel)}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return concatArray(keyValuePairs, opts.pretty && keyValuePairs.length > 1, opts.indent, indentLevel);
|
|
36
61
|
}
|
|
37
|
-
|
|
38
|
-
|
|
62
|
+
case '[object Boolean]':
|
|
63
|
+
return value.toString();
|
|
64
|
+
default:
|
|
65
|
+
if (value === null || value === undefined) {
|
|
66
|
+
return '';
|
|
67
|
+
}
|
|
68
|
+
return `"${value.toString().replace(/"/g, '\\"')}"`;
|
|
39
69
|
}
|
|
40
|
-
case "[object Boolean]":
|
|
41
|
-
return value.toString();
|
|
42
|
-
default:
|
|
43
|
-
if (value === null || value === void 0) {
|
|
44
|
-
return "";
|
|
45
|
-
}
|
|
46
|
-
return `"${value.toString().replace(/"/g, '\\"')}"`;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
export {
|
|
50
|
-
literalDeclaration
|
|
51
70
|
};
|
|
52
|
-
//# sourceMappingURL=helpers.js.map
|