@readme/httpsnippet 2.5.1 → 3.0.3
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 +19 -9
- package/package.json +24 -28
- package/src/helpers/code-builder.js +85 -80
- package/src/helpers/form-data.js +27 -25
- package/src/helpers/headers.js +10 -19
- package/src/helpers/reducer.js +10 -14
- package/src/index.js +167 -146
- package/src/targets/c/index.js +3 -5
- package/src/targets/c/libcurl.js +18 -23
- package/src/targets/clojure/clj_http.js +103 -87
- package/src/targets/clojure/index.js +3 -5
- package/src/targets/csharp/httpclient.js +90 -90
- package/src/targets/csharp/index.js +3 -5
- package/src/targets/csharp/restsharp.js +20 -22
- package/src/targets/go/index.js +3 -5
- package/src/targets/go/native.js +46 -53
- package/src/targets/http/http1.1.js +26 -36
- package/src/targets/http/index.js +3 -5
- package/src/targets/index.js +2 -4
- package/src/targets/java/asynchttp.js +22 -23
- package/src/targets/java/index.js +3 -5
- package/src/targets/java/nethttp.js +20 -24
- package/src/targets/java/okhttp.js +31 -31
- package/src/targets/java/unirest.js +22 -19
- package/src/targets/javascript/axios.js +43 -38
- package/src/targets/javascript/fetch.js +66 -68
- package/src/targets/javascript/index.js +3 -5
- package/src/targets/javascript/jquery.js +46 -40
- package/src/targets/javascript/xhr.js +42 -38
- package/src/targets/kotlin/index.js +3 -5
- package/src/targets/kotlin/okhttp.js +31 -31
- package/src/targets/node/axios.js +33 -30
- package/src/targets/node/fetch.js +89 -83
- package/src/targets/node/index.js +4 -5
- package/src/targets/node/native.js +36 -30
- package/src/targets/node/request.js +64 -64
- package/src/targets/node/unirest.js +56 -55
- package/src/targets/objc/helpers.js +24 -23
- package/src/targets/objc/index.js +3 -5
- package/src/targets/objc/nsurlsession.js +73 -45
- package/src/targets/ocaml/cohttp.js +29 -27
- package/src/targets/ocaml/index.js +3 -5
- package/src/targets/php/curl.js +86 -82
- package/src/targets/php/guzzle.js +135 -0
- package/src/targets/php/helpers.js +29 -28
- package/src/targets/php/http1.js +33 -44
- package/src/targets/php/http2.js +70 -71
- package/src/targets/php/index.js +5 -5
- package/src/targets/powershell/common.js +35 -30
- package/src/targets/powershell/index.js +3 -5
- package/src/targets/powershell/restmethod.js +3 -5
- package/src/targets/powershell/webrequest.js +3 -5
- package/src/targets/python/helpers.js +37 -34
- package/src/targets/python/index.js +4 -5
- package/src/targets/python/python3.js +33 -44
- package/src/targets/python/requests.js +47 -72
- package/src/targets/r/httr.js +59 -70
- package/src/targets/r/index.js +3 -5
- package/src/targets/ruby/index.js +3 -5
- package/src/targets/ruby/native.js +39 -33
- package/src/targets/shell/curl.js +74 -52
- package/src/targets/shell/helpers.js +7 -9
- package/src/targets/shell/httpie.js +45 -39
- package/src/targets/shell/index.js +4 -5
- package/src/targets/shell/wget.js +20 -22
- package/src/targets/swift/helpers.js +35 -32
- package/src/targets/swift/index.js +3 -5
- package/src/targets/swift/nsurlsession.js +53 -39
|
@@ -8,88 +8,109 @@
|
|
|
8
8
|
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const headerHelpers = require('../../helpers/headers')
|
|
16
|
-
const CodeBuilder = require('../../helpers/code-builder')
|
|
11
|
+
const { format } = require('util');
|
|
12
|
+
const helpers = require('./helpers');
|
|
13
|
+
const headerHelpers = require('../../helpers/headers');
|
|
14
|
+
const CodeBuilder = require('../../helpers/code-builder');
|
|
17
15
|
|
|
18
16
|
module.exports = function (source, options) {
|
|
19
|
-
const opts =
|
|
17
|
+
const opts = {
|
|
20
18
|
indent: ' ',
|
|
21
19
|
short: false,
|
|
22
20
|
binary: false,
|
|
23
21
|
globOff: false,
|
|
24
|
-
escapeBrackets: false
|
|
25
|
-
|
|
22
|
+
escapeBrackets: false,
|
|
23
|
+
...options,
|
|
24
|
+
};
|
|
26
25
|
|
|
27
|
-
const code = new CodeBuilder(opts.indent, opts.indent !== false ?
|
|
26
|
+
const code = new CodeBuilder(opts.indent, opts.indent !== false ? ` \\\n${opts.indent}` : ' ');
|
|
28
27
|
|
|
29
|
-
const globOption = opts.short ? '-g' : '--globoff'
|
|
30
|
-
const requestOption = opts.short ? '-X' : '--request'
|
|
31
|
-
let formattedUrl = helpers.quote(source.fullUrl)
|
|
28
|
+
const globOption = opts.short ? '-g' : '--globoff';
|
|
29
|
+
const requestOption = opts.short ? '-X' : '--request';
|
|
30
|
+
let formattedUrl = helpers.quote(source.fullUrl);
|
|
32
31
|
|
|
33
32
|
if (opts.escapeBrackets) {
|
|
34
|
-
formattedUrl = formattedUrl.replace(/\[/g, '\\[').replace(/\]/g, '\\]')
|
|
33
|
+
formattedUrl = formattedUrl.replace(/\[/g, '\\[').replace(/\]/g, '\\]');
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
code.push('curl %s %s', requestOption, source.method)
|
|
36
|
+
code.push('curl %s %s', requestOption, source.method);
|
|
38
37
|
if (opts.globOff) {
|
|
39
|
-
formattedUrl = unescape(formattedUrl)
|
|
40
|
-
code.push(globOption)
|
|
38
|
+
formattedUrl = unescape(formattedUrl);
|
|
39
|
+
code.push(globOption);
|
|
41
40
|
}
|
|
42
|
-
code.push(
|
|
41
|
+
code.push(format('%s%s', opts.short ? '' : '--url ', formattedUrl));
|
|
43
42
|
|
|
44
43
|
if (source.httpVersion === 'HTTP/1.0') {
|
|
45
|
-
code.push(opts.short ? '-0' : '--http1.0')
|
|
44
|
+
code.push(opts.short ? '-0' : '--http1.0');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// if multipart form data, we want to remove the boundary
|
|
48
|
+
if (source.postData.mimeType === 'multipart/form-data') {
|
|
49
|
+
const contentTypeHeaderName = headerHelpers.getHeaderName(source.headersObj, 'content-type');
|
|
50
|
+
const contentTypeHeader = source.headersObj[contentTypeHeaderName];
|
|
51
|
+
|
|
52
|
+
if (contentTypeHeaderName && contentTypeHeader) {
|
|
53
|
+
// remove the leading semi colon and boundary
|
|
54
|
+
// up to the next semi colon or the end of string
|
|
55
|
+
const noBoundary = contentTypeHeader.replace(/; boundary.+?(?=(;|$))/, '');
|
|
56
|
+
|
|
57
|
+
// replace the content-type header with no boundary in both headersObj and allHeaders
|
|
58
|
+
source.headersObj[contentTypeHeaderName] = noBoundary; // eslint-disable-line no-param-reassign
|
|
59
|
+
source.allHeaders[contentTypeHeaderName] = noBoundary; // eslint-disable-line no-param-reassign
|
|
60
|
+
}
|
|
46
61
|
}
|
|
47
62
|
|
|
48
63
|
// construct headers
|
|
49
|
-
Object.keys(source.headersObj)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
64
|
+
Object.keys(source.headersObj)
|
|
65
|
+
.sort()
|
|
66
|
+
.forEach(function (key) {
|
|
67
|
+
const header = format('%s: %s', key, source.headersObj[key]);
|
|
68
|
+
code.push('%s %s', opts.short ? '-H' : '--header', helpers.quote(header));
|
|
69
|
+
});
|
|
53
70
|
|
|
54
71
|
if (source.allHeaders.cookie) {
|
|
55
|
-
code.push('%s %s', opts.short ? '-b' : '--cookie', helpers.quote(source.allHeaders.cookie))
|
|
72
|
+
code.push('%s %s', opts.short ? '-b' : '--cookie', helpers.quote(source.allHeaders.cookie));
|
|
56
73
|
}
|
|
57
74
|
|
|
58
75
|
// construct post params
|
|
59
76
|
switch (source.postData.mimeType) {
|
|
60
77
|
case 'multipart/form-data':
|
|
61
|
-
source.postData.params
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
78
|
+
if (source.postData.params) {
|
|
79
|
+
source.postData.params.forEach(function (param) {
|
|
80
|
+
let post = '';
|
|
81
|
+
if (param.fileName) {
|
|
82
|
+
post = format('%s=@%s', param.name, param.fileName);
|
|
83
|
+
} else {
|
|
84
|
+
post = format('%s=%s', param.name, param.value);
|
|
85
|
+
}
|
|
68
86
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
87
|
+
code.push('%s %s', opts.short ? '-F' : '--form', helpers.quote(post));
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
72
91
|
|
|
73
92
|
case 'application/x-www-form-urlencoded':
|
|
74
93
|
if (source.postData.params) {
|
|
75
94
|
source.postData.params.forEach(function (param) {
|
|
76
95
|
code.push(
|
|
77
|
-
'%s %s',
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
96
|
+
'%s %s',
|
|
97
|
+
opts.binary ? '--data-binary' : opts.short ? '-d' : '--data',
|
|
98
|
+
helpers.quote(format('%s=%s', param.name, param.value))
|
|
99
|
+
);
|
|
100
|
+
});
|
|
81
101
|
} else {
|
|
82
102
|
code.push(
|
|
83
|
-
'%s %s',
|
|
103
|
+
'%s %s',
|
|
104
|
+
opts.binary ? '--data-binary' : opts.short ? '-d' : '--data',
|
|
84
105
|
helpers.quote(source.postData.text)
|
|
85
|
-
)
|
|
106
|
+
);
|
|
86
107
|
}
|
|
87
|
-
break
|
|
108
|
+
break;
|
|
88
109
|
|
|
89
110
|
default:
|
|
90
111
|
// raw request body
|
|
91
112
|
if (source.postData.text) {
|
|
92
|
-
let builtPayload = false
|
|
113
|
+
let builtPayload = false;
|
|
93
114
|
|
|
94
115
|
// If we're dealing with a JSON variant, and our payload is JSON let's make it look a little nicer.
|
|
95
116
|
if (headerHelpers.isMimeTypeJson(source.postData.mimeType)) {
|
|
@@ -97,18 +118,18 @@ module.exports = function (source, options) {
|
|
|
97
118
|
// overly lengthy
|
|
98
119
|
if (source.postData.text.length > 20) {
|
|
99
120
|
try {
|
|
100
|
-
const jsonPayload = JSON.parse(source.postData.text)
|
|
121
|
+
const jsonPayload = JSON.parse(source.postData.text);
|
|
101
122
|
|
|
102
123
|
// If the JSON object has a single quote we should prepare it inside of a HEREDOC because the single
|
|
103
124
|
// quote in something like `string's` can't be escaped when used with `--data`.
|
|
104
125
|
//
|
|
105
126
|
// Basically this boils down to `--data @- <<EOF...EOF` vs `--data '...'`.
|
|
106
|
-
builtPayload = true
|
|
127
|
+
builtPayload = true;
|
|
107
128
|
code.push(
|
|
108
129
|
source.postData.text.indexOf("'") > 0 ? '%s @- <<EOF\n%s\nEOF' : "%s '\n%s\n'",
|
|
109
|
-
opts.binary ? '--data-binary' :
|
|
130
|
+
opts.binary ? '--data-binary' : opts.short ? '-d' : '--data',
|
|
110
131
|
JSON.stringify(jsonPayload, null, opts.indent)
|
|
111
|
-
)
|
|
132
|
+
);
|
|
112
133
|
} catch (err) {
|
|
113
134
|
// no-op
|
|
114
135
|
}
|
|
@@ -117,19 +138,20 @@ module.exports = function (source, options) {
|
|
|
117
138
|
|
|
118
139
|
if (!builtPayload) {
|
|
119
140
|
code.push(
|
|
120
|
-
'%s %s',
|
|
141
|
+
'%s %s',
|
|
142
|
+
opts.binary ? '--data-binary' : opts.short ? '-d' : '--data',
|
|
121
143
|
helpers.quote(source.postData.text)
|
|
122
|
-
)
|
|
144
|
+
);
|
|
123
145
|
}
|
|
124
146
|
}
|
|
125
147
|
}
|
|
126
148
|
|
|
127
|
-
return code.join()
|
|
128
|
-
}
|
|
149
|
+
return code.join();
|
|
150
|
+
};
|
|
129
151
|
|
|
130
152
|
module.exports.info = {
|
|
131
153
|
key: 'curl',
|
|
132
154
|
title: 'cURL',
|
|
133
155
|
link: 'http://curl.haxx.se/',
|
|
134
|
-
description: 'cURL is a command line tool and library for transferring data with URL syntax'
|
|
135
|
-
}
|
|
156
|
+
description: 'cURL is a command line tool and library for transferring data with URL syntax',
|
|
157
|
+
};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const util = require('util')
|
|
1
|
+
const { format } = require('util');
|
|
4
2
|
|
|
5
3
|
module.exports = {
|
|
6
4
|
/**
|
|
@@ -9,17 +7,17 @@ module.exports = {
|
|
|
9
7
|
* http://wiki.bash-hackers.org/syntax/quoting#strong_quoting
|
|
10
8
|
*/
|
|
11
9
|
quote: function (value) {
|
|
12
|
-
const safe = /^[a-z0-9-_/.@%^=:]+$/i
|
|
10
|
+
const safe = /^[a-z0-9-_/.@%^=:]+$/i;
|
|
13
11
|
|
|
14
12
|
// Unless `value` is a simple shell-safe string, quote it.
|
|
15
13
|
if (!safe.test(value)) {
|
|
16
|
-
return
|
|
14
|
+
return format("'%s'", value.replace(/'/g, "'\\''"));
|
|
17
15
|
}
|
|
18
16
|
|
|
19
|
-
return value
|
|
17
|
+
return value;
|
|
20
18
|
},
|
|
21
19
|
|
|
22
20
|
escape: function (value) {
|
|
23
|
-
return value.replace(/\r/g, '\\r').replace(/\n/g, '\\n')
|
|
24
|
-
}
|
|
25
|
-
}
|
|
21
|
+
return value.replace(/\r/g, '\\r').replace(/\n/g, '\\n');
|
|
22
|
+
},
|
|
23
|
+
};
|
|
@@ -8,14 +8,12 @@
|
|
|
8
8
|
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const shell = require('./helpers')
|
|
15
|
-
const CodeBuilder = require('../../helpers/code-builder')
|
|
11
|
+
const { format } = require('util');
|
|
12
|
+
const shell = require('./helpers');
|
|
13
|
+
const CodeBuilder = require('../../helpers/code-builder');
|
|
16
14
|
|
|
17
15
|
module.exports = function (source, options) {
|
|
18
|
-
const opts =
|
|
16
|
+
const opts = {
|
|
19
17
|
body: false,
|
|
20
18
|
cert: false,
|
|
21
19
|
headers: false,
|
|
@@ -27,97 +25,105 @@ module.exports = function (source, options) {
|
|
|
27
25
|
style: false,
|
|
28
26
|
timeout: false,
|
|
29
27
|
verbose: false,
|
|
30
|
-
verify: false
|
|
31
|
-
|
|
28
|
+
verify: false,
|
|
29
|
+
...options,
|
|
30
|
+
};
|
|
32
31
|
|
|
33
|
-
const code = new CodeBuilder(opts.indent, opts.indent !== false ?
|
|
32
|
+
const code = new CodeBuilder(opts.indent, opts.indent !== false ? ` \\\n${opts.indent}` : ' ');
|
|
34
33
|
|
|
35
|
-
let raw = false
|
|
36
|
-
const flags = []
|
|
34
|
+
let raw = false;
|
|
35
|
+
const flags = [];
|
|
37
36
|
|
|
38
37
|
if (opts.headers) {
|
|
39
|
-
flags.push(opts.short ? '-h' : '--headers')
|
|
38
|
+
flags.push(opts.short ? '-h' : '--headers');
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
if (opts.body) {
|
|
43
|
-
flags.push(opts.short ? '-b' : '--body')
|
|
42
|
+
flags.push(opts.short ? '-b' : '--body');
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
if (opts.verbose) {
|
|
47
|
-
flags.push(opts.short ? '-v' : '--verbose')
|
|
46
|
+
flags.push(opts.short ? '-v' : '--verbose');
|
|
48
47
|
}
|
|
49
48
|
|
|
50
49
|
if (opts.print) {
|
|
51
|
-
flags.push(
|
|
50
|
+
flags.push(format('%s=%s', opts.short ? '-p' : '--print', opts.print));
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
if (opts.verify) {
|
|
55
|
-
flags.push(
|
|
54
|
+
flags.push(format('--verify=%s', opts.verify));
|
|
56
55
|
}
|
|
57
56
|
|
|
58
57
|
if (opts.cert) {
|
|
59
|
-
flags.push(
|
|
58
|
+
flags.push(format('--cert=%s', opts.cert));
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
if (opts.pretty) {
|
|
63
|
-
flags.push(
|
|
62
|
+
flags.push(format('--pretty=%s', opts.pretty));
|
|
64
63
|
}
|
|
65
64
|
|
|
66
65
|
if (opts.style) {
|
|
67
|
-
flags.push(
|
|
66
|
+
flags.push(format('--style=%s', opts.pretty));
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
if (opts.timeout) {
|
|
71
|
-
flags.push(
|
|
70
|
+
flags.push(format('--timeout=%s', opts.timeout));
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
// construct query params
|
|
75
74
|
if (opts.queryParams) {
|
|
76
|
-
const queryStringKeys = Object.keys(source.queryObj)
|
|
75
|
+
const queryStringKeys = Object.keys(source.queryObj);
|
|
77
76
|
|
|
78
77
|
queryStringKeys.forEach(function (name) {
|
|
79
|
-
const value = source.queryObj[name]
|
|
78
|
+
const value = source.queryObj[name];
|
|
80
79
|
|
|
81
80
|
if (Array.isArray(value)) {
|
|
82
81
|
value.forEach(function (val) {
|
|
83
|
-
code.push('%s==%s', name, shell.quote(val))
|
|
84
|
-
})
|
|
82
|
+
code.push('%s==%s', name, shell.quote(val));
|
|
83
|
+
});
|
|
85
84
|
} else {
|
|
86
|
-
code.push('%s==%s', name, shell.quote(value))
|
|
85
|
+
code.push('%s==%s', name, shell.quote(value));
|
|
87
86
|
}
|
|
88
|
-
})
|
|
87
|
+
});
|
|
89
88
|
}
|
|
90
89
|
|
|
91
90
|
// construct headers
|
|
92
|
-
Object.keys(source.allHeaders)
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
Object.keys(source.allHeaders)
|
|
92
|
+
.sort()
|
|
93
|
+
.forEach(function (key) {
|
|
94
|
+
code.push('%s:%s', key, shell.quote(source.allHeaders[key]));
|
|
95
|
+
});
|
|
95
96
|
|
|
96
97
|
if (source.postData.mimeType === 'application/x-www-form-urlencoded') {
|
|
97
98
|
// construct post params
|
|
98
99
|
if (source.postData.params && source.postData.params.length) {
|
|
99
|
-
flags.push(opts.short ? '-f' : '--form')
|
|
100
|
+
flags.push(opts.short ? '-f' : '--form');
|
|
100
101
|
|
|
101
102
|
source.postData.params.forEach(function (param) {
|
|
102
|
-
code.push('%s=%s', param.name, shell.quote(param.value))
|
|
103
|
-
})
|
|
103
|
+
code.push('%s=%s', param.name, shell.quote(param.value));
|
|
104
|
+
});
|
|
104
105
|
}
|
|
105
106
|
} else {
|
|
106
|
-
raw = true
|
|
107
|
+
raw = true;
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
code.unshift(
|
|
110
|
+
code.unshift(
|
|
111
|
+
'http %s%s %s',
|
|
112
|
+
flags.length ? `${flags.join(' ')} ` : '',
|
|
113
|
+
source.method,
|
|
114
|
+
shell.quote(opts.queryParams ? source.url : source.fullUrl)
|
|
115
|
+
);
|
|
110
116
|
|
|
111
117
|
if (raw && source.postData.text) {
|
|
112
|
-
code.unshift('echo %s | ', shell.quote(source.postData.text))
|
|
118
|
+
code.unshift('echo %s | ', shell.quote(source.postData.text));
|
|
113
119
|
}
|
|
114
120
|
|
|
115
|
-
return code.join()
|
|
116
|
-
}
|
|
121
|
+
return code.join();
|
|
122
|
+
};
|
|
117
123
|
|
|
118
124
|
module.exports.info = {
|
|
119
125
|
key: 'httpie',
|
|
120
126
|
title: 'HTTPie',
|
|
121
127
|
link: 'http://httpie.org/',
|
|
122
|
-
description: 'a CLI, cURL-like tool for humans'
|
|
123
|
-
}
|
|
128
|
+
description: 'a CLI, cURL-like tool for humans',
|
|
129
|
+
};
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
1
|
module.exports = {
|
|
4
2
|
info: {
|
|
5
3
|
key: 'shell',
|
|
6
4
|
title: 'Shell',
|
|
7
5
|
extname: '.sh',
|
|
8
|
-
default: 'curl'
|
|
6
|
+
default: 'curl',
|
|
7
|
+
cli: '%s',
|
|
9
8
|
},
|
|
10
9
|
|
|
11
10
|
curl: require('./curl'),
|
|
12
11
|
httpie: require('./httpie'),
|
|
13
|
-
wget: require('./wget')
|
|
14
|
-
}
|
|
12
|
+
wget: require('./wget'),
|
|
13
|
+
};
|
|
@@ -8,47 +8,45 @@
|
|
|
8
8
|
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const helpers = require('./helpers')
|
|
15
|
-
const CodeBuilder = require('../../helpers/code-builder')
|
|
11
|
+
const { format } = require('util');
|
|
12
|
+
const helpers = require('./helpers');
|
|
13
|
+
const CodeBuilder = require('../../helpers/code-builder');
|
|
16
14
|
|
|
17
15
|
module.exports = function (source, options) {
|
|
18
|
-
const opts =
|
|
16
|
+
const opts = {
|
|
19
17
|
indent: ' ',
|
|
20
18
|
short: false,
|
|
21
|
-
verbose: false
|
|
22
|
-
|
|
19
|
+
verbose: false,
|
|
20
|
+
...options,
|
|
21
|
+
};
|
|
23
22
|
|
|
24
|
-
const code = new CodeBuilder(opts.indent, opts.indent !== false ?
|
|
23
|
+
const code = new CodeBuilder(opts.indent, opts.indent !== false ? ` \\\n${opts.indent}` : ' ');
|
|
25
24
|
|
|
26
25
|
if (opts.verbose) {
|
|
27
|
-
code.push('wget %s', opts.short ? '-v' : '--verbose')
|
|
26
|
+
code.push('wget %s', opts.short ? '-v' : '--verbose');
|
|
28
27
|
} else {
|
|
29
|
-
code.push('wget %s', opts.short ? '-q' : '--quiet')
|
|
28
|
+
code.push('wget %s', opts.short ? '-q' : '--quiet');
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
code.push('--method %s', helpers.quote(source.method))
|
|
31
|
+
code.push('--method %s', helpers.quote(source.method));
|
|
33
32
|
|
|
34
33
|
Object.keys(source.allHeaders).forEach(function (key) {
|
|
35
|
-
const header =
|
|
36
|
-
code.push('--header %s', helpers.quote(header))
|
|
37
|
-
})
|
|
34
|
+
const header = format('%s: %s', key, source.allHeaders[key]);
|
|
35
|
+
code.push('--header %s', helpers.quote(header));
|
|
36
|
+
});
|
|
38
37
|
|
|
39
38
|
if (source.postData.text) {
|
|
40
|
-
code.push(
|
|
39
|
+
code.push(`--body-data ${helpers.escape(helpers.quote(source.postData.text))}`);
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
code.push(opts.short ? '-O' : '--output-document')
|
|
44
|
-
.push('- %s', helpers.quote(source.fullUrl))
|
|
42
|
+
code.push(opts.short ? '-O' : '--output-document').push('- %s', helpers.quote(source.fullUrl));
|
|
45
43
|
|
|
46
|
-
return code.join()
|
|
47
|
-
}
|
|
44
|
+
return code.join();
|
|
45
|
+
};
|
|
48
46
|
|
|
49
47
|
module.exports.info = {
|
|
50
48
|
key: 'wget',
|
|
51
49
|
title: 'Wget',
|
|
52
50
|
link: 'https://www.gnu.org/software/wget/',
|
|
53
|
-
description: 'a free software package for retrieving files using HTTP, HTTPS'
|
|
54
|
-
}
|
|
51
|
+
description: 'a free software package for retrieving files using HTTP, HTTPS',
|
|
52
|
+
};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const util = require('util')
|
|
1
|
+
const { format } = require('util');
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* Create an string of given length filled with blank spaces
|
|
@@ -9,24 +7,25 @@ const util = require('util')
|
|
|
9
7
|
* @param {string} str String to pad out with
|
|
10
8
|
* @return {string}
|
|
11
9
|
*/
|
|
12
|
-
function buildString
|
|
13
|
-
|
|
10
|
+
function buildString(length, str) {
|
|
11
|
+
// eslint-disable-next-line prefer-spread
|
|
12
|
+
return Array.apply(null, new Array(length)).map(String.prototype.valueOf, str).join('');
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* Create a string corresponding to a Dictionary or Array literal representation with pretty option
|
|
18
17
|
* and indentation.
|
|
19
18
|
*/
|
|
20
|
-
function concatArray
|
|
21
|
-
const currentIndent = buildString(indentLevel, indentation)
|
|
22
|
-
const closingBraceIndent = buildString(indentLevel - 1, indentation)
|
|
23
|
-
const join = pretty ?
|
|
19
|
+
function concatArray(arr, pretty, indentation, indentLevel) {
|
|
20
|
+
const currentIndent = buildString(indentLevel, indentation);
|
|
21
|
+
const closingBraceIndent = buildString(indentLevel - 1, indentation);
|
|
22
|
+
const join = pretty ? `,\n${currentIndent}` : ', ';
|
|
24
23
|
|
|
25
24
|
if (pretty) {
|
|
26
|
-
return
|
|
27
|
-
} else {
|
|
28
|
-
return '[' + arr.join(join) + ']'
|
|
25
|
+
return `[\n${currentIndent}${arr.join(join)}\n${closingBraceIndent}]`;
|
|
29
26
|
}
|
|
27
|
+
|
|
28
|
+
return `[${arr.join(join)}]`;
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
module.exports = {
|
|
@@ -39,7 +38,7 @@ module.exports = {
|
|
|
39
38
|
* @return {string}
|
|
40
39
|
*/
|
|
41
40
|
literalDeclaration: function (name, parameters, opts) {
|
|
42
|
-
return
|
|
41
|
+
return format('let %s = %s', name, this.literalRepresentation(parameters, opts));
|
|
43
42
|
},
|
|
44
43
|
|
|
45
44
|
/**
|
|
@@ -50,41 +49,45 @@ module.exports = {
|
|
|
50
49
|
* @return {string}
|
|
51
50
|
*/
|
|
52
51
|
literalRepresentation: function (value, opts, indentLevel) {
|
|
53
|
-
|
|
52
|
+
// eslint-disable-next-line no-param-reassign
|
|
53
|
+
indentLevel = indentLevel === undefined ? 1 : indentLevel + 1;
|
|
54
54
|
|
|
55
55
|
switch (Object.prototype.toString.call(value)) {
|
|
56
56
|
case '[object Number]':
|
|
57
|
-
return value
|
|
57
|
+
return value;
|
|
58
58
|
|
|
59
59
|
case '[object Array]': {
|
|
60
60
|
// Don't prettify arrays nto not take too much space
|
|
61
|
-
let pretty = false
|
|
62
|
-
const valuesRepresentation = value.map(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
61
|
+
let pretty = false;
|
|
62
|
+
const valuesRepresentation = value.map(
|
|
63
|
+
function (v) {
|
|
64
|
+
// Switch to prettify if the value is a dictionary with multiple keys
|
|
65
|
+
if (Object.prototype.toString.call(v) === '[object Object]') {
|
|
66
|
+
pretty = Object.keys(v).length > 1;
|
|
67
|
+
}
|
|
68
|
+
return this.literalRepresentation(v, opts, indentLevel);
|
|
69
|
+
}.bind(this)
|
|
70
|
+
);
|
|
71
|
+
return concatArray(valuesRepresentation, pretty, opts.indent, indentLevel);
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
case '[object Object]': {
|
|
73
|
-
const keyValuePairs = []
|
|
75
|
+
const keyValuePairs = [];
|
|
76
|
+
// eslint-disable-next-line guard-for-in, no-restricted-syntax
|
|
74
77
|
for (const k in value) {
|
|
75
|
-
keyValuePairs.push(
|
|
78
|
+
keyValuePairs.push(format('"%s": %s', k, this.literalRepresentation(value[k], opts, indentLevel)));
|
|
76
79
|
}
|
|
77
|
-
return concatArray(keyValuePairs, opts.pretty && keyValuePairs.length > 1, opts.indent, indentLevel)
|
|
80
|
+
return concatArray(keyValuePairs, opts.pretty && keyValuePairs.length > 1, opts.indent, indentLevel);
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
case '[object Boolean]':
|
|
81
|
-
return value.toString()
|
|
84
|
+
return value.toString();
|
|
82
85
|
|
|
83
86
|
default:
|
|
84
87
|
if (value === null || value === undefined) {
|
|
85
|
-
return ''
|
|
88
|
+
return '';
|
|
86
89
|
}
|
|
87
|
-
return
|
|
90
|
+
return `"${value.toString().replace(/"/g, '\\"')}"`;
|
|
88
91
|
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
92
|
+
},
|
|
93
|
+
};
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
1
|
module.exports = {
|
|
4
2
|
info: {
|
|
5
3
|
key: 'swift',
|
|
6
4
|
title: 'Swift',
|
|
7
5
|
extname: '.swift',
|
|
8
|
-
default: 'nsurlsession'
|
|
6
|
+
default: 'nsurlsession',
|
|
9
7
|
},
|
|
10
8
|
|
|
11
|
-
nsurlsession: require('./nsurlsession')
|
|
12
|
-
}
|
|
9
|
+
nsurlsession: require('./nsurlsession'),
|
|
10
|
+
};
|