@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
package/dist/libs/php.js
CHANGED
|
@@ -1,57 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a consistent indentation string based on the specified indentation level.
|
|
3
|
+
*/
|
|
1
4
|
function indent(level) {
|
|
2
|
-
|
|
5
|
+
return ' '.repeat(level * 2);
|
|
3
6
|
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Represents a raw PHP code that should not be quoted, e.g. `fopen('test.txt', 'r')`.
|
|
9
|
+
* If it consists of multiple lines, they will be indented properly.
|
|
10
|
+
*/
|
|
11
|
+
export class Raw {
|
|
12
|
+
value;
|
|
13
|
+
constructor(value) {
|
|
14
|
+
this.value = value;
|
|
15
|
+
}
|
|
8
16
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Converts a JavaScript object or value into a PHP array or scalar string representation.
|
|
19
|
+
* Handles nested arrays and objects, proper string escaping, and preserves indentation for readability.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* objectToString({ foo: 'bar', baz: 'qux' }) // => "['foo' => 'bar', 'baz' => 'qux']"
|
|
23
|
+
*/
|
|
24
|
+
export function objectToString(data, level = 0) {
|
|
25
|
+
if (data === null || data === undefined) {
|
|
26
|
+
return 'null';
|
|
27
|
+
}
|
|
28
|
+
if (data instanceof Raw) {
|
|
29
|
+
const lines = data.value.split('\n');
|
|
30
|
+
if (lines.length > 1) {
|
|
31
|
+
const innerIndentation = indent(level + 1);
|
|
32
|
+
return lines
|
|
33
|
+
.map((line, index) => {
|
|
34
|
+
if (index === 0) {
|
|
35
|
+
return line;
|
|
36
|
+
}
|
|
37
|
+
return `${innerIndentation}${line}`;
|
|
38
|
+
})
|
|
39
|
+
.join('\n');
|
|
20
40
|
}
|
|
21
|
-
return
|
|
22
|
-
|
|
41
|
+
return data.value;
|
|
42
|
+
}
|
|
43
|
+
if (typeof data === 'string') {
|
|
44
|
+
return `'${data.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`;
|
|
23
45
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (typeof data === "string") {
|
|
27
|
-
return `'${data.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
|
|
28
|
-
}
|
|
29
|
-
if (typeof data === "number" || typeof data === "boolean") {
|
|
30
|
-
return String(data);
|
|
31
|
-
}
|
|
32
|
-
if (Array.isArray(data)) {
|
|
33
|
-
if (data.length === 0) {
|
|
34
|
-
return "[]";
|
|
46
|
+
if (typeof data === 'number' || typeof data === 'boolean') {
|
|
47
|
+
return String(data);
|
|
35
48
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
|
|
49
|
+
if (Array.isArray(data)) {
|
|
50
|
+
if (data.length === 0) {
|
|
51
|
+
return '[]';
|
|
52
|
+
}
|
|
53
|
+
const items = data.map((item) => objectToString(item, level + 1)).join(',\n' + indent(level + 1));
|
|
54
|
+
return `[\n${indent(level + 1)}${items}\n${indent(level)}]`;
|
|
55
|
+
}
|
|
56
|
+
if (typeof data === 'object') {
|
|
57
|
+
const entries = Object.entries(data);
|
|
58
|
+
if (entries.length === 0) {
|
|
59
|
+
return '[]';
|
|
60
|
+
}
|
|
61
|
+
const items = entries
|
|
62
|
+
.map(([key, value]) => `'${key}' => ${objectToString(value, level + 1)}`)
|
|
63
|
+
.join(',\n' + indent(level + 1));
|
|
64
|
+
return `[\n${indent(level + 1)}${items}\n${indent(level)}]`;
|
|
45
65
|
}
|
|
46
|
-
|
|
47
|
-
return `[
|
|
48
|
-
${indent(level + 1)}${items}
|
|
49
|
-
${indent(level)}]`;
|
|
50
|
-
}
|
|
51
|
-
return "null";
|
|
66
|
+
return 'null';
|
|
52
67
|
}
|
|
53
|
-
export {
|
|
54
|
-
Raw,
|
|
55
|
-
objectToString
|
|
56
|
-
};
|
|
57
|
-
//# sourceMappingURL=php.js.map
|
package/dist/libs/rust.js
CHANGED
|
@@ -1,39 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escapes a string for use in Rust string literals
|
|
3
|
+
* Handles quotes, backslashes, newlines, and other special characters
|
|
4
|
+
*/
|
|
1
5
|
function escapeString(str) {
|
|
2
|
-
|
|
6
|
+
return str
|
|
7
|
+
.replace(/\\/g, '\\\\') // Escape backslashes first
|
|
8
|
+
.replace(/"/g, '\\"') // Escape double quotes
|
|
9
|
+
.replace(/\n/g, '\\n') // Escape newlines
|
|
10
|
+
.replace(/\r/g, '\\r') // Escape carriage returns
|
|
11
|
+
.replace(/\t/g, '\\t') // Escape tabs
|
|
12
|
+
.replace(/\0/g, '\\0'); // Escape null bytes
|
|
3
13
|
}
|
|
4
|
-
|
|
5
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Formats and escapes a string safely for use in Rust string literals.
|
|
16
|
+
* The returned value is the escaped string, surrounded by double quotes,
|
|
17
|
+
* making it ready for direct insertion into Rust source code.
|
|
18
|
+
*/
|
|
19
|
+
export function wrapInDoubleQuotes(str) {
|
|
20
|
+
return `"${escapeString(str)}"`;
|
|
6
21
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Produces an indented string using 4 spaces per indent level,
|
|
24
|
+
* in accordance with rustfmt style guidelines.
|
|
25
|
+
* Useful for code generation scenarios requiring precise formatting.
|
|
26
|
+
*/
|
|
27
|
+
export function indent(level, text) {
|
|
28
|
+
const spaces = ' '.repeat(level * 4);
|
|
29
|
+
return `${spaces}${text}`;
|
|
10
30
|
}
|
|
11
|
-
|
|
12
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Formats a Rust chained method call with standard 4-space indentation.
|
|
33
|
+
* Useful for fluent API or builder patterns in generated Rust code.
|
|
34
|
+
*/
|
|
35
|
+
export function createChain(method, ...args) {
|
|
36
|
+
return indent(1, `.${method}(${args.join(', ')})`);
|
|
13
37
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Properly formats a JSON snippet for Rust's `serde_json::json!` macro,
|
|
40
|
+
* applying idiomatic 4-space indentation to each line for improved readability.
|
|
41
|
+
*/
|
|
42
|
+
export function formatJson(jsonText) {
|
|
43
|
+
try {
|
|
44
|
+
const jsonData = JSON.parse(jsonText);
|
|
45
|
+
const prettyJson = JSON.stringify(jsonData, null, 4);
|
|
46
|
+
// Split into lines and add proper indentation for Rust
|
|
47
|
+
const lines = prettyJson.split('\n');
|
|
48
|
+
const rustLines = lines.map((line, index) => {
|
|
49
|
+
if (index === 0) {
|
|
50
|
+
// First line (opening brace)
|
|
51
|
+
return line;
|
|
52
|
+
}
|
|
53
|
+
if (index === lines.length - 1) {
|
|
54
|
+
// Last line (closing brace)
|
|
55
|
+
return indent(1, line);
|
|
56
|
+
}
|
|
57
|
+
// Middle lines
|
|
58
|
+
return indent(1, line);
|
|
59
|
+
});
|
|
60
|
+
return rustLines.join('\n');
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// If JSON parsing fails, return the original text
|
|
64
|
+
return jsonText;
|
|
65
|
+
}
|
|
32
66
|
}
|
|
33
|
-
export {
|
|
34
|
-
createChain,
|
|
35
|
-
formatJson,
|
|
36
|
-
indent,
|
|
37
|
-
wrapInDoubleQuotes
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=rust.js.map
|
package/dist/libs/shell.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Escapes single quotes in a string for safe use inside bash single-quoted strings.
|
|
3
|
+
* In bash, you cannot directly escape a single quote inside single quotes (i.e., 'hell\'o' is invalid).
|
|
4
|
+
* Instead, you must close the single quotes, insert an escaped single quote, then reopen the single quotes:
|
|
5
|
+
*
|
|
6
|
+
* ```bash
|
|
7
|
+
* 'hell'\''o'
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* This is why escaping a single quote in bash is not as simple as just using a backslash (\' does not work).
|
|
11
|
+
*
|
|
12
|
+
* @example "hell'o" becomes "hell'\''o"
|
|
13
|
+
*/
|
|
14
|
+
export const escapeSingleQuotes = (value) => value.replace(/'/g, "'\\''");
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { libcurl } from
|
|
2
|
-
import { convertWithHttpSnippetLite } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { libcurl } from '../../../httpsnippet-lite/targets/c/libcurl/client.js';
|
|
2
|
+
import { convertWithHttpSnippetLite } from '../../../utils/convertWithHttpSnippetLite.js';
|
|
3
|
+
/**
|
|
4
|
+
* c/libcurl
|
|
5
|
+
*/
|
|
6
|
+
export const cLibcurl = {
|
|
7
|
+
target: 'c',
|
|
8
|
+
client: 'libcurl',
|
|
9
|
+
title: 'Libcurl',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// TODO: Write an own converter
|
|
12
|
+
return convertWithHttpSnippetLite(libcurl, request);
|
|
13
|
+
},
|
|
10
14
|
};
|
|
11
|
-
export {
|
|
12
|
-
cLibcurl
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=libcurl.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { clj_http } from
|
|
2
|
-
import { convertWithHttpSnippetLite } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { clj_http } from '../../../httpsnippet-lite/targets/clojure/clj_http/client.js';
|
|
2
|
+
import { convertWithHttpSnippetLite } from '../../../utils/convertWithHttpSnippetLite.js';
|
|
3
|
+
/**
|
|
4
|
+
* clojure/clj_http
|
|
5
|
+
*/
|
|
6
|
+
export const clojureCljhttp = {
|
|
7
|
+
target: 'clojure',
|
|
8
|
+
client: 'clj_http',
|
|
9
|
+
title: 'clj-http',
|
|
10
|
+
generate(request) {
|
|
11
|
+
// TODO: Write an own converter
|
|
12
|
+
return convertWithHttpSnippetLite(clj_http, request);
|
|
13
|
+
},
|
|
10
14
|
};
|
|
11
|
-
export {
|
|
12
|
-
clojureCljhttp
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=clj_http.js.map
|