@scalar/snippetz 0.7.3 → 0.7.5

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.
Files changed (245) hide show
  1. package/dist/clients/index.js +168 -169
  2. package/dist/httpsnippet-lite/helpers/code-builder.js +86 -74
  3. package/dist/httpsnippet-lite/helpers/escape.js +69 -44
  4. package/dist/httpsnippet-lite/helpers/headers.js +17 -14
  5. package/dist/httpsnippet-lite/helpers/reducer.js +1 -1
  6. package/dist/httpsnippet-lite/helpers/shell.js +13 -13
  7. package/dist/httpsnippet-lite/helpers/snippet-request.js +1 -1
  8. package/dist/httpsnippet-lite/helpers/url.js +4 -8
  9. package/dist/httpsnippet-lite/targets/c/libcurl/client.js +69 -67
  10. package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js +165 -154
  11. package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js +35 -38
  12. package/dist/httpsnippet-lite/targets/go/native/client.js +151 -147
  13. package/dist/httpsnippet-lite/targets/java/asynchttp/client.js +32 -35
  14. package/dist/httpsnippet-lite/targets/java/nethttp/client.js +40 -39
  15. package/dist/httpsnippet-lite/targets/java/okhttp/client.js +83 -73
  16. package/dist/httpsnippet-lite/targets/java/unirest/client.js +41 -34
  17. package/dist/httpsnippet-lite/targets/javascript/axios/client.js +81 -76
  18. package/dist/httpsnippet-lite/targets/javascript/jquery/client.js +77 -71
  19. package/dist/httpsnippet-lite/targets/javascript/xhr/client.js +73 -71
  20. package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js +83 -73
  21. package/dist/httpsnippet-lite/targets/node/axios/client.js +74 -69
  22. package/dist/httpsnippet-lite/targets/objc/helpers.js +52 -33
  23. package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js +123 -121
  24. package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js +60 -49
  25. package/dist/httpsnippet-lite/targets/powershell/common.js +46 -56
  26. package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js +9 -13
  27. package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js +9 -13
  28. package/dist/httpsnippet-lite/targets/python/python3/client.js +85 -68
  29. package/dist/httpsnippet-lite/targets/r/httr/client.js +114 -95
  30. package/dist/httpsnippet-lite/targets/ruby/native/client.js +66 -70
  31. package/dist/httpsnippet-lite/targets/shell/httpie/client.js +121 -107
  32. package/dist/httpsnippet-lite/targets/shell/wget/client.js +48 -43
  33. package/dist/httpsnippet-lite/targets/swift/helpers.js +62 -44
  34. package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js +126 -112
  35. package/dist/httpsnippet-lite/targets/target.js +1 -1
  36. package/dist/index.js +2 -9
  37. package/dist/libs/http.js +68 -56
  38. package/dist/libs/javascript.js +77 -60
  39. package/dist/libs/php.js +59 -49
  40. package/dist/libs/rust.js +60 -33
  41. package/dist/libs/shell.js +14 -5
  42. package/dist/plugins/c/libcurl/index.js +1 -5
  43. package/dist/plugins/c/libcurl/libcurl.js +13 -13
  44. package/dist/plugins/clojure/clj_http/clj_http.js +13 -13
  45. package/dist/plugins/clojure/clj_http/index.js +1 -5
  46. package/dist/plugins/csharp/httpclient/httpclient.js +186 -150
  47. package/dist/plugins/csharp/httpclient/index.js +1 -5
  48. package/dist/plugins/csharp/restsharp/index.js +1 -5
  49. package/dist/plugins/csharp/restsharp/restsharp.js +13 -13
  50. package/dist/plugins/dart/http/http.js +95 -93
  51. package/dist/plugins/dart/http/index.js +1 -5
  52. package/dist/plugins/fsharp/httpclient/httpclient.js +156 -122
  53. package/dist/plugins/fsharp/httpclient/index.js +1 -5
  54. package/dist/plugins/go/native/index.js +1 -5
  55. package/dist/plugins/go/native/native.js +13 -13
  56. package/dist/plugins/http/http11/http11.js +103 -85
  57. package/dist/plugins/http/http11/index.js +1 -5
  58. package/dist/plugins/java/asynchttp/asynchttp.js +13 -13
  59. package/dist/plugins/java/asynchttp/index.js +1 -5
  60. package/dist/plugins/java/nethttp/index.js +1 -5
  61. package/dist/plugins/java/nethttp/nethttp.js +13 -13
  62. package/dist/plugins/java/okhttp/index.js +1 -5
  63. package/dist/plugins/java/okhttp/okhttp.js +13 -13
  64. package/dist/plugins/java/unirest/index.js +1 -5
  65. package/dist/plugins/java/unirest/unirest.js +13 -13
  66. package/dist/plugins/js/axios/axios.js +13 -13
  67. package/dist/plugins/js/axios/index.js +1 -5
  68. package/dist/plugins/js/fetch/fetch.js +82 -68
  69. package/dist/plugins/js/fetch/index.js +1 -5
  70. package/dist/plugins/js/jquery/index.js +1 -5
  71. package/dist/plugins/js/jquery/jquery.js +13 -13
  72. package/dist/plugins/js/ofetch/index.js +1 -5
  73. package/dist/plugins/js/ofetch/ofetch.js +61 -48
  74. package/dist/plugins/js/xhr/index.js +1 -5
  75. package/dist/plugins/js/xhr/xhr.js +13 -13
  76. package/dist/plugins/kotlin/okhttp/index.js +1 -5
  77. package/dist/plugins/kotlin/okhttp/okhttp.js +13 -13
  78. package/dist/plugins/node/axios/axios.js +13 -13
  79. package/dist/plugins/node/axios/index.js +1 -5
  80. package/dist/plugins/node/fetch/fetch.js +86 -74
  81. package/dist/plugins/node/fetch/index.js +1 -5
  82. package/dist/plugins/node/ofetch/index.js +1 -5
  83. package/dist/plugins/node/ofetch/ofetch.js +61 -48
  84. package/dist/plugins/node/undici/index.js +1 -5
  85. package/dist/plugins/node/undici/undici.js +60 -47
  86. package/dist/plugins/objc/nsurlsession/index.js +1 -5
  87. package/dist/plugins/objc/nsurlsession/nsurlsession.js +13 -13
  88. package/dist/plugins/ocaml/cohttp/cohttp.js +13 -13
  89. package/dist/plugins/ocaml/cohttp/index.js +1 -5
  90. package/dist/plugins/php/curl/curl.js +143 -101
  91. package/dist/plugins/php/curl/index.js +1 -5
  92. package/dist/plugins/php/guzzle/guzzle.js +103 -83
  93. package/dist/plugins/php/guzzle/index.js +1 -5
  94. package/dist/plugins/powershell/restmethod/index.js +1 -5
  95. package/dist/plugins/powershell/restmethod/restmethod.js +13 -13
  96. package/dist/plugins/powershell/webrequest/index.js +1 -5
  97. package/dist/plugins/powershell/webrequest/webrequest.js +13 -13
  98. package/dist/plugins/python/httpx/async.js +17 -15
  99. package/dist/plugins/python/httpx/index.js +2 -7
  100. package/dist/plugins/python/httpx/sync.js +11 -12
  101. package/dist/plugins/python/python3/index.js +1 -5
  102. package/dist/plugins/python/python3/python3.js +13 -13
  103. package/dist/plugins/python/requests/index.js +1 -5
  104. package/dist/plugins/python/requests/requests.js +11 -12
  105. package/dist/plugins/python/requestsLike.js +128 -112
  106. package/dist/plugins/r/httr/httr.js +13 -13
  107. package/dist/plugins/r/httr/index.js +1 -5
  108. package/dist/plugins/ruby/native/index.js +1 -5
  109. package/dist/plugins/ruby/native/native.js +13 -13
  110. package/dist/plugins/rust/reqwest/index.js +1 -5
  111. package/dist/plugins/rust/reqwest/reqwest.js +110 -83
  112. package/dist/plugins/shell/curl/curl.js +128 -97
  113. package/dist/plugins/shell/curl/index.js +1 -5
  114. package/dist/plugins/shell/httpie/httpie.js +13 -13
  115. package/dist/plugins/shell/httpie/index.js +1 -5
  116. package/dist/plugins/shell/wget/index.js +1 -5
  117. package/dist/plugins/shell/wget/wget.js +13 -13
  118. package/dist/plugins/swift/nsurlsession/index.js +1 -5
  119. package/dist/plugins/swift/nsurlsession/nsurlsession.js +13 -13
  120. package/dist/snippetz.js +25 -28
  121. package/dist/utils/convertWithHttpSnippetLite.js +100 -96
  122. package/dist/utils/index.js +1 -5
  123. package/package.json +8 -12
  124. package/dist/clients/index.js.map +0 -7
  125. package/dist/httpsnippet-lite/helpers/code-builder.js.map +0 -7
  126. package/dist/httpsnippet-lite/helpers/escape.js.map +0 -7
  127. package/dist/httpsnippet-lite/helpers/headers.js.map +0 -7
  128. package/dist/httpsnippet-lite/helpers/reducer.js.map +0 -7
  129. package/dist/httpsnippet-lite/helpers/shell.js.map +0 -7
  130. package/dist/httpsnippet-lite/helpers/snippet-request.js.map +0 -7
  131. package/dist/httpsnippet-lite/helpers/url.js.map +0 -7
  132. package/dist/httpsnippet-lite/targets/c/libcurl/client.js.map +0 -7
  133. package/dist/httpsnippet-lite/targets/clojure/clj_http/client.js.map +0 -7
  134. package/dist/httpsnippet-lite/targets/csharp/restsharp/client.js.map +0 -7
  135. package/dist/httpsnippet-lite/targets/go/native/client.js.map +0 -7
  136. package/dist/httpsnippet-lite/targets/java/asynchttp/client.js.map +0 -7
  137. package/dist/httpsnippet-lite/targets/java/nethttp/client.js.map +0 -7
  138. package/dist/httpsnippet-lite/targets/java/okhttp/client.js.map +0 -7
  139. package/dist/httpsnippet-lite/targets/java/unirest/client.js.map +0 -7
  140. package/dist/httpsnippet-lite/targets/javascript/axios/client.js.map +0 -7
  141. package/dist/httpsnippet-lite/targets/javascript/jquery/client.js.map +0 -7
  142. package/dist/httpsnippet-lite/targets/javascript/xhr/client.js.map +0 -7
  143. package/dist/httpsnippet-lite/targets/kotlin/okhttp/client.js.map +0 -7
  144. package/dist/httpsnippet-lite/targets/node/axios/client.js.map +0 -7
  145. package/dist/httpsnippet-lite/targets/objc/helpers.js.map +0 -7
  146. package/dist/httpsnippet-lite/targets/objc/nsurlsession/client.js.map +0 -7
  147. package/dist/httpsnippet-lite/targets/ocaml/cohttp/client.js.map +0 -7
  148. package/dist/httpsnippet-lite/targets/powershell/common.js.map +0 -7
  149. package/dist/httpsnippet-lite/targets/powershell/restmethod/client.js.map +0 -7
  150. package/dist/httpsnippet-lite/targets/powershell/webrequest/client.js.map +0 -7
  151. package/dist/httpsnippet-lite/targets/python/python3/client.js.map +0 -7
  152. package/dist/httpsnippet-lite/targets/r/httr/client.js.map +0 -7
  153. package/dist/httpsnippet-lite/targets/ruby/native/client.js.map +0 -7
  154. package/dist/httpsnippet-lite/targets/shell/httpie/client.js.map +0 -7
  155. package/dist/httpsnippet-lite/targets/shell/wget/client.js.map +0 -7
  156. package/dist/httpsnippet-lite/targets/swift/helpers.js.map +0 -7
  157. package/dist/httpsnippet-lite/targets/swift/nsurlsession/client.js.map +0 -7
  158. package/dist/httpsnippet-lite/targets/target.js.map +0 -7
  159. package/dist/index.js.map +0 -7
  160. package/dist/libs/http.js.map +0 -7
  161. package/dist/libs/javascript.js.map +0 -7
  162. package/dist/libs/php.js.map +0 -7
  163. package/dist/libs/rust.js.map +0 -7
  164. package/dist/libs/shell.js.map +0 -7
  165. package/dist/plugins/c/libcurl/index.js.map +0 -7
  166. package/dist/plugins/c/libcurl/libcurl.js.map +0 -7
  167. package/dist/plugins/clojure/clj_http/clj_http.js.map +0 -7
  168. package/dist/plugins/clojure/clj_http/index.js.map +0 -7
  169. package/dist/plugins/csharp/httpclient/httpclient.js.map +0 -7
  170. package/dist/plugins/csharp/httpclient/index.js.map +0 -7
  171. package/dist/plugins/csharp/restsharp/index.js.map +0 -7
  172. package/dist/plugins/csharp/restsharp/restsharp.js.map +0 -7
  173. package/dist/plugins/dart/http/http.js.map +0 -7
  174. package/dist/plugins/dart/http/index.js.map +0 -7
  175. package/dist/plugins/fsharp/httpclient/httpclient.js.map +0 -7
  176. package/dist/plugins/fsharp/httpclient/index.js.map +0 -7
  177. package/dist/plugins/go/native/index.js.map +0 -7
  178. package/dist/plugins/go/native/native.js.map +0 -7
  179. package/dist/plugins/http/http11/http11.js.map +0 -7
  180. package/dist/plugins/http/http11/index.js.map +0 -7
  181. package/dist/plugins/java/asynchttp/asynchttp.js.map +0 -7
  182. package/dist/plugins/java/asynchttp/index.js.map +0 -7
  183. package/dist/plugins/java/nethttp/index.js.map +0 -7
  184. package/dist/plugins/java/nethttp/nethttp.js.map +0 -7
  185. package/dist/plugins/java/okhttp/index.js.map +0 -7
  186. package/dist/plugins/java/okhttp/okhttp.js.map +0 -7
  187. package/dist/plugins/java/unirest/index.js.map +0 -7
  188. package/dist/plugins/java/unirest/unirest.js.map +0 -7
  189. package/dist/plugins/js/axios/axios.js.map +0 -7
  190. package/dist/plugins/js/axios/index.js.map +0 -7
  191. package/dist/plugins/js/fetch/fetch.js.map +0 -7
  192. package/dist/plugins/js/fetch/index.js.map +0 -7
  193. package/dist/plugins/js/jquery/index.js.map +0 -7
  194. package/dist/plugins/js/jquery/jquery.js.map +0 -7
  195. package/dist/plugins/js/ofetch/index.js.map +0 -7
  196. package/dist/plugins/js/ofetch/ofetch.js.map +0 -7
  197. package/dist/plugins/js/xhr/index.js.map +0 -7
  198. package/dist/plugins/js/xhr/xhr.js.map +0 -7
  199. package/dist/plugins/kotlin/okhttp/index.js.map +0 -7
  200. package/dist/plugins/kotlin/okhttp/okhttp.js.map +0 -7
  201. package/dist/plugins/node/axios/axios.js.map +0 -7
  202. package/dist/plugins/node/axios/index.js.map +0 -7
  203. package/dist/plugins/node/fetch/fetch.js.map +0 -7
  204. package/dist/plugins/node/fetch/index.js.map +0 -7
  205. package/dist/plugins/node/ofetch/index.js.map +0 -7
  206. package/dist/plugins/node/ofetch/ofetch.js.map +0 -7
  207. package/dist/plugins/node/undici/index.js.map +0 -7
  208. package/dist/plugins/node/undici/undici.js.map +0 -7
  209. package/dist/plugins/objc/nsurlsession/index.js.map +0 -7
  210. package/dist/plugins/objc/nsurlsession/nsurlsession.js.map +0 -7
  211. package/dist/plugins/ocaml/cohttp/cohttp.js.map +0 -7
  212. package/dist/plugins/ocaml/cohttp/index.js.map +0 -7
  213. package/dist/plugins/php/curl/curl.js.map +0 -7
  214. package/dist/plugins/php/curl/index.js.map +0 -7
  215. package/dist/plugins/php/guzzle/guzzle.js.map +0 -7
  216. package/dist/plugins/php/guzzle/index.js.map +0 -7
  217. package/dist/plugins/powershell/restmethod/index.js.map +0 -7
  218. package/dist/plugins/powershell/restmethod/restmethod.js.map +0 -7
  219. package/dist/plugins/powershell/webrequest/index.js.map +0 -7
  220. package/dist/plugins/powershell/webrequest/webrequest.js.map +0 -7
  221. package/dist/plugins/python/httpx/async.js.map +0 -7
  222. package/dist/plugins/python/httpx/index.js.map +0 -7
  223. package/dist/plugins/python/httpx/sync.js.map +0 -7
  224. package/dist/plugins/python/python3/index.js.map +0 -7
  225. package/dist/plugins/python/python3/python3.js.map +0 -7
  226. package/dist/plugins/python/requests/index.js.map +0 -7
  227. package/dist/plugins/python/requests/requests.js.map +0 -7
  228. package/dist/plugins/python/requestsLike.js.map +0 -7
  229. package/dist/plugins/r/httr/httr.js.map +0 -7
  230. package/dist/plugins/r/httr/index.js.map +0 -7
  231. package/dist/plugins/ruby/native/index.js.map +0 -7
  232. package/dist/plugins/ruby/native/native.js.map +0 -7
  233. package/dist/plugins/rust/reqwest/index.js.map +0 -7
  234. package/dist/plugins/rust/reqwest/reqwest.js.map +0 -7
  235. package/dist/plugins/shell/curl/curl.js.map +0 -7
  236. package/dist/plugins/shell/curl/index.js.map +0 -7
  237. package/dist/plugins/shell/httpie/httpie.js.map +0 -7
  238. package/dist/plugins/shell/httpie/index.js.map +0 -7
  239. package/dist/plugins/shell/wget/index.js.map +0 -7
  240. package/dist/plugins/shell/wget/wget.js.map +0 -7
  241. package/dist/plugins/swift/nsurlsession/index.js.map +0 -7
  242. package/dist/plugins/swift/nsurlsession/nsurlsession.js.map +0 -7
  243. package/dist/snippetz.js.map +0 -7
  244. package/dist/utils/convertWithHttpSnippetLite.js.map +0 -7
  245. package/dist/utils/index.js.map +0 -7
