@readme/httpsnippet 3.1.3 → 4.0.2
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/README.md +63 -62
- package/dist/package.json +86 -0
- package/dist/src/fixtures/customTarget.js +15 -0
- package/dist/src/fixtures/mimetypes.js +77 -0
- package/dist/src/fixtures/requests/application-form-encoded.js +69 -0
- package/dist/src/fixtures/requests/application-json.js +72 -0
- package/dist/src/fixtures/requests/cookies.js +51 -0
- package/dist/src/fixtures/requests/custom-method.js +41 -0
- package/dist/src/fixtures/requests/full.js +99 -0
- package/dist/src/fixtures/requests/headers.js +56 -0
- package/dist/src/fixtures/requests/http-insecure.js +45 -0
- package/dist/src/fixtures/requests/jsonObj-multiline.js +59 -0
- package/dist/src/fixtures/requests/jsonObj-null-value.js +61 -0
- package/dist/src/fixtures/requests/multipart-data.js +72 -0
- package/dist/src/fixtures/requests/multipart-file.js +65 -0
- package/dist/src/fixtures/requests/multipart-form-data-no-params.js +56 -0
- package/dist/src/fixtures/requests/multipart-form-data.js +64 -0
- package/dist/src/fixtures/requests/nested.js +64 -0
- package/dist/src/fixtures/requests/query-encoded.js +59 -0
- package/dist/src/fixtures/requests/query.js +64 -0
- package/dist/src/fixtures/requests/short.js +45 -0
- package/dist/src/fixtures/requests/text-plain.js +57 -0
- package/dist/src/fixtures/runCustomFixtures.js +77 -0
- package/dist/src/helpers/code-builder.js +91 -0
- package/dist/src/helpers/form-data.js +157 -0
- package/dist/src/helpers/har-validator.js +76 -0
- package/dist/src/helpers/headers.js +33 -0
- package/dist/src/helpers/reducer.js +19 -0
- package/dist/src/helpers/shell.js +20 -0
- package/dist/src/helpers/utils.js +21 -0
- package/dist/src/index.js +285 -0
- package/dist/src/targets/c/libcurl/client.js +43 -0
- package/dist/src/targets/c/target.js +15 -0
- package/dist/src/targets/clojure/clj_http/client.js +184 -0
- package/dist/src/targets/clojure/target.js +15 -0
- package/dist/src/targets/csharp/httpclient/client.js +162 -0
- package/dist/src/targets/csharp/restsharp/client.js +38 -0
- package/dist/src/targets/csharp/target.js +17 -0
- package/dist/src/targets/go/native/client.js +122 -0
- package/dist/src/targets/go/target.js +15 -0
- package/dist/src/targets/http/http1.1/client.js +79 -0
- package/dist/src/targets/http/target.js +15 -0
- package/dist/src/targets/java/asynchttp/client.js +53 -0
- package/dist/src/targets/java/nethttp/client.js +52 -0
- package/dist/src/targets/java/okhttp/client.js +79 -0
- package/dist/src/targets/java/target.js +21 -0
- package/dist/src/targets/java/unirest/client.js +53 -0
- package/dist/src/targets/javascript/axios/client.js +101 -0
- package/dist/src/targets/javascript/axios/fixtures/application-form-encoded.js +22 -0
- package/dist/src/targets/javascript/axios/fixtures/application-json.js +26 -0
- package/dist/src/targets/javascript/axios/fixtures/cookies.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/custom-method.js +14 -0
- package/dist/src/targets/javascript/axios/fixtures/full.js +26 -0
- package/dist/src/targets/javascript/axios/fixtures/headers.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/http-insecure.js +14 -0
- package/dist/src/targets/javascript/axios/fixtures/jsonObj-multiline.js +19 -0
- package/dist/src/targets/javascript/axios/fixtures/jsonObj-null-value.js +19 -0
- package/dist/src/targets/javascript/axios/fixtures/multipart-data.js +22 -0
- package/dist/src/targets/javascript/axios/fixtures/multipart-file.js +21 -0
- package/dist/src/targets/javascript/axios/fixtures/multipart-form-data-no-params.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/multipart-form-data.js +21 -0
- package/dist/src/targets/javascript/axios/fixtures/nested.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/query-encoded.js +21 -0
- package/dist/src/targets/javascript/axios/fixtures/query.js +18 -0
- package/dist/src/targets/javascript/axios/fixtures/short.js +14 -0
- package/dist/src/targets/javascript/axios/fixtures/text-plain.js +19 -0
- package/dist/src/targets/javascript/fetch/client.js +115 -0
- package/dist/src/targets/javascript/fetch/fixtures/application-form-encoded.js +9 -0
- package/dist/src/targets/javascript/fetch/fixtures/application-json.js +16 -0
- package/dist/src/targets/javascript/fetch/fixtures/cookies.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/custom-method.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/full.js +13 -0
- package/dist/src/targets/javascript/fetch/fixtures/headers.js +8 -0
- package/dist/src/targets/javascript/fetch/fixtures/http-insecure.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/jsonObj-multiline.js +9 -0
- package/dist/src/targets/javascript/fetch/fixtures/jsonObj-null-value.js +9 -0
- package/dist/src/targets/javascript/fetch/fixtures/multipart-data.js +9 -0
- package/dist/src/targets/javascript/fetch/fixtures/multipart-file.js +8 -0
- package/dist/src/targets/javascript/fetch/fixtures/multipart-form-data-no-params.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/multipart-form-data.js +8 -0
- package/dist/src/targets/javascript/fetch/fixtures/nested.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/query-encoded.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/query.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/short.js +5 -0
- package/dist/src/targets/javascript/fetch/fixtures/text-plain.js +5 -0
- package/dist/src/targets/javascript/jquery/client.js +93 -0
- package/dist/src/targets/javascript/jquery/fixtures/application-form-encoded.js +17 -0
- package/dist/src/targets/javascript/jquery/fixtures/application-json.js +15 -0
- package/dist/src/targets/javascript/jquery/fixtures/cookies.js +13 -0
- package/dist/src/targets/javascript/jquery/fixtures/custom-method.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/full.js +18 -0
- package/dist/src/targets/javascript/jquery/fixtures/headers.js +15 -0
- package/dist/src/targets/javascript/jquery/fixtures/http-insecure.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/jsonObj-multiline.js +15 -0
- package/dist/src/targets/javascript/jquery/fixtures/jsonObj-null-value.js +15 -0
- package/dist/src/targets/javascript/jquery/fixtures/multipart-data.js +18 -0
- package/dist/src/targets/javascript/jquery/fixtures/multipart-file.js +17 -0
- package/dist/src/targets/javascript/jquery/fixtures/multipart-form-data-no-params.js +13 -0
- package/dist/src/targets/javascript/jquery/fixtures/multipart-form-data.js +17 -0
- package/dist/src/targets/javascript/jquery/fixtures/nested.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/query-encoded.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/query.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/short.js +11 -0
- package/dist/src/targets/javascript/jquery/fixtures/text-plain.js +14 -0
- package/dist/src/targets/javascript/target.js +21 -0
- package/dist/src/targets/javascript/xhr/client.js +90 -0
- package/dist/src/targets/javascript/xhr/fixtures/application-form-encoded.js +12 -0
- package/dist/src/targets/javascript/xhr/fixtures/application-json.js +31 -0
- package/dist/src/targets/javascript/xhr/fixtures/cookies.js +12 -0
- package/dist/src/targets/javascript/xhr/fixtures/cors.js +10 -0
- package/dist/src/targets/javascript/xhr/fixtures/custom-method.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/full.js +14 -0
- package/dist/src/targets/javascript/xhr/fixtures/headers.js +14 -0
- package/dist/src/targets/javascript/xhr/fixtures/http-insecure.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/jsonObj-multiline.js +14 -0
- package/dist/src/targets/javascript/xhr/fixtures/jsonObj-null-value.js +14 -0
- package/dist/src/targets/javascript/xhr/fixtures/multipart-data.js +13 -0
- package/dist/src/targets/javascript/xhr/fixtures/multipart-file.js +12 -0
- package/dist/src/targets/javascript/xhr/fixtures/multipart-form-data-no-params.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/multipart-form-data.js +12 -0
- package/dist/src/targets/javascript/xhr/fixtures/nested.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/query-encoded.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/query.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/short.js +11 -0
- package/dist/src/targets/javascript/xhr/fixtures/text-plain.js +12 -0
- package/dist/src/targets/kotlin/okhttp/client.js +79 -0
- package/dist/src/targets/kotlin/target.js +15 -0
- package/dist/src/targets/node/axios/client.js +87 -0
- package/dist/src/targets/node/axios/fixtures/application-form-encoded.js +19 -0
- package/dist/src/targets/node/axios/fixtures/application-json.js +22 -0
- package/dist/src/targets/node/axios/fixtures/cookies.js +14 -0
- package/dist/src/targets/node/axios/fixtures/custom-method.js +10 -0
- package/dist/src/targets/node/axios/fixtures/full.js +22 -0
- package/dist/src/targets/node/axios/fixtures/headers.js +14 -0
- package/dist/src/targets/node/axios/fixtures/http-insecure.js +10 -0
- package/dist/src/targets/node/axios/fixtures/jsonObj-multiline.js +15 -0
- package/dist/src/targets/node/axios/fixtures/jsonObj-null-value.js +15 -0
- package/dist/src/targets/node/axios/fixtures/multipart-data.js +15 -0
- package/dist/src/targets/node/axios/fixtures/multipart-file.js +15 -0
- package/dist/src/targets/node/axios/fixtures/multipart-form-data-no-params.js +14 -0
- package/dist/src/targets/node/axios/fixtures/multipart-form-data.js +15 -0
- package/dist/src/targets/node/axios/fixtures/nested.js +13 -0
- package/dist/src/targets/node/axios/fixtures/query-encoded.js +13 -0
- package/dist/src/targets/node/axios/fixtures/query.js +13 -0
- package/dist/src/targets/node/axios/fixtures/short.js +10 -0
- package/dist/src/targets/node/axios/fixtures/text-plain.js +15 -0
- package/dist/src/targets/node/fetch/client.js +149 -0
- package/dist/src/targets/node/fetch/fixtures/application-form-encoded.js +15 -0
- package/dist/src/targets/node/fetch/fixtures/application-json.js +18 -0
- package/dist/src/targets/node/fetch/fixtures/cookies.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/custom-method.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/full.js +18 -0
- package/dist/src/targets/node/fetch/fixtures/headers.js +10 -0
- package/dist/src/targets/node/fetch/fixtures/http-insecure.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/jsonObj-multiline.js +11 -0
- package/dist/src/targets/node/fetch/fixtures/jsonObj-null-value.js +11 -0
- package/dist/src/targets/node/fetch/fixtures/multipart-data.js +13 -0
- package/dist/src/targets/node/fetch/fixtures/multipart-file.js +12 -0
- package/dist/src/targets/node/fetch/fixtures/multipart-form-data-no-params.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/multipart-form-data.js +11 -0
- package/dist/src/targets/node/fetch/fixtures/nested.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/query-encoded.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/query.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/short.js +7 -0
- package/dist/src/targets/node/fetch/fixtures/text-plain.js +7 -0
- package/dist/src/targets/node/native/client.js +91 -0
- package/dist/src/targets/node/native/fixtures/application-form-encoded.js +24 -0
- package/dist/src/targets/node/native/fixtures/application-json.js +30 -0
- package/dist/src/targets/node/native/fixtures/cookies.js +22 -0
- package/dist/src/targets/node/native/fixtures/custom-method.js +20 -0
- package/dist/src/targets/node/native/fixtures/full.js +26 -0
- package/dist/src/targets/node/native/fixtures/headers.js +24 -0
- package/dist/src/targets/node/native/fixtures/http-insecure.js +20 -0
- package/dist/src/targets/node/native/fixtures/jsonObj-multiline.js +23 -0
- package/dist/src/targets/node/native/fixtures/jsonObj-null-value.js +23 -0
- package/dist/src/targets/node/native/fixtures/multipart-data.js +23 -0
- package/dist/src/targets/node/native/fixtures/multipart-file.js +23 -0
- package/dist/src/targets/node/native/fixtures/multipart-form-data-no-params.js +22 -0
- package/dist/src/targets/node/native/fixtures/multipart-form-data.js +23 -0
- package/dist/src/targets/node/native/fixtures/nested.js +20 -0
- package/dist/src/targets/node/native/fixtures/query-encoded.js +20 -0
- package/dist/src/targets/node/native/fixtures/query.js +20 -0
- package/dist/src/targets/node/native/fixtures/short.js +20 -0
- package/dist/src/targets/node/native/fixtures/text-plain.js +23 -0
- package/dist/src/targets/node/request/client.js +116 -0
- package/dist/src/targets/node/request/fixtures/application-form-encoded.js +13 -0
- package/dist/src/targets/node/request/fixtures/application-json.js +21 -0
- package/dist/src/targets/node/request/fixtures/cookies.js +11 -0
- package/dist/src/targets/node/request/fixtures/custom-method.js +8 -0
- package/dist/src/targets/node/request/fixtures/full.js +20 -0
- package/dist/src/targets/node/request/fixtures/headers.js +12 -0
- package/dist/src/targets/node/request/fixtures/http-insecure.js +8 -0
- package/dist/src/targets/node/request/fixtures/jsonObj-multiline.js +14 -0
- package/dist/src/targets/node/request/fixtures/jsonObj-null-value.js +14 -0
- package/dist/src/targets/node/request/fixtures/multipart-data.js +20 -0
- package/dist/src/targets/node/request/fixtures/multipart-file.js +19 -0
- package/dist/src/targets/node/request/fixtures/multipart-form-data-no-params.js +12 -0
- package/dist/src/targets/node/request/fixtures/multipart-form-data.js +13 -0
- package/dist/src/targets/node/request/fixtures/nested.js +11 -0
- package/dist/src/targets/node/request/fixtures/query-encoded.js +11 -0
- package/dist/src/targets/node/request/fixtures/query.js +11 -0
- package/dist/src/targets/node/request/fixtures/short.js +8 -0
- package/dist/src/targets/node/request/fixtures/text-plain.js +13 -0
- package/dist/src/targets/node/target.js +24 -0
- package/dist/src/targets/node/unirest/client.js +119 -0
- package/dist/src/targets/node/unirest/fixtures/application-form-encoded.js +15 -0
- package/dist/src/targets/node/unirest/fixtures/application-json.js +32 -0
- package/dist/src/targets/node/unirest/fixtures/cookies.js +12 -0
- package/dist/src/targets/node/unirest/fixtures/custom-method.js +8 -0
- package/dist/src/targets/node/unirest/fixtures/full.js +27 -0
- package/dist/src/targets/node/unirest/fixtures/headers.js +13 -0
- package/dist/src/targets/node/unirest/fixtures/http-insecure.js +8 -0
- package/dist/src/targets/node/unirest/fixtures/jsonObj-multiline.js +15 -0
- package/dist/src/targets/node/unirest/fixtures/jsonObj-null-value.js +15 -0
- package/dist/src/targets/node/unirest/fixtures/multipart-data.js +20 -0
- package/dist/src/targets/node/unirest/fixtures/multipart-file.js +18 -0
- package/dist/src/targets/node/unirest/fixtures/multipart-form-data-no-params.js +11 -0
- package/dist/src/targets/node/unirest/fixtures/multipart-form-data.js +16 -0
- package/dist/src/targets/node/unirest/fixtures/nested.js +13 -0
- package/dist/src/targets/node/unirest/fixtures/query-encoded.js +12 -0
- package/dist/src/targets/node/unirest/fixtures/query.js +16 -0
- package/dist/src/targets/node/unirest/fixtures/short.js +8 -0
- package/dist/src/targets/node/unirest/fixtures/text-plain.js +12 -0
- package/dist/src/targets/objc/helpers.js +59 -0
- package/dist/src/targets/objc/nsurlsession/client.js +151 -0
- package/dist/src/targets/objc/target.js +15 -0
- package/dist/src/targets/ocaml/cohttp/client.js +72 -0
- package/dist/src/targets/ocaml/target.js +15 -0
- package/dist/src/targets/php/curl/client.js +135 -0
- package/dist/src/targets/php/guzzle/client.js +126 -0
- package/dist/src/targets/php/helpers.js +63 -0
- package/dist/src/targets/php/http1/client.js +90 -0
- package/dist/src/targets/php/http2/client.js +128 -0
- package/dist/src/targets/php/target.js +22 -0
- package/dist/src/targets/powershell/common.js +49 -0
- package/dist/src/targets/powershell/restmethod/client.js +13 -0
- package/dist/src/targets/powershell/target.js +17 -0
- package/dist/src/targets/powershell/webrequest/client.js +13 -0
- package/dist/src/targets/python/helpers.js +70 -0
- package/dist/src/targets/python/requests/client.js +161 -0
- package/dist/src/targets/python/target.js +16 -0
- package/dist/src/targets/r/httr/client.js +125 -0
- package/dist/src/targets/r/target.js +15 -0
- package/dist/src/targets/ruby/native/client.js +69 -0
- package/dist/src/targets/ruby/target.js +15 -0
- package/dist/src/targets/shell/curl/client.js +171 -0
- package/dist/src/targets/shell/httpie/client.js +111 -0
- package/dist/src/targets/shell/target.js +20 -0
- package/dist/src/targets/shell/wget/client.js +55 -0
- package/dist/src/targets/swift/helpers.js +80 -0
- package/dist/src/targets/swift/nsurlsession/client.js +156 -0
- package/dist/src/targets/swift/target.js +15 -0
- package/dist/src/targets/targets.js +130 -0
- package/package.json +26 -21
- package/src/helpers/code-builder.js +0 -108
- package/src/helpers/form-data.js +0 -107
- package/src/helpers/headers.js +0 -48
- package/src/helpers/reducer.js +0 -20
- package/src/index.js +0 -361
- package/src/targets/c/index.js +0 -10
- package/src/targets/c/libcurl.js +0 -45
- package/src/targets/clojure/clj_http.js +0 -176
- package/src/targets/clojure/index.js +0 -10
- package/src/targets/csharp/httpclient.js +0 -157
- package/src/targets/csharp/index.js +0 -11
- package/src/targets/csharp/restsharp.js +0 -49
- package/src/targets/go/index.js +0 -10
- package/src/targets/go/native.js +0 -130
- package/src/targets/http/http1.1.js +0 -89
- package/src/targets/http/index.js +0 -10
- package/src/targets/index.js +0 -20
- package/src/targets/java/asynchttp.js +0 -54
- package/src/targets/java/index.js +0 -13
- package/src/targets/java/nethttp.js +0 -59
- package/src/targets/java/okhttp.js +0 -78
- package/src/targets/java/unirest.js +0 -57
- package/src/targets/javascript/axios.js +0 -101
- package/src/targets/javascript/fetch.js +0 -129
- package/src/targets/javascript/index.js +0 -13
- package/src/targets/javascript/jquery.js +0 -89
- package/src/targets/javascript/xhr.js +0 -86
- package/src/targets/kotlin/index.js +0 -10
- package/src/targets/kotlin/okhttp.js +0 -78
- package/src/targets/node/axios.js +0 -76
- package/src/targets/node/fetch.js +0 -145
- package/src/targets/node/index.js +0 -15
- package/src/targets/node/native.js +0 -92
- package/src/targets/node/request.js +0 -126
- package/src/targets/node/unirest.js +0 -120
- package/src/targets/objc/helpers.js +0 -80
- package/src/targets/objc/index.js +0 -10
- package/src/targets/objc/nsurlsession.js +0 -164
- package/src/targets/ocaml/cohttp.js +0 -73
- package/src/targets/ocaml/index.js +0 -10
- package/src/targets/php/curl.js +0 -142
- package/src/targets/php/guzzle.js +0 -135
- package/src/targets/php/helpers.js +0 -87
- package/src/targets/php/http1.js +0 -85
- package/src/targets/php/http2.js +0 -131
- package/src/targets/php/index.js +0 -14
- package/src/targets/powershell/common.js +0 -60
- package/src/targets/powershell/index.js +0 -11
- package/src/targets/powershell/restmethod.js +0 -8
- package/src/targets/powershell/webrequest.js +0 -8
- package/src/targets/python/helpers.js +0 -85
- package/src/targets/python/index.js +0 -11
- package/src/targets/python/requests.js +0 -163
- package/src/targets/r/httr.js +0 -134
- package/src/targets/r/index.js +0 -10
- package/src/targets/ruby/index.js +0 -10
- package/src/targets/ruby/native.js +0 -71
- package/src/targets/shell/curl.js +0 -157
- package/src/targets/shell/helpers.js +0 -23
- package/src/targets/shell/httpie.js +0 -129
- package/src/targets/shell/index.js +0 -13
- package/src/targets/shell/wget.js +0 -52
- package/src/targets/swift/helpers.js +0 -93
- package/src/targets/swift/index.js +0 -10
- package/src/targets/swift/nsurlsession.js +0 -152
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description
|
|
3
|
-
* HTTP code snippet generator for Node.js using node-fetch.
|
|
4
|
-
*
|
|
5
|
-
* @author
|
|
6
|
-
* @hirenoble
|
|
7
|
-
*
|
|
8
|
-
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const headerHelpers = require('../../helpers/headers');
|
|
12
|
-
const stringifyObject = require('stringify-object');
|
|
13
|
-
const CodeBuilder = require('../../helpers/code-builder');
|
|
14
|
-
|
|
15
|
-
module.exports = function (source, options) {
|
|
16
|
-
const opts = {
|
|
17
|
-
indent: ' ',
|
|
18
|
-
...options,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
let includeFS = false;
|
|
22
|
-
const code = new CodeBuilder(opts.indent);
|
|
23
|
-
|
|
24
|
-
code.push("const fetch = require('node-fetch');");
|
|
25
|
-
const url = source.fullUrl;
|
|
26
|
-
const reqOpts = {
|
|
27
|
-
method: source.method,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
if (Object.keys(source.allHeaders).length) {
|
|
31
|
-
reqOpts.headers = source.allHeaders;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
switch (source.postData.mimeType) {
|
|
35
|
-
case 'application/x-www-form-urlencoded':
|
|
36
|
-
code.unshift("const { URLSearchParams } = require('url');");
|
|
37
|
-
code.push('const encodedParams = new URLSearchParams();');
|
|
38
|
-
code.blank();
|
|
39
|
-
|
|
40
|
-
source.postData.params.forEach(function (param) {
|
|
41
|
-
code.push(`encodedParams.set('${param.name}', '${param.value}');`);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
reqOpts.body = 'encodedParams';
|
|
45
|
-
break;
|
|
46
|
-
|
|
47
|
-
case 'application/json':
|
|
48
|
-
if (source.postData.jsonObj) {
|
|
49
|
-
reqOpts.body = source.postData.jsonObj;
|
|
50
|
-
}
|
|
51
|
-
break;
|
|
52
|
-
|
|
53
|
-
case 'multipart/form-data':
|
|
54
|
-
if (source.postData.params) {
|
|
55
|
-
// The `form-data` library automatically adds a `Content-Type` header for
|
|
56
|
-
// `multipart/form-data` content and if we add our own here, data won't be correctly
|
|
57
|
-
// transferred.
|
|
58
|
-
if (reqOpts.headers) {
|
|
59
|
-
const contentTypeHeader = headerHelpers.getHeaderName(reqOpts.headers, 'content-type');
|
|
60
|
-
if (contentTypeHeader) {
|
|
61
|
-
delete reqOpts.headers[contentTypeHeader];
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
code.unshift("const FormData = require('form-data');");
|
|
66
|
-
code.push('const formData = new FormData();');
|
|
67
|
-
code.blank();
|
|
68
|
-
|
|
69
|
-
source.postData.params.forEach(function (param) {
|
|
70
|
-
if (!param.fileName && !param.contentType) {
|
|
71
|
-
code.push(`formData.append('${param.name}', '${param.value}');`);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (param.fileName) {
|
|
76
|
-
includeFS = true;
|
|
77
|
-
code.push(`formData.append('${param.name}', fs.createReadStream('${param.fileName}'));`);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
break;
|
|
82
|
-
|
|
83
|
-
default:
|
|
84
|
-
if (source.postData.text) {
|
|
85
|
-
reqOpts.body = source.postData.text;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// If we ultimately don't have any headers to send then we shouldn't add an empty object into
|
|
90
|
-
// the request options.
|
|
91
|
-
if (reqOpts.headers && !Object.keys(reqOpts.headers).length) {
|
|
92
|
-
delete reqOpts.headers;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
code.blank();
|
|
96
|
-
code.push(`const url = '${url}';`);
|
|
97
|
-
code
|
|
98
|
-
.push(
|
|
99
|
-
'const options = %s;',
|
|
100
|
-
stringifyObject(reqOpts, {
|
|
101
|
-
indent: opts.indent,
|
|
102
|
-
inlineCharacterLimit: 80,
|
|
103
|
-
|
|
104
|
-
// The Fetch API body only accepts string parameters, but stringified JSON can be difficult to
|
|
105
|
-
// read, so we keep the object as a literal and use this transform function to wrap the literal
|
|
106
|
-
// in a `JSON.stringify` call.
|
|
107
|
-
transform: (object, property, originalResult) => {
|
|
108
|
-
if (property === 'body' && source.postData.mimeType === 'application/json') {
|
|
109
|
-
return `JSON.stringify(${originalResult})`;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return originalResult;
|
|
113
|
-
},
|
|
114
|
-
})
|
|
115
|
-
)
|
|
116
|
-
.blank();
|
|
117
|
-
|
|
118
|
-
if (includeFS) {
|
|
119
|
-
code.unshift("const fs = require('fs');");
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (source.postData.mimeType === 'multipart/form-data') {
|
|
123
|
-
if (source.postData.params) {
|
|
124
|
-
code.push('options.body = formData;').blank();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
code
|
|
129
|
-
.push('fetch(url, options)')
|
|
130
|
-
.push(1, '.then(res => res.json())')
|
|
131
|
-
.push(1, '.then(json => console.log(json))')
|
|
132
|
-
.push(1, ".catch(err => console.error('error:' + err));");
|
|
133
|
-
|
|
134
|
-
return code
|
|
135
|
-
.join()
|
|
136
|
-
.replace(/'encodedParams'/, 'encodedParams')
|
|
137
|
-
.replace(/"fs\.createReadStream\(\\"(.+)\\"\)"/, 'fs.createReadStream("$1")');
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
module.exports.info = {
|
|
141
|
-
key: 'fetch',
|
|
142
|
-
title: 'Fetch',
|
|
143
|
-
link: 'https://github.com/bitinn/node-fetch',
|
|
144
|
-
description: 'Simplified HTTP node-fetch client',
|
|
145
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
info: {
|
|
3
|
-
key: 'node',
|
|
4
|
-
title: 'Node.js',
|
|
5
|
-
extname: '.js',
|
|
6
|
-
default: 'native',
|
|
7
|
-
cli: 'node %s',
|
|
8
|
-
},
|
|
9
|
-
|
|
10
|
-
native: require('./native'),
|
|
11
|
-
request: require('./request'),
|
|
12
|
-
unirest: require('./unirest'),
|
|
13
|
-
axios: require('./axios'),
|
|
14
|
-
fetch: require('./fetch'),
|
|
15
|
-
};
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description
|
|
3
|
-
* HTTP code snippet generator for native Node.js.
|
|
4
|
-
*
|
|
5
|
-
* @author
|
|
6
|
-
* @AhmadNassri
|
|
7
|
-
*
|
|
8
|
-
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const stringifyObject = require('stringify-object');
|
|
12
|
-
const CodeBuilder = require('../../helpers/code-builder');
|
|
13
|
-
|
|
14
|
-
module.exports = function (source, options) {
|
|
15
|
-
const opts = {
|
|
16
|
-
indent: ' ',
|
|
17
|
-
...options,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const code = new CodeBuilder(opts.indent);
|
|
21
|
-
|
|
22
|
-
const reqOpts = {
|
|
23
|
-
method: source.method,
|
|
24
|
-
hostname: source.uriObj.hostname,
|
|
25
|
-
port: source.uriObj.port,
|
|
26
|
-
path: source.uriObj.path,
|
|
27
|
-
headers: source.allHeaders,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
code.push('const http = require("%s");', source.uriObj.protocol.replace(':', ''));
|
|
31
|
-
|
|
32
|
-
code
|
|
33
|
-
.blank()
|
|
34
|
-
.push('const options = %s;', JSON.stringify(reqOpts, null, opts.indent))
|
|
35
|
-
.blank()
|
|
36
|
-
.push('const req = http.request(options, function (res) {')
|
|
37
|
-
.push(1, 'const chunks = [];')
|
|
38
|
-
.blank()
|
|
39
|
-
.push(1, 'res.on("data", function (chunk) {')
|
|
40
|
-
.push(2, 'chunks.push(chunk);')
|
|
41
|
-
.push(1, '});')
|
|
42
|
-
.blank()
|
|
43
|
-
.push(1, 'res.on("end", function () {')
|
|
44
|
-
.push(2, 'const body = Buffer.concat(chunks);')
|
|
45
|
-
.push(2, 'console.log(body.toString());')
|
|
46
|
-
.push(1, '});')
|
|
47
|
-
.push('});')
|
|
48
|
-
.blank();
|
|
49
|
-
|
|
50
|
-
switch (source.postData.mimeType) {
|
|
51
|
-
case 'application/x-www-form-urlencoded':
|
|
52
|
-
if (source.postData.paramsObj) {
|
|
53
|
-
code.unshift('const qs = require("querystring");');
|
|
54
|
-
code.push(
|
|
55
|
-
'req.write(qs.stringify(%s));',
|
|
56
|
-
stringifyObject(source.postData.paramsObj, {
|
|
57
|
-
indent: ' ',
|
|
58
|
-
inlineCharacterLimit: 80,
|
|
59
|
-
})
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
break;
|
|
63
|
-
|
|
64
|
-
case 'application/json':
|
|
65
|
-
if (source.postData.jsonObj) {
|
|
66
|
-
code.push(
|
|
67
|
-
'req.write(JSON.stringify(%s));',
|
|
68
|
-
stringifyObject(source.postData.jsonObj, {
|
|
69
|
-
indent: ' ',
|
|
70
|
-
inlineCharacterLimit: 80,
|
|
71
|
-
})
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
break;
|
|
75
|
-
|
|
76
|
-
default:
|
|
77
|
-
if (source.postData.text) {
|
|
78
|
-
code.push('req.write(%s);', JSON.stringify(source.postData.text, null, opts.indent));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
code.push('req.end();');
|
|
83
|
-
|
|
84
|
-
return code.join();
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
module.exports.info = {
|
|
88
|
-
key: 'native',
|
|
89
|
-
title: 'HTTP',
|
|
90
|
-
link: 'http://nodejs.org/api/http.html#http_http_request_options_callback',
|
|
91
|
-
description: 'Node.js native HTTP interface',
|
|
92
|
-
};
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description
|
|
3
|
-
* HTTP code snippet generator for Node.js using Request.
|
|
4
|
-
*
|
|
5
|
-
* @author
|
|
6
|
-
* @AhmadNassri
|
|
7
|
-
*
|
|
8
|
-
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const stringifyObject = require('stringify-object');
|
|
12
|
-
const CodeBuilder = require('../../helpers/code-builder');
|
|
13
|
-
|
|
14
|
-
module.exports = function (source, options) {
|
|
15
|
-
const opts = {
|
|
16
|
-
indent: ' ',
|
|
17
|
-
...options,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
let includeFS = false;
|
|
21
|
-
const code = new CodeBuilder(opts.indent);
|
|
22
|
-
|
|
23
|
-
code.push("const request = require('request');").blank();
|
|
24
|
-
|
|
25
|
-
const reqOpts = {
|
|
26
|
-
method: source.method,
|
|
27
|
-
url: source.fullUrl,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
if (Object.keys(source.headersObj).length) {
|
|
31
|
-
reqOpts.headers = source.headersObj;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
switch (source.postData.mimeType) {
|
|
35
|
-
case 'application/x-www-form-urlencoded':
|
|
36
|
-
reqOpts.form = source.postData.paramsObj;
|
|
37
|
-
break;
|
|
38
|
-
|
|
39
|
-
case 'application/json':
|
|
40
|
-
if (source.postData.jsonObj) {
|
|
41
|
-
reqOpts.body = source.postData.jsonObj;
|
|
42
|
-
reqOpts.json = true;
|
|
43
|
-
}
|
|
44
|
-
break;
|
|
45
|
-
|
|
46
|
-
case 'multipart/form-data':
|
|
47
|
-
if (source.postData.params) {
|
|
48
|
-
reqOpts.formData = {};
|
|
49
|
-
|
|
50
|
-
source.postData.params.forEach(function (param) {
|
|
51
|
-
const attachment = {};
|
|
52
|
-
|
|
53
|
-
if (!param.fileName && !param.contentType) {
|
|
54
|
-
reqOpts.formData[param.name] = param.value;
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (param.fileName) {
|
|
59
|
-
includeFS = true;
|
|
60
|
-
|
|
61
|
-
attachment.value = `fs.createReadStream("${param.fileName}")`;
|
|
62
|
-
} else if (param.value) {
|
|
63
|
-
attachment.value = param.value;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (param.fileName) {
|
|
67
|
-
attachment.options = {
|
|
68
|
-
filename: param.fileName,
|
|
69
|
-
contentType: param.contentType ? param.contentType : null,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
reqOpts.formData[param.name] = attachment;
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
break;
|
|
77
|
-
|
|
78
|
-
default:
|
|
79
|
-
if (source.postData.text) {
|
|
80
|
-
reqOpts.body = source.postData.text;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// construct cookies argument
|
|
85
|
-
if (source.allHeaders.cookie) {
|
|
86
|
-
reqOpts.jar = 'JAR';
|
|
87
|
-
|
|
88
|
-
code.push('const jar = request.jar();');
|
|
89
|
-
|
|
90
|
-
const url = source.url;
|
|
91
|
-
|
|
92
|
-
// Cookies are already encoded within `source.allHeaders` so we can pull them out of that instead of doing our
|
|
93
|
-
// own encoding work.
|
|
94
|
-
source.allHeaders.cookie.split('; ').forEach(function (cookie) {
|
|
95
|
-
const [name, value] = cookie.split('=');
|
|
96
|
-
code.push("jar.setCookie(request.cookie('%s=%s'), '%s');", name, value, url);
|
|
97
|
-
});
|
|
98
|
-
code.blank();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (includeFS) {
|
|
102
|
-
code.unshift("const fs = require('fs');");
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
code.push('const options = %s;', stringifyObject(reqOpts, { indent: ' ', inlineCharacterLimit: 80 })).blank();
|
|
106
|
-
|
|
107
|
-
code
|
|
108
|
-
.push('request(options, function (error, response, body) {')
|
|
109
|
-
.push(1, 'if (error) throw new Error(error);')
|
|
110
|
-
.blank()
|
|
111
|
-
.push(1, 'console.log(body);')
|
|
112
|
-
.push('});')
|
|
113
|
-
.blank();
|
|
114
|
-
|
|
115
|
-
return code
|
|
116
|
-
.join()
|
|
117
|
-
.replace("'JAR'", 'jar')
|
|
118
|
-
.replace(/'fs\.createReadStream\("(.+)"\)'/g, "fs.createReadStream('$1')");
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
module.exports.info = {
|
|
122
|
-
key: 'request',
|
|
123
|
-
title: 'Request',
|
|
124
|
-
link: 'https://github.com/request/request',
|
|
125
|
-
description: 'Simplified HTTP request client',
|
|
126
|
-
};
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description
|
|
3
|
-
* HTTP code snippet generator for Node.js using Unirest.
|
|
4
|
-
*
|
|
5
|
-
* @author
|
|
6
|
-
* @AhmadNassri
|
|
7
|
-
*
|
|
8
|
-
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const CodeBuilder = require('../../helpers/code-builder');
|
|
12
|
-
|
|
13
|
-
module.exports = function (source, options) {
|
|
14
|
-
const opts = {
|
|
15
|
-
indent: ' ',
|
|
16
|
-
...options,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
let includeFS = false;
|
|
20
|
-
const code = new CodeBuilder(opts.indent);
|
|
21
|
-
|
|
22
|
-
code
|
|
23
|
-
.push('const unirest = require("unirest");')
|
|
24
|
-
.blank()
|
|
25
|
-
.push('const req = unirest("%s", "%s");', source.method, source.url)
|
|
26
|
-
.blank();
|
|
27
|
-
|
|
28
|
-
if (source.allHeaders.cookie) {
|
|
29
|
-
code.push('const CookieJar = unirest.jar();');
|
|
30
|
-
|
|
31
|
-
// Cookies are already encoded within `source.allHeaders` so we can pull them out of that instead of doing our
|
|
32
|
-
// own encoding work.
|
|
33
|
-
source.allHeaders.cookie.split('; ').forEach(function (cookie) {
|
|
34
|
-
const [name, value] = cookie.split('=');
|
|
35
|
-
code.push('CookieJar.add("%s=%s","%s");', name, value, source.url);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
code.push('req.jar(CookieJar);').blank();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (Object.keys(source.queryObj).length) {
|
|
42
|
-
code.push('req.query(%s);', JSON.stringify(source.queryObj, null, opts.indent)).blank();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (Object.keys(source.headersObj).length) {
|
|
46
|
-
code.push('req.headers(%s);', JSON.stringify(source.headersObj, null, opts.indent)).blank();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
switch (source.postData.mimeType) {
|
|
50
|
-
case 'application/x-www-form-urlencoded':
|
|
51
|
-
if (source.postData.paramsObj) {
|
|
52
|
-
code.push('req.form(%s);', JSON.stringify(source.postData.paramsObj, null, opts.indent)).blank();
|
|
53
|
-
}
|
|
54
|
-
break;
|
|
55
|
-
|
|
56
|
-
case 'application/json':
|
|
57
|
-
if (source.postData.jsonObj) {
|
|
58
|
-
code
|
|
59
|
-
.push('req.type("json");')
|
|
60
|
-
.push('req.send(%s);', JSON.stringify(source.postData.jsonObj, null, opts.indent))
|
|
61
|
-
.blank();
|
|
62
|
-
}
|
|
63
|
-
break;
|
|
64
|
-
|
|
65
|
-
case 'multipart/form-data': {
|
|
66
|
-
if (source.postData.params) {
|
|
67
|
-
const multipart = [];
|
|
68
|
-
|
|
69
|
-
source.postData.params.forEach(function (param) {
|
|
70
|
-
const part = {};
|
|
71
|
-
|
|
72
|
-
if (param.fileName && !param.value) {
|
|
73
|
-
includeFS = true;
|
|
74
|
-
|
|
75
|
-
part.body = `fs.createReadStream("${param.fileName}")`;
|
|
76
|
-
} else if (param.value) {
|
|
77
|
-
part.body = param.value;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (part.body) {
|
|
81
|
-
if (param.contentType) {
|
|
82
|
-
part['content-type'] = param.contentType;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
multipart.push(part);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
code.push('req.multipart(%s);', JSON.stringify(multipart, null, opts.indent)).blank();
|
|
90
|
-
}
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
default:
|
|
95
|
-
if (source.postData.text) {
|
|
96
|
-
code.push('req.send(%s);', JSON.stringify(source.postData.text, null, opts.indent)).blank();
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (includeFS) {
|
|
101
|
-
code.unshift('const fs = require("fs");');
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
code
|
|
105
|
-
.push('req.end(function (res) {')
|
|
106
|
-
.push(1, 'if (res.error) throw new Error(res.error);')
|
|
107
|
-
.blank()
|
|
108
|
-
.push(1, 'console.log(res.body);')
|
|
109
|
-
.push('});')
|
|
110
|
-
.blank();
|
|
111
|
-
|
|
112
|
-
return code.join().replace(/"fs\.createReadStream\(\\"(.+)\\"\)"/, 'fs.createReadStream("$1")');
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
module.exports.info = {
|
|
116
|
-
key: 'unirest',
|
|
117
|
-
title: 'Unirest',
|
|
118
|
-
link: 'http://unirest.io/nodejs.html',
|
|
119
|
-
description: 'Lightweight HTTP Request Client Library',
|
|
120
|
-
};
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
const { format } = require('util');
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
/**
|
|
5
|
-
* Create an string of given length filled with blank spaces
|
|
6
|
-
*
|
|
7
|
-
* @param {number} length Length of the array to return
|
|
8
|
-
* @return {string}
|
|
9
|
-
*/
|
|
10
|
-
blankString: function (length) {
|
|
11
|
-
// eslint-disable-next-line prefer-spread
|
|
12
|
-
return Array.apply(null, new Array(length)).map(String.prototype.valueOf, ' ').join('');
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Create a string corresponding to a valid declaration and initialization of an Objective-C object literal.
|
|
17
|
-
*
|
|
18
|
-
* @param {string} nsClass Class of the litteral
|
|
19
|
-
* @param {string} name Desired name of the instance
|
|
20
|
-
* @param {Object} parameters Key-value object of parameters to translate to an Objective-C object litearal
|
|
21
|
-
* @param {boolean} indent If true, will declare the litteral by indenting each new key/value pair.
|
|
22
|
-
* @return {string} A valid Objective-C declaration and initialization of an Objective-C object litteral.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* nsDeclaration('NSDictionary', 'params', {a: 'b', c: 'd'}, true)
|
|
26
|
-
* // returns:
|
|
27
|
-
* NSDictionary *params = @{ @"a": @"b",
|
|
28
|
-
* @"c": @"d" };
|
|
29
|
-
*
|
|
30
|
-
* nsDeclaration('NSDictionary', 'params', {a: 'b', c: 'd'})
|
|
31
|
-
* // returns:
|
|
32
|
-
* NSDictionary *params = @{ @"a": @"b", @"c": @"d" };
|
|
33
|
-
*/
|
|
34
|
-
nsDeclaration: function (nsClass, name, parameters, indent) {
|
|
35
|
-
const opening = `${nsClass} *${name} = `;
|
|
36
|
-
const literal = this.literalRepresentation(parameters, indent ? opening.length : undefined);
|
|
37
|
-
return `${opening + literal};`;
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Create a valid Objective-C string of a literal value according to its type.
|
|
42
|
-
*
|
|
43
|
-
* @param {*} value Any JavaScript literal
|
|
44
|
-
* @return {string}
|
|
45
|
-
*/
|
|
46
|
-
literalRepresentation: function (value, indentation) {
|
|
47
|
-
const join = indentation === undefined ? ', ' : `,\n ${this.blankString(indentation)}`;
|
|
48
|
-
|
|
49
|
-
switch (Object.prototype.toString.call(value)) {
|
|
50
|
-
case '[object Number]':
|
|
51
|
-
return `@${value}`;
|
|
52
|
-
|
|
53
|
-
case '[object Array]': {
|
|
54
|
-
const valuesRepresentation = value.map(
|
|
55
|
-
function (v) {
|
|
56
|
-
return this.literalRepresentation(v);
|
|
57
|
-
}.bind(this)
|
|
58
|
-
);
|
|
59
|
-
return `@[ ${valuesRepresentation.join(join)} ]`;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
case '[object Object]': {
|
|
63
|
-
const keyValuePairs = [];
|
|
64
|
-
Object.keys(value).forEach(k => {
|
|
65
|
-
keyValuePairs.push(format('@"%s": %s', k, this.literalRepresentation(value[k])));
|
|
66
|
-
});
|
|
67
|
-
return `@{ ${keyValuePairs.join(join)} }`;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
case '[object Boolean]':
|
|
71
|
-
return value ? '@YES' : '@NO';
|
|
72
|
-
|
|
73
|
-
default:
|
|
74
|
-
if (value === null || value === undefined) {
|
|
75
|
-
return '';
|
|
76
|
-
}
|
|
77
|
-
return `@"${value.toString().replace(/"/g, '\\"')}"`;
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
};
|