@scalar/snippetz 0.2.6 → 0.2.8

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 (214) hide show
  1. package/dist/_virtual/client.js +133 -0
  2. package/dist/_virtual/client10.js +121 -0
  3. package/dist/_virtual/client11.js +128 -0
  4. package/dist/_virtual/client12.js +64 -0
  5. package/dist/_virtual/client13.js +128 -0
  6. package/dist/_virtual/client14.js +71 -0
  7. package/dist/_virtual/client15.js +81 -0
  8. package/dist/_virtual/client16.js +76 -0
  9. package/dist/_virtual/client17.js +81 -0
  10. package/dist/_virtual/client18.js +87 -0
  11. package/dist/_virtual/client19.js +45 -0
  12. package/dist/_virtual/client2.js +52 -0
  13. package/dist/_virtual/client20.js +44 -0
  14. package/dist/_virtual/client21.js +71 -0
  15. package/dist/_virtual/client22.js +45 -0
  16. package/dist/_virtual/client23.js +71 -0
  17. package/dist/_virtual/client24.js +122 -0
  18. package/dist/_virtual/client25.js +37 -0
  19. package/dist/_virtual/client26.js +154 -0
  20. package/dist/_virtual/client27.js +181 -0
  21. package/dist/_virtual/client28.js +43 -0
  22. package/dist/_virtual/client3.js +113 -0
  23. package/dist/_virtual/client4.js +70 -0
  24. package/dist/_virtual/client5.js +123 -0
  25. package/dist/_virtual/client6.js +166 -0
  26. package/dist/_virtual/client7.js +91 -0
  27. package/dist/_virtual/client8.js +13 -0
  28. package/dist/_virtual/client9.js +13 -0
  29. package/dist/core/types.d.ts +29 -1
  30. package/dist/core/types.d.ts.map +1 -1
  31. package/dist/core/utils/convertWithHttpSnippetLite.d.ts +7 -0
  32. package/dist/core/utils/convertWithHttpSnippetLite.d.ts.map +1 -0
  33. package/dist/core/utils/convertWithHttpSnippetLite.js +83 -0
  34. package/dist/httpsnippet-lite/dist/esm/helpers/code-builder.js +60 -0
  35. package/dist/httpsnippet-lite/dist/esm/helpers/escape.js +72 -0
  36. package/dist/httpsnippet-lite/dist/esm/helpers/headers.js +20 -0
  37. package/dist/httpsnippet-lite/dist/esm/helpers/shell.js +16 -0
  38. package/dist/httpsnippet-lite/dist/esm/targets/objc/helpers.js +56 -0
  39. package/dist/httpsnippet-lite/dist/esm/targets/php/helpers.js +35 -0
  40. package/dist/httpsnippet-lite/dist/esm/targets/powershell/common.js +51 -0
  41. package/dist/httpsnippet-lite/dist/esm/targets/python/helpers.js +61 -0
  42. package/dist/httpsnippet-lite/dist/esm/targets/swift/helpers.js +74 -0
  43. package/dist/plugins/c/libcurl/index.d.ts +2 -0
  44. package/dist/plugins/c/libcurl/index.d.ts.map +1 -0
  45. package/dist/plugins/c/libcurl/index.js +1 -0
  46. package/dist/plugins/c/libcurl/libcurl.d.ts +6 -0
  47. package/dist/plugins/c/libcurl/libcurl.d.ts.map +1 -0
  48. package/dist/plugins/c/libcurl/libcurl.js +16 -0
  49. package/dist/plugins/clojure/clj_http/clj_http.d.ts +6 -0
  50. package/dist/plugins/clojure/clj_http/clj_http.d.ts.map +1 -0
  51. package/dist/plugins/clojure/clj_http/clj_http.js +16 -0
  52. package/dist/plugins/clojure/clj_http/index.d.ts +2 -0
  53. package/dist/plugins/clojure/clj_http/index.d.ts.map +1 -0
  54. package/dist/plugins/clojure/clj_http/index.js +1 -0
  55. package/dist/plugins/csharp/httpclient/httpclient.d.ts +6 -0
  56. package/dist/plugins/csharp/httpclient/httpclient.d.ts.map +1 -0
  57. package/dist/plugins/csharp/httpclient/httpclient.js +16 -0
  58. package/dist/plugins/csharp/httpclient/index.d.ts +2 -0
  59. package/dist/plugins/csharp/httpclient/index.d.ts.map +1 -0
  60. package/dist/plugins/csharp/httpclient/index.js +1 -0
  61. package/dist/plugins/csharp/restsharp/index.d.ts +2 -0
  62. package/dist/plugins/csharp/restsharp/index.d.ts.map +1 -0
  63. package/dist/plugins/csharp/restsharp/index.js +1 -0
  64. package/dist/plugins/csharp/restsharp/restsharp.d.ts +6 -0
  65. package/dist/plugins/csharp/restsharp/restsharp.d.ts.map +1 -0
  66. package/dist/plugins/csharp/restsharp/restsharp.js +16 -0
  67. package/dist/plugins/go/native/index.d.ts +2 -0
  68. package/dist/plugins/go/native/index.d.ts.map +1 -0
  69. package/dist/plugins/go/native/index.js +1 -0
  70. package/dist/plugins/go/native/native.d.ts +6 -0
  71. package/dist/plugins/go/native/native.d.ts.map +1 -0
  72. package/dist/plugins/go/native/native.js +16 -0
  73. package/dist/plugins/http/http11/http11.d.ts +6 -0
  74. package/dist/plugins/http/http11/http11.d.ts.map +1 -0
  75. package/dist/plugins/http/http11/http11.js +16 -0
  76. package/dist/plugins/http/http11/index.d.ts +2 -0
  77. package/dist/plugins/http/http11/index.d.ts.map +1 -0
  78. package/dist/plugins/http/http11/index.js +1 -0
  79. package/dist/plugins/java/asynchttp/asynchttp.d.ts +6 -0
  80. package/dist/plugins/java/asynchttp/asynchttp.d.ts.map +1 -0
  81. package/dist/plugins/java/asynchttp/asynchttp.js +16 -0
  82. package/dist/plugins/java/asynchttp/index.d.ts +2 -0
  83. package/dist/plugins/java/asynchttp/index.d.ts.map +1 -0
  84. package/dist/plugins/java/asynchttp/index.js +1 -0
  85. package/dist/plugins/java/nethttp/index.d.ts +2 -0
  86. package/dist/plugins/java/nethttp/index.d.ts.map +1 -0
  87. package/dist/plugins/java/nethttp/index.js +1 -0
  88. package/dist/plugins/java/nethttp/nethttp.d.ts +6 -0
  89. package/dist/plugins/java/nethttp/nethttp.d.ts.map +1 -0
  90. package/dist/plugins/java/nethttp/nethttp.js +16 -0
  91. package/dist/plugins/java/okhttp/index.d.ts +2 -0
  92. package/dist/plugins/java/okhttp/index.d.ts.map +1 -0
  93. package/dist/plugins/java/okhttp/index.js +1 -0
  94. package/dist/plugins/java/okhttp/okhttp.d.ts +6 -0
  95. package/dist/plugins/java/okhttp/okhttp.d.ts.map +1 -0
  96. package/dist/plugins/java/okhttp/okhttp.js +16 -0
  97. package/dist/plugins/java/unirest/index.d.ts +2 -0
  98. package/dist/plugins/java/unirest/index.d.ts.map +1 -0
  99. package/dist/plugins/java/unirest/index.js +1 -0
  100. package/dist/plugins/java/unirest/unirest.d.ts +6 -0
  101. package/dist/plugins/java/unirest/unirest.d.ts.map +1 -0
  102. package/dist/plugins/java/unirest/unirest.js +16 -0
  103. package/dist/plugins/js/axios/axios.d.ts +6 -0
  104. package/dist/plugins/js/axios/axios.d.ts.map +1 -0
  105. package/dist/plugins/js/axios/axios.js +16 -0
  106. package/dist/plugins/js/axios/index.d.ts +2 -0
  107. package/dist/plugins/js/axios/index.d.ts.map +1 -0
  108. package/dist/plugins/js/axios/index.js +1 -0
  109. package/dist/plugins/js/jquery/index.d.ts +2 -0
  110. package/dist/plugins/js/jquery/index.d.ts.map +1 -0
  111. package/dist/plugins/js/jquery/index.js +1 -0
  112. package/dist/plugins/js/jquery/jquery.d.ts +6 -0
  113. package/dist/plugins/js/jquery/jquery.d.ts.map +1 -0
  114. package/dist/plugins/js/jquery/jquery.js +16 -0
  115. package/dist/plugins/js/xhr/index.d.ts +2 -0
  116. package/dist/plugins/js/xhr/index.d.ts.map +1 -0
  117. package/dist/plugins/js/xhr/index.js +1 -0
  118. package/dist/plugins/js/xhr/xhr.d.ts +6 -0
  119. package/dist/plugins/js/xhr/xhr.d.ts.map +1 -0
  120. package/dist/plugins/js/xhr/xhr.js +16 -0
  121. package/dist/plugins/kotlin/okhttp/index.d.ts +2 -0
  122. package/dist/plugins/kotlin/okhttp/index.d.ts.map +1 -0
  123. package/dist/plugins/kotlin/okhttp/index.js +1 -0
  124. package/dist/plugins/kotlin/okhttp/okhttp.d.ts +6 -0
  125. package/dist/plugins/kotlin/okhttp/okhttp.d.ts.map +1 -0
  126. package/dist/plugins/kotlin/okhttp/okhttp.js +16 -0
  127. package/dist/plugins/node/axios/axios.d.ts +6 -0
  128. package/dist/plugins/node/axios/axios.d.ts.map +1 -0
  129. package/dist/plugins/node/axios/axios.js +16 -0
  130. package/dist/plugins/node/axios/index.d.ts +2 -0
  131. package/dist/plugins/node/axios/index.d.ts.map +1 -0
  132. package/dist/plugins/node/axios/index.js +1 -0
  133. package/dist/plugins/objc/nsurlsession/index.d.ts +2 -0
  134. package/dist/plugins/objc/nsurlsession/index.d.ts.map +1 -0
  135. package/dist/plugins/objc/nsurlsession/index.js +1 -0
  136. package/dist/plugins/objc/nsurlsession/nsurlsession.d.ts +6 -0
  137. package/dist/plugins/objc/nsurlsession/nsurlsession.d.ts.map +1 -0
  138. package/dist/plugins/objc/nsurlsession/nsurlsession.js +16 -0
  139. package/dist/plugins/ocaml/cohttp/cohttp.d.ts +6 -0
  140. package/dist/plugins/ocaml/cohttp/cohttp.d.ts.map +1 -0
  141. package/dist/plugins/ocaml/cohttp/cohttp.js +16 -0
  142. package/dist/plugins/ocaml/cohttp/index.d.ts +2 -0
  143. package/dist/plugins/ocaml/cohttp/index.d.ts.map +1 -0
  144. package/dist/plugins/ocaml/cohttp/index.js +1 -0
  145. package/dist/plugins/php/curl/curl.d.ts +6 -0
  146. package/dist/plugins/php/curl/curl.d.ts.map +1 -0
  147. package/dist/plugins/php/curl/curl.js +16 -0
  148. package/dist/plugins/php/curl/index.d.ts +2 -0
  149. package/dist/plugins/php/curl/index.d.ts.map +1 -0
  150. package/dist/plugins/php/curl/index.js +1 -0
  151. package/dist/plugins/php/guzzle/guzzle.d.ts +6 -0
  152. package/dist/plugins/php/guzzle/guzzle.d.ts.map +1 -0
  153. package/dist/plugins/php/guzzle/guzzle.js +16 -0
  154. package/dist/plugins/php/guzzle/index.d.ts +2 -0
  155. package/dist/plugins/php/guzzle/index.d.ts.map +1 -0
  156. package/dist/plugins/php/guzzle/index.js +1 -0
  157. package/dist/plugins/powershell/restmethod/index.d.ts +2 -0
  158. package/dist/plugins/powershell/restmethod/index.d.ts.map +1 -0
  159. package/dist/plugins/powershell/restmethod/index.js +1 -0
  160. package/dist/plugins/powershell/restmethod/restmethod.d.ts +6 -0
  161. package/dist/plugins/powershell/restmethod/restmethod.d.ts.map +1 -0
  162. package/dist/plugins/powershell/restmethod/restmethod.js +16 -0
  163. package/dist/plugins/powershell/webrequest/index.d.ts +2 -0
  164. package/dist/plugins/powershell/webrequest/index.d.ts.map +1 -0
  165. package/dist/plugins/powershell/webrequest/index.js +1 -0
  166. package/dist/plugins/powershell/webrequest/webrequest.d.ts +6 -0
  167. package/dist/plugins/powershell/webrequest/webrequest.d.ts.map +1 -0
  168. package/dist/plugins/powershell/webrequest/webrequest.js +16 -0
  169. package/dist/plugins/python/python3/index.d.ts +2 -0
  170. package/dist/plugins/python/python3/index.d.ts.map +1 -0
  171. package/dist/plugins/python/python3/index.js +1 -0
  172. package/dist/plugins/python/python3/python3.d.ts +6 -0
  173. package/dist/plugins/python/python3/python3.d.ts.map +1 -0
  174. package/dist/plugins/python/python3/python3.js +16 -0
  175. package/dist/plugins/python/requests/index.d.ts +2 -0
  176. package/dist/plugins/python/requests/index.d.ts.map +1 -0
  177. package/dist/plugins/python/requests/index.js +1 -0
  178. package/dist/plugins/python/requests/requests.d.ts +6 -0
  179. package/dist/plugins/python/requests/requests.d.ts.map +1 -0
  180. package/dist/plugins/python/requests/requests.js +16 -0
  181. package/dist/plugins/r/httr/httr.d.ts +6 -0
  182. package/dist/plugins/r/httr/httr.d.ts.map +1 -0
  183. package/dist/plugins/r/httr/httr.js +16 -0
  184. package/dist/plugins/r/httr/index.d.ts +2 -0
  185. package/dist/plugins/r/httr/index.d.ts.map +1 -0
  186. package/dist/plugins/r/httr/index.js +1 -0
  187. package/dist/plugins/ruby/native/index.d.ts +2 -0
  188. package/dist/plugins/ruby/native/index.d.ts.map +1 -0
  189. package/dist/plugins/ruby/native/index.js +1 -0
  190. package/dist/plugins/ruby/native/native.d.ts +6 -0
  191. package/dist/plugins/ruby/native/native.d.ts.map +1 -0
  192. package/dist/plugins/ruby/native/native.js +16 -0
  193. package/dist/plugins/shell/httpie/httpie.d.ts +6 -0
  194. package/dist/plugins/shell/httpie/httpie.d.ts.map +1 -0
  195. package/dist/plugins/shell/httpie/httpie.js +16 -0
  196. package/dist/plugins/shell/httpie/index.d.ts +2 -0
  197. package/dist/plugins/shell/httpie/index.d.ts.map +1 -0
  198. package/dist/plugins/shell/httpie/index.js +1 -0
  199. package/dist/plugins/shell/wget/index.d.ts +2 -0
  200. package/dist/plugins/shell/wget/index.d.ts.map +1 -0
  201. package/dist/plugins/shell/wget/index.js +1 -0
  202. package/dist/plugins/shell/wget/wget.d.ts +6 -0
  203. package/dist/plugins/shell/wget/wget.d.ts.map +1 -0
  204. package/dist/plugins/shell/wget/wget.js +16 -0
  205. package/dist/plugins/swift/nsurlsession/index.d.ts +2 -0
  206. package/dist/plugins/swift/nsurlsession/index.d.ts.map +1 -0
  207. package/dist/plugins/swift/nsurlsession/index.js +1 -0
  208. package/dist/plugins/swift/nsurlsession/nsurlsession.d.ts +6 -0
  209. package/dist/plugins/swift/nsurlsession/nsurlsession.d.ts.map +1 -0
  210. package/dist/plugins/swift/nsurlsession/nsurlsession.js +16 -0
  211. package/dist/snippetz.d.ts +4 -4
  212. package/dist/snippetz.d.ts.map +1 -1
  213. package/dist/snippetz.js +60 -4
  214. package/package.json +145 -1