@@ -1,15 +1,18 @@
1
- const getHeaderName = (headers, name) => Object.keys(headers).find((header) => header.toLowerCase() === name.toLowerCase());
2
- const getHeader = (headers, name) => {
3
- const headerName = getHeaderName(headers, name);
4
- if (!headerName) {
5
- return void 0;
6
- }
7
- return headers[headerName];
1
+ /**
2
+ * Given a headers object retrieve a specific header out of it via a case-insensitive key.
3
+ */
4
+ export const getHeaderName = (headers, name) => Object.keys(headers).find((header) => header.toLowerCase() === name.toLowerCase());
5
+ /**
6
+ * Given a headers object retrieve the contents of a header out of it via a case-insensitive key.
7
+ */
8
+ export const getHeader = (headers, name) => {
9
+ const headerName = getHeaderName(headers, name);
10
+ if (!headerName) {
11
+ return undefined;
12
+ }
13
+ return headers[headerName];
8
14
  };
9
- const hasHeader = (headers, name) => Boolean(getHeaderName(headers, name));
10
- export {
11
- getHeader,
12
- getHeaderName,
13
- hasHeader
14
- };
15
- //# sourceMappingURL=headers.js.map
15
+ /**
16
+ * Determine if a given case-insensitive header exists within a header object.
17
+ */
18
+ export const hasHeader = (headers, name) => Boolean(getHeaderName(headers, name));
@@ -1 +1 @@
1
- //# sourceMappingURL=reducer.js.map
1
+ export {};
@@ -1,14 +1,14 @@
1
- const shellQuote = (value = "") => {
2
- const safe = /^[a-z0-9-_/.@%^=:]+$/i;
3
- const isShellSafe = safe.test(value);
4
- if (isShellSafe) {
5
- return value;
6
- }
7
- return `'${value.replace(/'/g, "'\\''")}'`;
1
+ /**
2
+ * Use 'strong quoting' using single quotes so that we only need to deal with nested single quote characters.
3
+ * see: http://wiki.bash-hackers.org/syntax/quoting#strong_quoting
4
+ */
5
+ export const shellQuote = (value = '') => {
6
+ const safe = /^[a-z0-9-_/.@%^=:]+$/i;
7
+ const isShellSafe = safe.test(value);
8
+ if (isShellSafe) {
9
+ return value;
10
+ }
11
+ // if the value is not shell safe, then quote it
12
+ return `'${value.replace(/'/g, "'\\''")}'`;
8
13
  };
9
- const shellEscape = (value) => value.replace(/\r/g, "\\r").replace(/\n/g, "\\n");
10
- export {
11
- shellEscape,
12
- shellQuote
13
- };
14
- //# sourceMappingURL=shell.js.map
14
+ export const shellEscape = (value) => value.replace(/\r/g, '\\r').replace(/\n/g, '\\n');
@@ -1 +1 @@
1
- //# sourceMappingURL=snippet-request.js.map
1
+ export {};
@@ -1,9 +1,5 @@
1
- class ExtendedURL extends URL {
2
- get path() {
3
- return this.pathname + this.search;
4
- }
1
+ export class ExtendedURL extends URL {
2
+ get path() {
3
+ return this.pathname + this.search;
4
+ }
5
5
  }
6
- export {
7
- ExtendedURL
8
- };
9
- //# sourceMappingURL=url.js.map
@@ -1,70 +1,72 @@
1
- import { CodeBuilder } from "../../../../httpsnippet-lite/helpers/code-builder.js";
2
- import { escapeForDoubleQuotes } from "../../../../httpsnippet-lite/helpers/escape.js";
3
- import { createSearchParams } from "../../../../libs/http.js";
4
- const libcurl = {
5
- info: {
6
- key: "libcurl",
7
- title: "Libcurl",
8
- link: "http://curl.haxx.se/libcurl",
9
- description: "Simple REST and HTTP API Client for C"
10
- },
11
- convert: ({ method, fullUrl, headersObj, allHeaders, postData }) => {
12
- const { push, blank, join } = new CodeBuilder({ indent: " " });
13
- push("CURL *hnd = curl_easy_init();");
14
- blank();
15
- push(`curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "${method.toUpperCase()}");`);
16
- push(`curl_easy_setopt(hnd, CURLOPT_URL, "${fullUrl}");`);
17
- const headers = Object.keys(headersObj);
18
- if (headers.length) {
19
- blank();
20
- push("struct curl_slist *headers = NULL;");
21
- headers.forEach((header) => {
22
- if (headersObj[header]) {
23
- push(
24
- `headers = curl_slist_append(headers, "${header}: ${escapeForDoubleQuotes(headersObj[header])}");`
25
- );
26
- } else {
27
- push(`headers = curl_slist_append(headers, "${header};");`);
1
+ import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
2
+ import { escapeForDoubleQuotes } from '../../../../httpsnippet-lite/helpers/escape.js';
3
+ import { createSearchParams } from '../../../../libs/http.js';
4
+ export const libcurl = {
5
+ info: {
6
+ key: 'libcurl',
7
+ title: 'Libcurl',
8
+ link: 'http://curl.haxx.se/libcurl',
9
+ description: 'Simple REST and HTTP API Client for C',
10
+ },
11
+ convert: ({ method, fullUrl, headersObj, allHeaders, postData }) => {
12
+ const { push, blank, join } = new CodeBuilder({ indent: ' ' });
13
+ push('CURL *hnd = curl_easy_init();');
14
+ blank();
15
+ push(`curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "${method.toUpperCase()}");`);
16
+ push(`curl_easy_setopt(hnd, CURLOPT_URL, "${fullUrl}");`);
17
+ // Add headers, including the cookies
18
+ const headers = Object.keys(headersObj);
19
+ // construct headers
20
+ if (headers.length) {
21
+ blank();
22
+ push('struct curl_slist *headers = NULL;');
23
+ headers.forEach((header) => {
24
+ // See https://curl.se/libcurl/c/httpcustomheader.html for syntax
25
+ if (headersObj[header]) {
26
+ push(`headers = curl_slist_append(headers, "${header}: ${escapeForDoubleQuotes(headersObj[header])}");`);
27
+ }
28
+ else {
29
+ push(`headers = curl_slist_append(headers, "${header};");`);
30
+ }
31
+ });
32
+ push('curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);');
33
+ }
34
+ // construct cookies
35
+ if (allHeaders.cookie) {
36
+ blank();
37
+ push(`curl_easy_setopt(hnd, CURLOPT_COOKIE, "${allHeaders.cookie}");`);
38
+ }
39
+ if (postData !== null && postData !== void 0) {
40
+ blank();
41
+ if (postData.text) {
42
+ push(`curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, ${JSON.stringify(postData.text)});`);
43
+ }
44
+ else if (postData.mimeType === 'application/x-www-form-urlencoded' && postData.params) {
45
+ push(`curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "${createSearchParams(postData.params).toString()}");`);
46
+ }
47
+ else if (postData.mimeType === 'multipart/form-data' && postData.params) {
48
+ push('curl_mime *mime = curl_mime_init(hnd);');
49
+ postData.params.forEach((param) => {
50
+ blank();
51
+ push('{');
52
+ push('curl_mimepart *part = curl_mime_addpart(mime);', 1);
53
+ if (param.name) {
54
+ push(`curl_mime_name(part, "${param.name}");`, 1);
55
+ }
56
+ if (param.fileName) {
57
+ push(`curl_mime_filedata(part, "${param.fileName}");`, 1);
58
+ }
59
+ else if (param.value) {
60
+ push(`curl_mime_data(part, "${escapeForDoubleQuotes(param.value)}", CURL_ZERO_TERMINATED);`, 1);
61
+ }
62
+ push('}');
63
+ });
64
+ blank();
65
+ push('curl_easy_setopt(hnd, CURLOPT_MIMEPOST, mime);');
66
+ }
28
67
  }
29
- });
30
- push("curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);");
31
- }
32
- if (allHeaders.cookie) {
33
- blank();
34
- push(`curl_easy_setopt(hnd, CURLOPT_COOKIE, "${allHeaders.cookie}");`);
35
- }
36
- if (postData !== null && postData !== void 0) {
37
- blank();
38
- if (postData.text) {
39
- push(`curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, ${JSON.stringify(postData.text)});`);
40
- } else if (postData.mimeType === "application/x-www-form-urlencoded" && postData.params) {
41
- push(`curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "${createSearchParams(postData.params).toString()}");`);
42
- } else if (postData.mimeType === "multipart/form-data" && postData.params) {
43
- push("curl_mime *mime = curl_mime_init(hnd);");
44
- postData.params.forEach((param) => {
45
- blank();
46
- push("{");
47
- push("curl_mimepart *part = curl_mime_addpart(mime);", 1);
48
- if (param.name) {
49
- push(`curl_mime_name(part, "${param.name}");`, 1);
50
- }
51
- if (param.fileName) {
52
- push(`curl_mime_filedata(part, "${param.fileName}");`, 1);
53
- } else if (param.value) {
54
- push(`curl_mime_data(part, "${escapeForDoubleQuotes(param.value)}", CURL_ZERO_TERMINATED);`, 1);
55
- }
56
- push("}");
57
- });
58
68
  blank();
59
- push("curl_easy_setopt(hnd, CURLOPT_MIMEPOST, mime);");
60
- }
61
- }
62
- blank();
63
- push("CURLcode ret = curl_easy_perform(hnd);");
64
- return join();
65
- }
66
- };
67
- export {
68
- libcurl
69
+ push('CURLcode ret = curl_easy_perform(hnd);');
70
+ return join();
71
+ },
69
72
  };
70
- //# sourceMappingURL=client.js.map
@@ -1,175 +1,186 @@
1
- import { CodeBuilder } from "../../../../httpsnippet-lite/helpers/code-builder.js";
2
- import { getHeader, getHeaderName } from "../../../../httpsnippet-lite/helpers/headers.js";
1
+ /**
2
+ * @description
3
+ * HTTP code snippet generator for Clojure using clj-http.
4
+ *
5
+ * @author
6
+ * @tggreene
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 { getHeader, getHeaderName } from '../../../../httpsnippet-lite/helpers/headers.js';
3
12
  class Keyword {
4
- name;
5
- toString;
6
- constructor(name) {
7
- this.name = "";
8
- this.toString = () => `:${this.name}`;
9
- this.name = name;
10
- }
13
+ name;
14
+ toString;
15
+ constructor(name) {
16
+ this.name = '';
17
+ this.toString = () => `:${this.name}`;
18
+ this.name = name;
19
+ }
11
20
  }
12
21
  class File {
13
- path;
14
- toString;
15
- constructor(path) {
16
- this.path = "";
17
- this.toString = () => `(clojure.java.io/file "${this.path}")`;
18
- this.path = path;
19
- }
22
+ path;
23
+ toString;
24
+ constructor(path) {
25
+ this.path = '';
26
+ this.toString = () => `(clojure.java.io/file "${this.path}")`;
27
+ this.path = path;
28
+ }
20
29
  }
21
30
  const jsType = (input) => {
22
- if (input === void 0) {
23
- return null;
24
- }
25
- if (input === null) {
26
- return "null";
27
- }
28
- return input.constructor.name.toLowerCase();
31
+ if (input === undefined) {
32
+ return null;
33
+ }
34
+ if (input === null) {
35
+ return 'null';
36
+ }
37
+ return input.constructor.name.toLowerCase();
29
38
  };
30
39
  const objEmpty = (input) => {
31
- if (jsType(input) === "object") {
32
- return Object.keys(input).length === 0;
33
- }
34
- return false;
40
+ if (jsType(input) === 'object') {
41
+ return Object.keys(input).length === 0;
42
+ }
43
+ return false;
35
44
  };
36
45
  const filterEmpty = (input) => {
37
- Object.keys(input).filter((x) => objEmpty(input[x])).forEach((x) => {
38
- delete input[x];
39
- });
40
- return input;
46
+ Object.keys(input)
47
+ .filter((x) => objEmpty(input[x]))
48
+ .forEach((x) => {
49
+ delete input[x];
50
+ });
51
+ return input;
41
52
  };
42
53
  const padBlock = (padSize, input) => {
43
- const padding = " ".repeat(padSize);
44
- return input.replace(/\n/g, `
45
- ${padding}`);
54
+ const padding = ' '.repeat(padSize);
55
+ return input.replace(/\n/g, `\n${padding}`);
46
56
  };
47
57
  const jsToEdn = (js) => {
48
- switch (jsType(js)) {
49
- case "string":
50
- return `"${js.replace(/"/g, '\\"')}"`;
51
- case "file":
52
- return js.toString();
53
- case "keyword":
54
- return js.toString();
55
- case "null":
56
- return "nil";
57
- case "regexp":
58
- return `#"${js.source}"`;
59
- case "object": {
60
- const obj = Object.keys(js).reduce((accumulator, key) => {
61
- const val = padBlock(key.length + 2, jsToEdn(js[key]));
62
- return `${accumulator}:${key} ${val}
63
- `;
64
- }, "").trim();
65
- return `{${padBlock(1, obj)}}`;
66
- }
67
- case "array": {
68
- const arr = js.reduce((accumulator, value) => `${accumulator} ${jsToEdn(value)}`, "").trim();
69
- return `[${padBlock(1, arr)}]`;
58
+ switch (jsType(js)) {
59
+ case 'string':
60
+ return `"${js.replace(/"/g, '\\"')}"`;
61
+ case 'file':
62
+ return js.toString();
63
+ case 'keyword':
64
+ return js.toString();
65
+ case 'null':
66
+ return 'nil';
67
+ case 'regexp':
68
+ return `#"${js.source}"`;
69
+ case 'object': {
70
+ // simple vertical format
71
+ const obj = Object.keys(js)
72
+ .reduce((accumulator, key) => {
73
+ const val = padBlock(key.length + 2, jsToEdn(js[key]));
74
+ return `${accumulator}:${key} ${val}\n `;
75
+ }, '')
76
+ .trim();
77
+ return `{${padBlock(1, obj)}}`;
78
+ }
79
+ case 'array': {
80
+ // simple horizontal format
81
+ const arr = js.reduce((accumulator, value) => `${accumulator} ${jsToEdn(value)}`, '').trim();
82
+ return `[${padBlock(1, arr)}]`;
83
+ }
84
+ default: // 'number' 'boolean'
85
+ return js.toString();
70
86
  }
71
- default:
72
- return js.toString();
73
- }
74
87
  };
75
- const clj_http = {
76
- info: {
77
- key: "clj_http",
78
- title: "clj-http",
79
- link: "https://github.com/dakrone/clj-http",
80
- description: "An idiomatic clojure http client wrapping the apache client."
81
- },
82
- convert: ({ queryObj, method, postData, url, allHeaders }, options) => {
83
- const { push, join } = new CodeBuilder({
84
- indent: options === null || options === void 0 ? void 0 : options.indent
85
- });
86
- const methods = ["get", "post", "put", "delete", "patch", "head", "options"];
87
- method = method.toLowerCase();
88
- if (!methods.includes(method)) {
89
- push("Method not supported");
90
- return join();
91
- }
92
- const params = {
93
- "headers": allHeaders,
94
- "query-params": queryObj
95
- };
96
- if (queryObj && Object.keys(queryObj).length > 0) {
97
- url = url.split("?")[0];
98
- }
99
- switch (postData === null || postData === void 0 ? void 0 : postData.mimeType) {
100
- case "application/json":
101
- {
102
- params["content-type"] = new Keyword("json");
103
- params["form-params"] = postData.jsonObj;
104
- const header = getHeaderName(params.headers, "content-type");
105
- if (header) {
106
- delete params.headers[header];
107
- }
108
- }
109
- break;
110
- case "application/x-www-form-urlencoded":
111
- {
112
- params["form-params"] = postData.paramsObj;
113
- const header = getHeaderName(params.headers, "content-type");
114
- if (header) {
115
- delete params.headers[header];
116
- }
88
+ export const clj_http = {
89
+ info: {
90
+ key: 'clj_http',
91
+ title: 'clj-http',
92
+ link: 'https://github.com/dakrone/clj-http',
93
+ description: 'An idiomatic clojure http client wrapping the apache client.',
94
+ },
95
+ convert: ({ queryObj, method, postData, url, allHeaders }, options) => {
96
+ const { push, join } = new CodeBuilder({
97
+ indent: options === null || options === void 0 ? void 0 : options.indent,
98
+ });
99
+ const methods = ['get', 'post', 'put', 'delete', 'patch', 'head', 'options'];
100
+ method = method.toLowerCase();
101
+ if (!methods.includes(method)) {
102
+ push('Method not supported');
103
+ return join();
117
104
  }
118
- break;
119
- case "text/plain":
120
- {
121
- params.body = postData.text;
122
- const header = getHeaderName(params.headers, "content-type");
123
- if (header) {
124
- delete params.headers[header];
125
- }
105
+ const params = {
106
+ 'headers': allHeaders,
107
+ 'query-params': queryObj,
108
+ };
109
+ // Remove query string from URL if queryObj has parameters
110
+ if (queryObj && Object.keys(queryObj).length > 0) {
111
+ url = url.split('?')[0];
126
112
  }
127
- break;
128
- case "multipart/form-data": {
129
- if (postData?.params) {
130
- params.multipart = postData.params.map((param) => {
131
- if (param.fileName && !param.value) {
132
- return {
133
- name: param.name,
134
- content: new File(param.fileName)
135
- };
113
+ switch (postData === null || postData === void 0 ? void 0 : postData.mimeType) {
114
+ case 'application/json':
115
+ {
116
+ params['content-type'] = new Keyword('json');
117
+ params['form-params'] = postData.jsonObj;
118
+ const header = getHeaderName(params.headers, 'content-type');
119
+ if (header) {
120
+ delete params.headers[header];
121
+ }
122
+ }
123
+ break;
124
+ case 'application/x-www-form-urlencoded':
125
+ {
126
+ params['form-params'] = postData.paramsObj;
127
+ const header = getHeaderName(params.headers, 'content-type');
128
+ if (header) {
129
+ delete params.headers[header];
130
+ }
131
+ }
132
+ break;
133
+ case 'text/plain':
134
+ {
135
+ params.body = postData.text;
136
+ const header = getHeaderName(params.headers, 'content-type');
137
+ if (header) {
138
+ delete params.headers[header];
139
+ }
140
+ }
141
+ break;
142
+ case 'multipart/form-data': {
143
+ if (postData?.params) {
144
+ params.multipart = postData.params.map((param) => {
145
+ if (param.fileName && !param.value) {
146
+ return {
147
+ name: param.name,
148
+ content: new File(param.fileName),
149
+ };
150
+ }
151
+ return {
152
+ name: param.name,
153
+ content: param.value,
154
+ };
155
+ });
156
+ const header = getHeaderName(params.headers, 'content-type');
157
+ if (header) {
158
+ delete params.headers[header];
159
+ }
160
+ }
161
+ break;
136
162
  }
137
- return {
138
- name: param.name,
139
- content: param.value
140
- };
141
- });
142
- const header = getHeaderName(params.headers, "content-type");
143
- if (header) {
144
- delete params.headers[header];
145
- }
146
163
  }
147
- break;
148
- }
149
- }
150
- switch (getHeader(params.headers, "accept")) {
151
- case "application/json":
152
- {
153
- params.accept = new Keyword("json");
154
- const header = getHeaderName(params.headers, "accept");
155
- if (header) {
156
- delete params.headers[header];
157
- }
164
+ switch (getHeader(params.headers, 'accept')) {
165
+ case 'application/json':
166
+ {
167
+ params.accept = new Keyword('json');
168
+ const header = getHeaderName(params.headers, 'accept');
169
+ if (header) {
170
+ delete params.headers[header];
171
+ }
172
+ }
173
+ break;
158
174
  }
159
- break;
160
- }
161
- push("(require '[clj-http.client :as client])\n");
162
- if (objEmpty(filterEmpty(params))) {
163
- push(`(client/${method} "${url}")`);
164
- } else {
165
- const padding = 11 + method.length + url.length;
166
- const formattedParams = padBlock(padding, jsToEdn(filterEmpty(params)));
167
- push(`(client/${method} "${url}" ${formattedParams})`);
168
- }
169
- return join();
170
- }
171
- };
172
- export {
173
- clj_http
175
+ push("(require '[clj-http.client :as client])\n");
176
+ if (objEmpty(filterEmpty(params))) {
177
+ push(`(client/${method} "${url}")`);
178
+ }
179
+ else {
180
+ const padding = 11 + method.length + url.length;
181
+ const formattedParams = padBlock(padding, jsToEdn(filterEmpty(params)));
182
+ push(`(client/${method} "${url}" ${formattedParams})`);
183
+ }
184
+ return join();
185
+ },
174
186
  };
175
- //# sourceMappingURL=client.js.map
@@ -1,39 +1,36 @@
1
- import { CodeBuilder } from "../../../../httpsnippet-lite/helpers/code-builder.js";
2
- import { escapeForDoubleQuotes } from "../../../../httpsnippet-lite/helpers/escape.js";
3
- import { getHeader } from "../../../../httpsnippet-lite/helpers/headers.js";
4
- const restsharp = {
5
- info: {
6
- key: "restsharp",
7
- title: "RestSharp",
8
- link: "http://restsharp.org/",
9
- description: "Simple REST and HTTP API Client for .NET"
10
- },
11
- convert: ({ allHeaders, method, fullUrl, headersObj, cookies, postData }) => {
12
- const { push, join } = new CodeBuilder();
13
- const isSupportedMethod = ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"].includes(
14
- method.toUpperCase()
15
- );
16
- if (!isSupportedMethod) {
17
- return "Method not supported";
18
- }
19
- push(`var client = new RestClient("${fullUrl}");`);
20
- push(`var request = new RestRequest(Method.${method.toUpperCase()});`);
21
- Object.keys(headersObj).forEach((key) => {
22
- push(`request.AddHeader("${key}", "${escapeForDoubleQuotes(headersObj[key])}");`);
23
- });
24
- cookies === null || cookies === void 0 ? void 0 : cookies.forEach(({ name, value }) => {
25
- push(`request.AddCookie("${name}", "${value}");`);
26
- });
27
- if (postData === null || postData === void 0 ? void 0 : postData.text) {
28
- const header = getHeader(allHeaders, "content-type");
29
- const text = JSON.stringify(postData.text);
30
- push(`request.AddParameter("${header}", ${text}, ParameterType.RequestBody);`);
31
- }
32
- push("IRestResponse response = client.Execute(request);");
33
- return join();
34
- }
1
+ import { CodeBuilder } from '../../../../httpsnippet-lite/helpers/code-builder.js';
2
+ import { escapeForDoubleQuotes } from '../../../../httpsnippet-lite/helpers/escape.js';
3
+ import { getHeader } from '../../../../httpsnippet-lite/helpers/headers.js';
4
+ export const restsharp = {
5
+ info: {
6
+ key: 'restsharp',
7
+ title: 'RestSharp',
8
+ link: 'http://restsharp.org/',
9
+ description: 'Simple REST and HTTP API Client for .NET',
10
+ },
11
+ convert: ({ allHeaders, method, fullUrl, headersObj, cookies, postData }) => {
12
+ const { push, join } = new CodeBuilder();
13
+ const isSupportedMethod = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'].includes(method.toUpperCase());
14
+ if (!isSupportedMethod) {
15
+ return 'Method not supported';
16
+ }
17
+ push(`var client = new RestClient("${fullUrl}");`);
18
+ push(`var request = new RestRequest(Method.${method.toUpperCase()});`);
19
+ // Add headers, including the cookies
20
+ Object.keys(headersObj).forEach((key) => {
21
+ push(`request.AddHeader("${key}", "${escapeForDoubleQuotes(headersObj[key])}");`);
22
+ });
23
+ cookies === null || cookies === void 0
24
+ ? void 0
25
+ : cookies.forEach(({ name, value }) => {
26
+ push(`request.AddCookie("${name}", "${value}");`);
27
+ });
28
+ if (postData === null || postData === void 0 ? void 0 : postData.text) {
29
+ const header = getHeader(allHeaders, 'content-type');
30
+ const text = JSON.stringify(postData.text);
31
+ push(`request.AddParameter("${header}", ${text}, ParameterType.RequestBody);`);
32
+ }
33
+ push('IRestResponse response = client.Execute(request);');
34
+ return join();
35
+ },
35
36
  };
36
- export {
37
- restsharp
38
- };
39
- //# sourceMappingURL=client.js.map