@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
package/src/targets/php/http1.js
CHANGED
|
@@ -8,89 +8,78 @@
|
|
|
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 helpers = require('./helpers')
|
|
14
|
-
const CodeBuilder = require('../../helpers/code-builder')
|
|
11
|
+
const helpers = require('./helpers');
|
|
12
|
+
const CodeBuilder = require('../../helpers/code-builder');
|
|
15
13
|
|
|
16
14
|
module.exports = function (source, options) {
|
|
17
|
-
const opts =
|
|
15
|
+
const opts = {
|
|
18
16
|
closingTag: false,
|
|
19
17
|
indent: ' ',
|
|
20
18
|
noTags: false,
|
|
21
|
-
shortTags: false
|
|
22
|
-
|
|
19
|
+
shortTags: false,
|
|
20
|
+
...options,
|
|
21
|
+
};
|
|
23
22
|
|
|
24
|
-
const code = new CodeBuilder(opts.indent)
|
|
23
|
+
const code = new CodeBuilder(opts.indent);
|
|
25
24
|
|
|
26
25
|
if (!opts.noTags) {
|
|
27
|
-
code.push(opts.shortTags ? '<?' : '<?php')
|
|
28
|
-
.blank()
|
|
26
|
+
code.push(opts.shortTags ? '<?' : '<?php').blank();
|
|
29
27
|
}
|
|
30
28
|
|
|
31
|
-
if (
|
|
32
|
-
code.push(
|
|
29
|
+
if (!helpers.methods.includes(source.method.toUpperCase())) {
|
|
30
|
+
code.push("HttpRequest::methodRegister('%s');", source.method);
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
code.push('$request = new HttpRequest();')
|
|
36
|
-
.push('$request->setUrl(%s);', helpers.convert(source.url))
|
|
33
|
+
code.push('$request = new HttpRequest();').push('$request->setUrl(%s);', helpers.convert(source.url));
|
|
37
34
|
|
|
38
|
-
if (
|
|
39
|
-
code.push('$request->setMethod(HTTP_METH_%s);', source.method.toUpperCase())
|
|
35
|
+
if (helpers.methods.includes(source.method.toUpperCase())) {
|
|
36
|
+
code.push('$request->setMethod(HTTP_METH_%s);', source.method.toUpperCase());
|
|
40
37
|
} else {
|
|
41
|
-
code.push('$request->setMethod(HttpRequest::HTTP_METH_%s);', source.method.toUpperCase())
|
|
38
|
+
code.push('$request->setMethod(HttpRequest::HTTP_METH_%s);', source.method.toUpperCase());
|
|
42
39
|
}
|
|
43
40
|
|
|
44
|
-
code.blank()
|
|
41
|
+
code.blank();
|
|
45
42
|
|
|
46
43
|
if (Object.keys(source.queryObj).length) {
|
|
47
|
-
code.push('$request->setQueryData(%s);', helpers.convert(source.queryObj, opts.indent))
|
|
48
|
-
.blank()
|
|
44
|
+
code.push('$request->setQueryData(%s);', helpers.convert(source.queryObj, opts.indent)).blank();
|
|
49
45
|
}
|
|
50
46
|
|
|
51
47
|
if (Object.keys(source.headersObj).length) {
|
|
52
|
-
code.push('$request->setHeaders(%s);', helpers.convert(source.headersObj, opts.indent))
|
|
53
|
-
.blank()
|
|
48
|
+
code.push('$request->setHeaders(%s);', helpers.convert(source.headersObj, opts.indent)).blank();
|
|
54
49
|
}
|
|
55
50
|
|
|
56
51
|
if (Object.keys(source.cookiesObj).length) {
|
|
57
|
-
code.push('$request->setCookies(%s);', helpers.convert(source.cookiesObj, opts.indent))
|
|
58
|
-
.blank()
|
|
52
|
+
code.push('$request->setCookies(%s);', helpers.convert(source.cookiesObj, opts.indent)).blank();
|
|
59
53
|
}
|
|
60
54
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
default:
|
|
69
|
-
if (source.postData.text) {
|
|
70
|
-
code.push('$request->setBody(%s);', helpers.convert(source.postData.text))
|
|
71
|
-
.blank()
|
|
72
|
-
}
|
|
55
|
+
if (source.postData.mimeType === 'application/x-www-form-urlencoded') {
|
|
56
|
+
code
|
|
57
|
+
.push('$request->setContentType(%s);', helpers.convert(source.postData.mimeType))
|
|
58
|
+
.push('$request->setPostFields(%s);', helpers.convert(source.postData.paramsObj, opts.indent))
|
|
59
|
+
.blank();
|
|
60
|
+
} else if (source.postData.text) {
|
|
61
|
+
code.push('$request->setBody(%s);', helpers.convert(source.postData.text)).blank();
|
|
73
62
|
}
|
|
74
63
|
|
|
75
|
-
code
|
|
64
|
+
code
|
|
65
|
+
.push('try {')
|
|
76
66
|
.push(1, '$response = $request->send();')
|
|
77
67
|
.blank()
|
|
78
68
|
.push(1, 'echo $response->getBody();')
|
|
79
69
|
.push('} catch (HttpException $ex) {')
|
|
80
70
|
.push(1, 'echo $ex;')
|
|
81
|
-
.push('}')
|
|
71
|
+
.push('}');
|
|
82
72
|
|
|
83
73
|
if (!opts.noTags && opts.closingTag) {
|
|
84
|
-
code.blank()
|
|
85
|
-
.push('?>')
|
|
74
|
+
code.blank().push('?>');
|
|
86
75
|
}
|
|
87
76
|
|
|
88
|
-
return code.join()
|
|
89
|
-
}
|
|
77
|
+
return code.join();
|
|
78
|
+
};
|
|
90
79
|
|
|
91
80
|
module.exports.info = {
|
|
92
81
|
key: 'http1',
|
|
93
82
|
title: 'HTTP v1',
|
|
94
83
|
link: 'http://php.net/manual/en/book.http.php',
|
|
95
|
-
description: 'PHP with pecl/http v1'
|
|
96
|
-
}
|
|
84
|
+
description: 'PHP with pecl/http v1',
|
|
85
|
+
};
|
package/src/targets/php/http2.js
CHANGED
|
@@ -8,125 +8,124 @@
|
|
|
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 headerHelpers = require('../../helpers/headers')
|
|
15
|
-
const CodeBuilder = require('../../helpers/code-builder')
|
|
11
|
+
const helpers = require('./helpers');
|
|
12
|
+
const headerHelpers = require('../../helpers/headers');
|
|
13
|
+
const CodeBuilder = require('../../helpers/code-builder');
|
|
16
14
|
|
|
17
15
|
module.exports = function (source, options) {
|
|
18
|
-
const opts =
|
|
16
|
+
const opts = {
|
|
19
17
|
closingTag: false,
|
|
20
18
|
indent: ' ',
|
|
21
19
|
noTags: false,
|
|
22
|
-
shortTags: false
|
|
23
|
-
|
|
20
|
+
shortTags: false,
|
|
21
|
+
...options,
|
|
22
|
+
};
|
|
24
23
|
|
|
25
|
-
const code = new CodeBuilder(opts.indent)
|
|
26
|
-
let hasBody = false
|
|
24
|
+
const code = new CodeBuilder(opts.indent);
|
|
25
|
+
let hasBody = false;
|
|
27
26
|
|
|
28
27
|
if (!opts.noTags) {
|
|
29
|
-
code.push(opts.shortTags ? '<?' : '<?php')
|
|
30
|
-
.blank()
|
|
28
|
+
code.push(opts.shortTags ? '<?' : '<?php').blank();
|
|
31
29
|
}
|
|
32
30
|
|
|
33
|
-
code.push('$client = new http\\Client;')
|
|
34
|
-
.push('$request = new http\\Client\\Request;')
|
|
35
|
-
.blank()
|
|
31
|
+
code.push('$client = new http\\Client;').push('$request = new http\\Client\\Request;').blank();
|
|
36
32
|
|
|
37
33
|
switch (source.postData.mimeType) {
|
|
38
34
|
case 'application/x-www-form-urlencoded':
|
|
39
|
-
code
|
|
35
|
+
code
|
|
36
|
+
.push('$body = new http\\Message\\Body;')
|
|
40
37
|
.push('$body->append(new http\\QueryString(%s));', helpers.convert(source.postData.paramsObj, opts.indent))
|
|
41
|
-
.blank()
|
|
42
|
-
hasBody = true
|
|
43
|
-
break
|
|
38
|
+
.blank();
|
|
39
|
+
hasBody = true;
|
|
40
|
+
break;
|
|
44
41
|
|
|
45
42
|
case 'multipart/form-data': {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
43
|
+
if (source.postData.params) {
|
|
44
|
+
const files = [];
|
|
45
|
+
const fields = {};
|
|
46
|
+
|
|
47
|
+
source.postData.params.forEach(function (param) {
|
|
48
|
+
if (param.fileName) {
|
|
49
|
+
files.push({
|
|
50
|
+
name: param.name,
|
|
51
|
+
type: param.contentType,
|
|
52
|
+
file: param.fileName,
|
|
53
|
+
data: param.value,
|
|
54
|
+
});
|
|
55
|
+
} else if (param.value) {
|
|
56
|
+
fields[param.name] = param.value;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
code
|
|
61
|
+
.push('$body = new http\\Message\\Body;')
|
|
62
|
+
.push(
|
|
63
|
+
'$body->addForm(%s, %s);',
|
|
64
|
+
Object.keys(fields).length ? helpers.convert(fields, opts.indent) : 'null',
|
|
65
|
+
files.length ? helpers.convert(files, opts.indent) : 'null'
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
// remove the contentType header
|
|
69
|
+
if (headerHelpers.hasHeader(source.headersObj, 'content-type')) {
|
|
70
|
+
if (headerHelpers.getHeader(source.headersObj, 'content-type').includes('boundary')) {
|
|
71
|
+
// eslint-disable-next-line no-param-reassign
|
|
72
|
+
delete source.headersObj[headerHelpers.getHeaderName(source.headersObj, 'content-type')];
|
|
73
|
+
}
|
|
72
74
|
}
|
|
73
|
-
}
|
|
74
75
|
|
|
75
|
-
|
|
76
|
+
code.blank();
|
|
76
77
|
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
hasBody = true;
|
|
79
|
+
}
|
|
80
|
+
break;
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
default:
|
|
82
84
|
if (source.postData.text) {
|
|
83
|
-
code
|
|
85
|
+
code
|
|
86
|
+
.push('$body = new http\\Message\\Body;')
|
|
84
87
|
.push('$body->append(%s);', helpers.convert(source.postData.text))
|
|
85
|
-
.blank()
|
|
86
|
-
hasBody = true
|
|
88
|
+
.blank();
|
|
89
|
+
hasBody = true;
|
|
87
90
|
}
|
|
88
91
|
}
|
|
89
92
|
|
|
90
|
-
code
|
|
91
|
-
.push('$request->
|
|
93
|
+
code
|
|
94
|
+
.push('$request->setRequestUrl(%s);', helpers.convert(source.url))
|
|
95
|
+
.push('$request->setRequestMethod(%s);', helpers.convert(source.method));
|
|
92
96
|
|
|
93
97
|
if (hasBody) {
|
|
94
|
-
code.push('$request->setBody($body);')
|
|
95
|
-
.blank()
|
|
98
|
+
code.push('$request->setBody($body);').blank();
|
|
96
99
|
}
|
|
97
100
|
|
|
98
101
|
if (Object.keys(source.queryObj).length) {
|
|
99
|
-
code.push('$request->setQuery(new http\\QueryString(%s));', helpers.convert(source.queryObj, opts.indent))
|
|
100
|
-
.blank()
|
|
102
|
+
code.push('$request->setQuery(new http\\QueryString(%s));', helpers.convert(source.queryObj, opts.indent)).blank();
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
if (Object.keys(source.headersObj).length) {
|
|
104
|
-
code.push('$request->setHeaders(%s);', helpers.convert(source.headersObj, opts.indent))
|
|
105
|
-
.blank()
|
|
106
|
+
code.push('$request->setHeaders(%s);', helpers.convert(source.headersObj, opts.indent)).blank();
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
if (Object.keys(source.cookiesObj).length) {
|
|
109
|
-
code.blank()
|
|
110
|
-
.push('$client->setCookies(%s);', helpers.convert(source.cookiesObj, opts.indent))
|
|
111
|
-
.blank()
|
|
110
|
+
code.blank().push('$client->setCookies(%s);', helpers.convert(source.cookiesObj, opts.indent)).blank();
|
|
112
111
|
}
|
|
113
112
|
|
|
114
|
-
code
|
|
113
|
+
code
|
|
114
|
+
.push('$client->enqueue($request)->send();')
|
|
115
115
|
.push('$response = $client->getResponse();')
|
|
116
116
|
.blank()
|
|
117
|
-
.push('echo $response->getBody();')
|
|
117
|
+
.push('echo $response->getBody();');
|
|
118
118
|
|
|
119
119
|
if (!opts.noTags && opts.closingTag) {
|
|
120
|
-
code.blank()
|
|
121
|
-
.push('?>')
|
|
120
|
+
code.blank().push('?>');
|
|
122
121
|
}
|
|
123
122
|
|
|
124
|
-
return code.join()
|
|
125
|
-
}
|
|
123
|
+
return code.join();
|
|
124
|
+
};
|
|
126
125
|
|
|
127
126
|
module.exports.info = {
|
|
128
127
|
key: 'http2',
|
|
129
128
|
title: 'HTTP v2',
|
|
130
129
|
link: 'http://devel-m6w6.rhcloud.com/mdref/http',
|
|
131
|
-
description: 'PHP with pecl/http v2'
|
|
132
|
-
}
|
|
130
|
+
description: 'PHP with pecl/http v2',
|
|
131
|
+
};
|
package/src/targets/php/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
1
|
module.exports = {
|
|
4
2
|
info: {
|
|
5
3
|
key: 'php',
|
|
6
4
|
title: 'PHP',
|
|
7
5
|
extname: '.php',
|
|
8
|
-
default: 'curl'
|
|
6
|
+
default: 'curl',
|
|
7
|
+
cli: 'php %s',
|
|
9
8
|
},
|
|
10
9
|
|
|
11
10
|
curl: require('./curl'),
|
|
12
11
|
http1: require('./http1'),
|
|
13
|
-
http2: require('./http2')
|
|
14
|
-
|
|
12
|
+
http2: require('./http2'),
|
|
13
|
+
guzzle: require('./guzzle'),
|
|
14
|
+
};
|
|
@@ -1,55 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const CodeBuilder = require('../../helpers/code-builder')
|
|
4
|
-
const helpers = require('../../helpers/headers')
|
|
1
|
+
const CodeBuilder = require('../../helpers/code-builder');
|
|
2
|
+
const helpers = require('../../helpers/headers');
|
|
5
3
|
|
|
6
4
|
module.exports = function (command) {
|
|
7
|
-
return function (source
|
|
8
|
-
const code = new CodeBuilder()
|
|
9
|
-
const methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS']
|
|
5
|
+
return function (source) {
|
|
6
|
+
const code = new CodeBuilder();
|
|
7
|
+
const methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
|
|
10
8
|
|
|
11
|
-
if (methods.
|
|
12
|
-
return 'Method not supported'
|
|
9
|
+
if (!methods.includes(source.method.toUpperCase())) {
|
|
10
|
+
return 'Method not supported';
|
|
13
11
|
}
|
|
14
12
|
|
|
15
|
-
const commandOptions = []
|
|
13
|
+
const commandOptions = [];
|
|
16
14
|
|
|
17
15
|
// Add headers, including the cookies
|
|
18
|
-
const headers = Object.keys(source.headersObj)
|
|
16
|
+
const headers = Object.keys(source.headersObj);
|
|
19
17
|
|
|
20
18
|
// construct headers
|
|
21
19
|
if (headers.length) {
|
|
22
|
-
code.push('$headers=@{}')
|
|
20
|
+
code.push('$headers=@{}');
|
|
23
21
|
headers.forEach(function (key) {
|
|
24
|
-
if (key !== 'connection') {
|
|
25
|
-
|
|
22
|
+
if (key !== 'connection') {
|
|
23
|
+
// Not allowed
|
|
24
|
+
code.push('$headers.Add("%s", "%s")', key, source.headersObj[key]);
|
|
26
25
|
}
|
|
27
|
-
})
|
|
28
|
-
commandOptions.push('-Headers $headers')
|
|
26
|
+
});
|
|
27
|
+
commandOptions.push('-Headers $headers');
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
// construct cookies
|
|
32
31
|
if (source.cookies.length) {
|
|
33
|
-
code.push('$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession')
|
|
32
|
+
code.push('$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession');
|
|
34
33
|
|
|
35
34
|
source.cookies.forEach(function (cookie) {
|
|
36
|
-
code.push('$cookie = New-Object System.Net.Cookie')
|
|
35
|
+
code.push('$cookie = New-Object System.Net.Cookie');
|
|
37
36
|
|
|
38
|
-
code.push("$cookie.Name = '%s'", cookie.name)
|
|
39
|
-
code.push("$cookie.Value = '%s'", cookie.value)
|
|
40
|
-
code.push("$cookie.Domain = '%s'", source.uriObj.host)
|
|
37
|
+
code.push("$cookie.Name = '%s'", cookie.name);
|
|
38
|
+
code.push("$cookie.Value = '%s'", cookie.value);
|
|
39
|
+
code.push("$cookie.Domain = '%s'", source.uriObj.host);
|
|
41
40
|
|
|
42
|
-
code.push('$session.Cookies.Add($cookie)')
|
|
43
|
-
})
|
|
44
|
-
commandOptions.push('-WebSession $session')
|
|
41
|
+
code.push('$session.Cookies.Add($cookie)');
|
|
42
|
+
});
|
|
43
|
+
commandOptions.push('-WebSession $session');
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
if (source.postData.text) {
|
|
48
|
-
commandOptions.push(
|
|
49
|
-
commandOptions.push(
|
|
47
|
+
commandOptions.push(`-ContentType '${helpers.getHeader(source.allHeaders, 'content-type')}'`);
|
|
48
|
+
commandOptions.push(`-Body '${source.postData.text}'`);
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
code.push(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
code.push(
|
|
52
|
+
"$response = %s -Uri '%s' -Method %s %s",
|
|
53
|
+
command,
|
|
54
|
+
source.fullUrl,
|
|
55
|
+
source.method,
|
|
56
|
+
commandOptions.join(' ')
|
|
57
|
+
);
|
|
58
|
+
return code.join();
|
|
59
|
+
};
|
|
60
|
+
};
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
1
|
module.exports = {
|
|
4
2
|
info: {
|
|
5
3
|
key: 'powershell',
|
|
6
4
|
title: 'Powershell',
|
|
7
5
|
extname: '.ps1',
|
|
8
|
-
default: 'webrequest'
|
|
6
|
+
default: 'webrequest',
|
|
9
7
|
},
|
|
10
8
|
|
|
11
9
|
webrequest: require('./webrequest'),
|
|
12
|
-
restmethod: require('./restmethod')
|
|
13
|
-
}
|
|
10
|
+
restmethod: require('./restmethod'),
|
|
11
|
+
};
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
module.exports = require('./common')('Invoke-RestMethod')
|
|
1
|
+
module.exports = require('./common')('Invoke-RestMethod');
|
|
4
2
|
|
|
5
3
|
module.exports.info = {
|
|
6
4
|
key: 'restmethod',
|
|
7
5
|
title: 'Invoke-RestMethod',
|
|
8
6
|
link: 'https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Invoke-RestMethod',
|
|
9
|
-
description: 'Powershell Invoke-RestMethod client'
|
|
10
|
-
}
|
|
7
|
+
description: 'Powershell Invoke-RestMethod client',
|
|
8
|
+
};
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
module.exports = require('./common')('Invoke-WebRequest')
|
|
1
|
+
module.exports = require('./common')('Invoke-WebRequest');
|
|
4
2
|
|
|
5
3
|
module.exports.info = {
|
|
6
4
|
key: 'webrequest',
|
|
7
5
|
title: 'Invoke-WebRequest',
|
|
8
6
|
link: 'https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Invoke-WebRequest',
|
|
9
|
-
description: 'Powershell Invoke-WebRequest client'
|
|
10
|
-
}
|
|
7
|
+
description: 'Powershell Invoke-WebRequest client',
|
|
8
|
+
};
|
|
@@ -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,26 +7,27 @@ 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 concatValues
|
|
21
|
-
const currentIndent = buildString(indentLevel, indentation)
|
|
22
|
-
const closingBraceIndent = buildString(indentLevel - 1, indentation)
|
|
23
|
-
const join = pretty ?
|
|
24
|
-
const openingBrace = concatType === 'object' ? '{' : '['
|
|
25
|
-
const closingBrace = concatType === 'object' ? '}' : ']'
|
|
19
|
+
function concatValues(concatType, values, pretty, indentation, indentLevel) {
|
|
20
|
+
const currentIndent = buildString(indentLevel, indentation);
|
|
21
|
+
const closingBraceIndent = buildString(indentLevel - 1, indentation);
|
|
22
|
+
const join = pretty ? `,\n${currentIndent}` : ', ';
|
|
23
|
+
const openingBrace = concatType === 'object' ? '{' : '[';
|
|
24
|
+
const closingBrace = concatType === 'object' ? '}' : ']';
|
|
26
25
|
|
|
27
26
|
if (pretty) {
|
|
28
|
-
return openingBrace
|
|
29
|
-
} else {
|
|
30
|
-
return openingBrace + values.join(join) + closingBrace
|
|
27
|
+
return `${openingBrace}\n${currentIndent}${values.join(join)}\n${closingBraceIndent}${closingBrace}`;
|
|
31
28
|
}
|
|
29
|
+
|
|
30
|
+
return openingBrace + values.join(join) + closingBrace;
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
module.exports = {
|
|
@@ -40,43 +39,47 @@ module.exports = {
|
|
|
40
39
|
* @return {string}
|
|
41
40
|
*/
|
|
42
41
|
literalRepresentation: function (value, opts, indentLevel) {
|
|
43
|
-
|
|
42
|
+
// eslint-disable-next-line no-param-reassign
|
|
43
|
+
indentLevel = indentLevel === undefined ? 1 : indentLevel + 1;
|
|
44
44
|
|
|
45
45
|
switch (Object.prototype.toString.call(value)) {
|
|
46
46
|
case '[object Number]':
|
|
47
|
-
return value
|
|
47
|
+
return value;
|
|
48
48
|
|
|
49
49
|
case '[object Array]': {
|
|
50
|
-
let pretty = false
|
|
51
|
-
const valuesRepresentation = value.map(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
let pretty = false;
|
|
51
|
+
const valuesRepresentation = value.map(
|
|
52
|
+
function (v) {
|
|
53
|
+
// Switch to prettify if the value is a dictionary with multiple keys
|
|
54
|
+
if (Object.prototype.toString.call(v) === '[object Object]') {
|
|
55
|
+
pretty = Object.keys(v).length > 1;
|
|
56
|
+
}
|
|
57
|
+
return this.literalRepresentation(v, opts, indentLevel);
|
|
58
|
+
}.bind(this)
|
|
59
|
+
);
|
|
60
|
+
return concatValues('array', valuesRepresentation, pretty, opts.indent, indentLevel);
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
case '[object Object]': {
|
|
62
|
-
const keyValuePairs = []
|
|
64
|
+
const keyValuePairs = [];
|
|
65
|
+
// eslint-disable-next-line guard-for-in, no-restricted-syntax
|
|
63
66
|
for (const k in value) {
|
|
64
|
-
keyValuePairs.push(
|
|
67
|
+
keyValuePairs.push(format('"%s": %s', k, this.literalRepresentation(value[k], opts, indentLevel)));
|
|
65
68
|
}
|
|
66
|
-
return concatValues('object', keyValuePairs, opts.pretty && keyValuePairs.length > 1, opts.indent, indentLevel)
|
|
69
|
+
return concatValues('object', keyValuePairs, opts.pretty && keyValuePairs.length > 1, opts.indent, indentLevel);
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
case '[object Null]':
|
|
70
|
-
return 'None'
|
|
73
|
+
return 'None';
|
|
71
74
|
|
|
72
75
|
case '[object Boolean]':
|
|
73
|
-
return value ? 'True' : 'False'
|
|
76
|
+
return value ? 'True' : 'False';
|
|
74
77
|
|
|
75
78
|
default:
|
|
76
79
|
if (value === null || value === undefined) {
|
|
77
|
-
return ''
|
|
80
|
+
return '';
|
|
78
81
|
}
|
|
79
|
-
return
|
|
82
|
+
return `"${value.toString().replace(/"/g, '\\"')}"`;
|
|
80
83
|
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
84
|
+
},
|
|
85
|
+
};
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
1
|
module.exports = {
|
|
4
2
|
info: {
|
|
5
3
|
key: 'python',
|
|
6
4
|
title: 'Python',
|
|
7
5
|
extname: '.py',
|
|
8
|
-
default: 'python3'
|
|
6
|
+
default: 'python3',
|
|
7
|
+
cli: 'python3 %s',
|
|
9
8
|
},
|
|
10
9
|
|
|
11
10
|
python3: require('./python3'),
|
|
12
|
-
requests: require('./requests')
|
|
13
|
-
}
|
|
11
|
+
requests: require('./requests'),
|
|
12
|
+
};
|