@@ -0,0 +1,60 @@
1
+ const DEFAULT_INDENTATION_CHARACTER = '';
2
+ const DEFAULT_LINE_JOIN = '\n';
3
+ class CodeBuilder {
4
+ /**
5
+ * Helper object to format and aggragate lines of code.
6
+ * Lines are aggregated in a `code` array, and need to be joined to obtain a proper code snippet.
7
+ */
8
+ constructor({ indent, join } = {}) {
9
+ this.postProcessors = [];
10
+ this.code = [];
11
+ this.indentationCharacter = DEFAULT_INDENTATION_CHARACTER;
12
+ this.lineJoin = DEFAULT_LINE_JOIN;
13
+ /**
14
+ * Add given indentation level to given line of code
15
+ */
16
+ this.indentLine = (line, indentationLevel = 0) => {
17
+ const indent = this.indentationCharacter.repeat(indentationLevel);
18
+ return `${indent}${line}`;
19
+ };
20
+ /**
21
+ * Add the line at the beginning of the current lines
22
+ */
23
+ this.unshift = (line, indentationLevel) => {
24
+ const newLine = this.indentLine(line, indentationLevel);
25
+ this.code.unshift(newLine);
26
+ };
27
+ /**
28
+ * Add the line at the end of the current lines
29
+ */
30
+ this.push = (line, indentationLevel) => {
31
+ const newLine = this.indentLine(line, indentationLevel);
32
+ this.code.push(newLine);
33
+ };
34
+ /**
35
+ * Add an empty line at the end of current lines
36
+ */
37
+ this.blank = () => {
38
+ this.code.push('');
39
+ };
40
+ /**
41
+ * Concatenate all current lines using the given lineJoin, then apply any replacers that may have been added
42
+ */
43
+ this.join = () => {
44
+ const unreplacedCode = this.code.join(this.lineJoin);
45
+ const replacedOutput = this.postProcessors.reduce((accumulator, replacer) => replacer(accumulator), unreplacedCode);
46
+ return replacedOutput;
47
+ };
48
+ /**
49
+ * Often when writing modules you may wish to add a literal tag or bit of metadata that you wish to transform after other processing as a final step.
50
+ * To do so, you can provide a PostProcessor function and it will be run automatically for you when you call `join()` later on.
51
+ */
52
+ this.addPostProcessor = (postProcessor) => {
53
+ this.postProcessors = [...this.postProcessors, postProcessor];
54
+ };
55
+ this.indentationCharacter = indent || DEFAULT_INDENTATION_CHARACTER;
56
+ this.lineJoin = join !== null && join !== void 0 ? join : DEFAULT_LINE_JOIN;
57
+ }
58
+ }
59
+
60
+ export { CodeBuilder };
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Escape characters within a value to make it safe to insert directly into a
3
+ * snippet. Takes options which define the escape requirements.
4
+ *
5
+ * This is closely based on the JSON-stringify string serialization algorithm,
6
+ * but generalized for other string delimiters (e.g. " or ') and different escape
7
+ * characters (e.g. Powershell uses `)
8
+ *
9
+ * See https://tc39.es/ecma262/multipage/structured-data.html#sec-quotejsonstring
10
+ * for the complete original algorithm.
11
+ */
12
+ function escapeString(rawValue, options = {}) {
13
+ const { delimiter = '"', escapeChar = '\\', escapeNewlines = true } = options;
14
+ const stringValue = rawValue.toString();
15
+ return [...stringValue]
16
+ .map(c => {
17
+ if (c === '\b') {
18
+ return `${escapeChar}b`;
19
+ }
20
+ else if (c === '\t') {
21
+ return `${escapeChar}t`;
22
+ }
23
+ else if (c === '\n') {
24
+ if (escapeNewlines) {
25
+ return `${escapeChar}n`;
26
+ }
27
+ return c; // Don't just continue, or this is caught by < \u0020
28
+ }
29
+ else if (c === '\f') {
30
+ return `${escapeChar}f`;
31
+ }
32
+ else if (c === '\r') {
33
+ if (escapeNewlines) {
34
+ return `${escapeChar}r`;
35
+ }
36
+ return c; // Don't just continue, or this is caught by < \u0020
37
+ }
38
+ else if (c === escapeChar) {
39
+ return escapeChar + escapeChar;
40
+ }
41
+ else if (c === delimiter) {
42
+ return escapeChar + delimiter;
43
+ }
44
+ else if (c < '\u0020' || c > '\u007E') {
45
+ // Delegate the trickier non-ASCII cases to the normal algorithm. Some of these
46
+ // are escaped as \uXXXX, whilst others are represented literally. Since we're
47
+ // using this primarily for header values that are generally (though not 100%
48
+ // strictly?) ASCII-only, this should almost never happen.
49
+ return JSON.stringify(c).slice(1, -1);
50
+ }
51
+ return c;
52
+ })
53
+ .join('');
54
+ }
55
+ /**
56
+ * Make a string value safe to insert literally into a snippet within single quotes,
57
+ * by escaping problematic characters, including single quotes inside the string,
58
+ * backslashes, newlines, and other special characters.
59
+ *
60
+ * If value is not a string, it will be stringified with .toString() first.
61
+ */
62
+ const escapeForSingleQuotes = (value) => escapeString(value, { delimiter: "'" });
63
+ /**
64
+ * Make a string value safe to insert literally into a snippet within double quotes,
65
+ * by escaping problematic characters, including double quotes inside the string,
66
+ * backslashes, newlines, and other special characters.
67
+ *
68
+ * If value is not a string, it will be stringified with .toString() first.
69
+ */
70
+ const escapeForDoubleQuotes = (value) => escapeString(value, { delimiter: '"' });
71
+
72
+ export { escapeForDoubleQuotes, escapeForSingleQuotes, escapeString };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Given a headers object retrieve a specific header out of it via a case-insensitive key.
3
+ */
4
+ 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
+ const getHeader = (headers, name) => {
9
+ const headerName = getHeaderName(headers, name);
10
+ if (!headerName) {
11
+ return undefined;
12
+ }
13
+ return headers[headerName];
14
+ };
15
+ /**
16
+ * Determine if a given case-insensitive header exists within a header object.
17
+ */
18
+ const hasHeader = (headers, name) => Boolean(getHeaderName(headers, name));
19
+
20
+ export { getHeader, getHeaderName, hasHeader };
@@ -0,0 +1,16 @@
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
+ const quote = (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, "'\\''")}'`;
13
+ };
14
+ const escape = (value) => value.replace(/\r/g, '\\r').replace(/\n/g, '\\n');
15
+
16
+ export { escape, quote };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Create a string corresponding to a valid declaration and initialization of an Objective-C object literal.
3
+ *
4
+ * @param nsClass Class of the litteral
5
+ * @param name Desired name of the instance
6
+ * @param parameters Key-value object of parameters to translate to an Objective-C object litearal
7
+ * @param indent If true, will declare the litteral by indenting each new key/value pair.
8
+ * @return A valid Objective-C declaration and initialization of an Objective-C object litteral.
9
+ *
10
+ * @example
11
+ * nsDeclaration('NSDictionary', 'params', {a: 'b', c: 'd'}, true)
12
+ * // returns:
13
+ * NSDictionary *params = @{ @"a": @"b",
14
+ * @"c": @"d" };
15
+ *
16
+ * nsDeclaration('NSDictionary', 'params', {a: 'b', c: 'd'})
17
+ * // returns:
18
+ * NSDictionary *params = @{ @"a": @"b", @"c": @"d" };
19
+ */
20
+ const nsDeclaration = (nsClass, name, parameters, indent) => {
21
+ const opening = `${nsClass} *${name} = `;
22
+ const literal = literalRepresentation(parameters, indent ? opening.length : undefined);
23
+ return `${opening}${literal};`;
24
+ };
25
+ /**
26
+ * Create a valid Objective-C string of a literal value according to its type.
27
+ *
28
+ * @param value Any JavaScript literal
29
+ */
30
+ const literalRepresentation = (value, indentation) => {
31
+ const join = indentation === undefined ? ', ' : `,\n ${' '.repeat(indentation)}`;
32
+ switch (Object.prototype.toString.call(value)) {
33
+ case '[object Number]':
34
+ return `@${value}`;
35
+ case '[object Array]': {
36
+ const valuesRepresentation = value.map((value) => literalRepresentation(value));
37
+ return `@[ ${valuesRepresentation.join(join)} ]`;
38
+ }
39
+ case '[object Object]': {
40
+ const keyValuePairs = [];
41
+ for (const key in value) {
42
+ keyValuePairs.push(`@"${key}": ${literalRepresentation(value[key])}`);
43
+ }
44
+ return `@{ ${keyValuePairs.join(join)} }`;
45
+ }
46
+ case '[object Boolean]':
47
+ return value ? '@YES' : '@NO';
48
+ default:
49
+ if (value === null || value === undefined) {
50
+ return '';
51
+ }
52
+ return `@"${value.toString().replace(/"/g, '\\"')}"`;
53
+ }
54
+ };
55
+
56
+ export { literalRepresentation, nsDeclaration };
@@ -0,0 +1,35 @@
1
+ import { escapeString } from '../../helpers/escape.js';
2
+
3
+ const convertType = (obj, indent, lastIndent) => {
4
+ lastIndent = lastIndent || '';
5
+ indent = indent || '';
6
+ switch (Object.prototype.toString.call(obj)) {
7
+ case '[object Null]':
8
+ return 'null';
9
+ case '[object Undefined]':
10
+ return 'null';
11
+ case '[object String]':
12
+ return `'${escapeString(obj, { delimiter: "'", escapeNewlines: false })}'`;
13
+ case '[object Number]':
14
+ return obj.toString();
15
+ case '[object Array]': {
16
+ const contents = obj
17
+ .map((item) => convertType(item, `${indent}${indent}`, indent))
18
+ .join(`,\n${indent}`);
19
+ return `[\n${indent}${contents}\n${lastIndent}]`;
20
+ }
21
+ case '[object Object]': {
22
+ const result = [];
23
+ for (const i in obj) {
24
+ if (Object.prototype.hasOwnProperty.call(obj, i)) {
25
+ result.push(`${convertType(i, indent)} => ${convertType(obj[i], `${indent}${indent}`, indent)}`);
26
+ }
27
+ }
28
+ return `[\n${indent}${result.join(`,\n${indent}`)}\n${lastIndent}]`;
29
+ }
30
+ default:
31
+ return 'null';
32
+ }
33
+ };
34
+
35
+ export { convertType };
@@ -0,0 +1,51 @@
1
+ import { CodeBuilder } from '../../helpers/code-builder.js';
2
+ import { escapeString } from '../../helpers/escape.js';
3
+ import { getHeader } from '../../helpers/headers.js';
4
+
5
+ const generatePowershellConvert = (command) => {
6
+ const convert = ({ method, headersObj, cookies, uriObj, fullUrl, postData, allHeaders, }) => {
7
+ const { push, join } = new CodeBuilder();
8
+ const methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
9
+ if (!methods.includes(method.toUpperCase())) {
10
+ return 'Method not supported';
11
+ }
12
+ const commandOptions = [];
13
+ // Add headers, including the cookies
14
+ const headers = Object.keys(headersObj);
15
+ // construct headers
16
+ if (headers.length) {
17
+ push('$headers=@{}');
18
+ headers.forEach(key => {
19
+ if (key !== 'connection') {
20
+ // Not allowed
21
+ push(`$headers.Add("${key}", "${escapeString(headersObj[key], { escapeChar: '`' })}")`);
22
+ }
23
+ });
24
+ commandOptions.push('-Headers $headers');
25
+ }
26
+ // construct cookies
27
+ if (cookies.length) {
28
+ push('$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession');
29
+ cookies.forEach(cookie => {
30
+ push('$cookie = New-Object System.Net.Cookie');
31
+ push(`$cookie.Name = '${cookie.name}'`);
32
+ push(`$cookie.Value = '${cookie.value}'`);
33
+ push(`$cookie.Domain = '${uriObj.host}'`);
34
+ push('$session.Cookies.Add($cookie)');
35
+ });
36
+ commandOptions.push('-WebSession $session');
37
+ }
38
+ if (postData === null || postData === void 0 ? void 0 : postData.text) {
39
+ commandOptions.push(`-ContentType '${escapeString(getHeader(allHeaders, 'content-type'), {
40
+ delimiter: "'",
41
+ escapeChar: '`',
42
+ })}'`);
43
+ commandOptions.push(`-Body '${postData.text}'`);
44
+ }
45
+ push(`$response = ${command} -Uri '${fullUrl}' -Method ${method} ${commandOptions.join(' ')}`);
46
+ return join();
47
+ };
48
+ return convert;
49
+ };
50
+
51
+ export { generatePowershellConvert };
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Create a string corresponding to a Dictionary or Array literal representation with pretty option
3
+ * and indentation.
4
+ */
5
+ function concatValues(concatType, values, pretty, indentation, indentLevel) {
6
+ const currentIndent = indentation.repeat(indentLevel);
7
+ const closingBraceIndent = indentation.repeat(indentLevel - 1);
8
+ const join = pretty ? `,\n${currentIndent}` : ', ';
9
+ const openingBrace = concatType === 'object' ? '{' : '[';
10
+ const closingBrace = concatType === 'object' ? '}' : ']';
11
+ if (pretty) {
12
+ return `${openingBrace}\n${currentIndent}${values.join(join)}\n${closingBraceIndent}${closingBrace}`;
13
+ }
14
+ if (concatType === 'object' && values.length > 0) {
15
+ return `${openingBrace} ${values.join(join)} ${closingBrace}`;
16
+ }
17
+ return `${openingBrace}${values.join(join)}${closingBrace}`;
18
+ }
19
+ /**
20
+ * Create a valid Python string of a literal value according to its type.
21
+ *
22
+ * @param {*} value Any JavaScript literal
23
+ * @param {Object} opts Target options
24
+ * @return {string}
25
+ */
26
+ const literalRepresentation = (value, opts, indentLevel) => {
27
+ indentLevel = indentLevel === undefined ? 1 : indentLevel + 1;
28
+ switch (Object.prototype.toString.call(value)) {
29
+ case '[object Number]':
30
+ return value;
31
+ case '[object Array]': {
32
+ let pretty = false;
33
+ const valuesRepresentation = value.map(v => {
34
+ // Switch to prettify if the value is a dictionary with multiple keys
35
+ if (Object.prototype.toString.call(v) === '[object Object]') {
36
+ pretty = Object.keys(v).length > 1;
37
+ }
38
+ return literalRepresentation(v, opts, indentLevel);
39
+ });
40
+ return concatValues('array', valuesRepresentation, pretty, opts.indent, indentLevel);
41
+ }
42
+ case '[object Object]': {
43
+ const keyValuePairs = [];
44
+ for (const key in value) {
45
+ keyValuePairs.push(`"${key}": ${literalRepresentation(value[key], opts, indentLevel)}`);
46
+ }
47
+ return concatValues('object', keyValuePairs, opts.pretty && keyValuePairs.length > 1, opts.indent, indentLevel);
48
+ }
49
+ case '[object Null]':
50
+ return 'None';
51
+ case '[object Boolean]':
52
+ return value ? 'True' : 'False';
53
+ default:
54
+ if (value === null || value === undefined) {
55
+ return '';
56
+ }
57
+ return `"${value.toString().replace(/"/g, '\\"')}"`;
58
+ }
59
+ };
60
+
61
+ export { literalRepresentation };
@@ -0,0 +1,74 @@
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
+ */
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
+ */
11
+ const concatArray = (arr, pretty, indentation, indentLevel) => {
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)}]`;
19
+ };
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 litearal
25
+ * @param opts Target options
26
+ * @return {string}
27
+ */
28
+ 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
+ */
35
+ const literalRepresentation = (value, opts, indentLevel) => {
36
+ indentLevel = indentLevel === undefined ? 1 : indentLevel + 1;
37
+ switch (Object.prototype.toString.call(value)) {
38
+ case '[object Number]':
39
+ return value;
40
+ case '[object Array]': {
41
+ // Don't prettify arrays nto not take 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
+ // @ts-expect-error needs better types
51
+ return concatArray(valuesRepresentation, pretty, opts.indent, indentLevel);
52
+ }
53
+ case '[object Object]': {
54
+ const keyValuePairs = [];
55
+ for (const key in value) {
56
+ keyValuePairs.push(`"${key}": ${literalRepresentation(value[key], opts, indentLevel)}`);
57
+ }
58
+ return concatArray(keyValuePairs,
59
+ // @ts-expect-error needs better types
60
+ opts.pretty && keyValuePairs.length > 1,
61
+ // @ts-expect-error needs better types
62
+ opts.indent, indentLevel);
63
+ }
64
+ case '[object Boolean]':
65
+ return value.toString();
66
+ default:
67
+ if (value === null || value === undefined) {
68
+ return '';
69
+ }
70
+ return `"${value.toString().replace(/"/g, '\\"')}"`;
71
+ }
72
+ };
73
+
74
+ export { literalDeclaration, literalRepresentation };
@@ -0,0 +1,2 @@
1
+ export * from './libcurl.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/c/libcurl/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
@@ -0,0 +1 @@
1
+ export { cLibcurl } from './libcurl.js';
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from '../../../core/index.js';
2
+ /**
3
+ * c/libcurl
4
+ */
5
+ export declare const cLibcurl: Plugin;
6
+ //# sourceMappingURL=libcurl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libcurl.d.ts","sourceRoot":"","sources":["../../../../src/plugins/c/libcurl/libcurl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAKpC;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,MAOtB,CAAA"}
@@ -0,0 +1,16 @@
1
+ import { convertWithHttpSnippetLite } from '../../../core/utils/convertWithHttpSnippetLite.js';
2
+ import { libcurl } from '../../../_virtual/client28.js';
3
+
4
+ /**
5
+ * c/libcurl
6
+ */
7
+ const cLibcurl = {
8
+ target: 'c',
9
+ client: 'libcurl',
10
+ generate(request) {
11
+ // TODO: Write an own converter
12
+ return convertWithHttpSnippetLite(libcurl, request);
13
+ },
14
+ };
15
+
16
+ export { cLibcurl };
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from '../../../core/index.js';
2
+ /**
3
+ * clojure/clj_http
4
+ */
5
+ export declare const clojureCljhttp: Plugin;
6
+ //# sourceMappingURL=clj_http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clj_http.d.ts","sourceRoot":"","sources":["../../../../src/plugins/clojure/clj_http/clj_http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAKpC;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,MAO5B,CAAA"}
@@ -0,0 +1,16 @@
1
+ import { convertWithHttpSnippetLite } from '../../../core/utils/convertWithHttpSnippetLite.js';
2
+ import { clj_http } from '../../../_virtual/client27.js';
3
+
4
+ /**
5
+ * clojure/clj_http
6
+ */
7
+ const clojureCljhttp = {
8
+ target: 'clojure',
9
+ client: 'clj_http',
10
+ generate(request) {
11
+ // TODO: Write an own converter
12
+ return convertWithHttpSnippetLite(clj_http, request);
13
+ },
14
+ };
15
+
16
+ export { clojureCljhttp };
@@ -0,0 +1,2 @@
1
+ export * from './clj_http.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/clojure/clj_http/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA"}
@@ -0,0 +1 @@
1
+ export { clojureCljhttp } from './clj_http.js';
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from '../../../core/index.js';
2
+ /**
3
+ * csharp/httpclient
4
+ */
5
+ export declare const csharpHttpclient: Plugin;
6
+ //# sourceMappingURL=httpclient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpclient.d.ts","sourceRoot":"","sources":["../../../../src/plugins/csharp/httpclient/httpclient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAKpC;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,MAO9B,CAAA"}
@@ -0,0 +1,16 @@
1
+ import { convertWithHttpSnippetLite } from '../../../core/utils/convertWithHttpSnippetLite.js';
2
+ import { httpclient } from '../../../_virtual/client26.js';
3
+
4
+ /**
5
+ * csharp/httpclient
6
+ */
7
+ const csharpHttpclient = {
8
+ target: 'csharp',
9
+ client: 'httpclient',
10
+ generate(request) {
11
+ // TODO: Write an own converter
12
+ return convertWithHttpSnippetLite(httpclient, request);
13
+ },
14
+ };
15
+
16
+ export { csharpHttpclient };
@@ -0,0 +1,2 @@
1
+ export * from './httpclient.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/csharp/httpclient/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
@@ -0,0 +1 @@
1
+ export { csharpHttpclient } from './httpclient.js';
@@ -0,0 +1,2 @@
1
+ export * from './restsharp.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/csharp/restsharp/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
@@ -0,0 +1 @@
1
+ export { csharpRestsharp } from './restsharp.js';
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from '../../../core/index.js';
2
+ /**
3
+ * csharp/restsharp
4
+ */
5
+ export declare const csharpRestsharp: Plugin;
6
+ //# sourceMappingURL=restsharp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"restsharp.d.ts","sourceRoot":"","sources":["../../../../src/plugins/csharp/restsharp/restsharp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAKpC;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,MAO7B,CAAA"}
@@ -0,0 +1,16 @@
1
+ import { convertWithHttpSnippetLite } from '../../../core/utils/convertWithHttpSnippetLite.js';
2
+ import { restsharp } from '../../../_virtual/client25.js';
3
+
4
+ /**
5
+ * csharp/restsharp
6
+ */
7
+ const csharpRestsharp = {
8
+ target: 'csharp',
9
+ client: 'restsharp',
10
+ generate(request) {
11
+ // TODO: Write an own converter
12
+ return convertWithHttpSnippetLite(restsharp, request);
13
+ },
14
+ };
15
+
16
+ export { csharpRestsharp };
@@ -0,0 +1,2 @@
1
+ export * from './native.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/go/native/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
@@ -0,0 +1 @@
1
+ export { goNative } from './native.js';
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from '../../../core/index.js';
2
+ /**
3
+ * go/native
4
+ */
5
+ export declare const goNative: Plugin;
6
+ //# sourceMappingURL=native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../../../src/plugins/go/native/native.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAKpC;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,MAOtB,CAAA"}