@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.
Files changed (68) hide show
  1. package/README.md +19 -9
  2. package/package.json +24 -28
  3. package/src/helpers/code-builder.js +85 -80
  4. package/src/helpers/form-data.js +27 -25
  5. package/src/helpers/headers.js +10 -19
  6. package/src/helpers/reducer.js +10 -14
  7. package/src/index.js +167 -146
  8. package/src/targets/c/index.js +3 -5
  9. package/src/targets/c/libcurl.js +18 -23
  10. package/src/targets/clojure/clj_http.js +103 -87
  11. package/src/targets/clojure/index.js +3 -5
  12. package/src/targets/csharp/httpclient.js +90 -90
  13. package/src/targets/csharp/index.js +3 -5
  14. package/src/targets/csharp/restsharp.js +20 -22
  15. package/src/targets/go/index.js +3 -5
  16. package/src/targets/go/native.js +46 -53
  17. package/src/targets/http/http1.1.js +26 -36
  18. package/src/targets/http/index.js +3 -5
  19. package/src/targets/index.js +2 -4
  20. package/src/targets/java/asynchttp.js +22 -23
  21. package/src/targets/java/index.js +3 -5
  22. package/src/targets/java/nethttp.js +20 -24
  23. package/src/targets/java/okhttp.js +31 -31
  24. package/src/targets/java/unirest.js +22 -19
  25. package/src/targets/javascript/axios.js +43 -38
  26. package/src/targets/javascript/fetch.js +66 -68
  27. package/src/targets/javascript/index.js +3 -5
  28. package/src/targets/javascript/jquery.js +46 -40
  29. package/src/targets/javascript/xhr.js +42 -38
  30. package/src/targets/kotlin/index.js +3 -5
  31. package/src/targets/kotlin/okhttp.js +31 -31
  32. package/src/targets/node/axios.js +33 -30
  33. package/src/targets/node/fetch.js +89 -83
  34. package/src/targets/node/index.js +4 -5
  35. package/src/targets/node/native.js +36 -30
  36. package/src/targets/node/request.js +64 -64
  37. package/src/targets/node/unirest.js +56 -55
  38. package/src/targets/objc/helpers.js +24 -23
  39. package/src/targets/objc/index.js +3 -5
  40. package/src/targets/objc/nsurlsession.js +73 -45
  41. package/src/targets/ocaml/cohttp.js +29 -27
  42. package/src/targets/ocaml/index.js +3 -5
  43. package/src/targets/php/curl.js +86 -82
  44. package/src/targets/php/guzzle.js +135 -0
  45. package/src/targets/php/helpers.js +29 -28
  46. package/src/targets/php/http1.js +33 -44
  47. package/src/targets/php/http2.js +70 -71
  48. package/src/targets/php/index.js +5 -5
  49. package/src/targets/powershell/common.js +35 -30
  50. package/src/targets/powershell/index.js +3 -5
  51. package/src/targets/powershell/restmethod.js +3 -5
  52. package/src/targets/powershell/webrequest.js +3 -5
  53. package/src/targets/python/helpers.js +37 -34
  54. package/src/targets/python/index.js +4 -5
  55. package/src/targets/python/python3.js +33 -44
  56. package/src/targets/python/requests.js +47 -72
  57. package/src/targets/r/httr.js +59 -70
  58. package/src/targets/r/index.js +3 -5
  59. package/src/targets/ruby/index.js +3 -5
  60. package/src/targets/ruby/native.js +39 -33
  61. package/src/targets/shell/curl.js +74 -52
  62. package/src/targets/shell/helpers.js +7 -9
  63. package/src/targets/shell/httpie.js +45 -39
  64. package/src/targets/shell/index.js +4 -5
  65. package/src/targets/shell/wget.js +20 -22
  66. package/src/targets/swift/helpers.js +35 -32
  67. package/src/targets/swift/index.js +3 -5
  68. package/src/targets/swift/nsurlsession.js +53 -39
@@ -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
- 'use strict'
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 = Object.assign({
15
+ const opts = {
18
16
  closingTag: false,
19
17
  indent: ' ',
20
18
  noTags: false,
21
- shortTags: false
22
- }, options)
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 (!~helpers.methods.indexOf(source.method.toUpperCase())) {
32
- code.push('HttpRequest::methodRegister(\'%s\');', source.method)
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 (~helpers.methods.indexOf(source.method.toUpperCase())) {
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
- switch (source.postData.mimeType) {
62
- case 'application/x-www-form-urlencoded':
63
- code.push('$request->setContentType(%s);', helpers.convert(source.postData.mimeType))
64
- .push('$request->setPostFields(%s);', helpers.convert(source.postData.paramsObj, opts.indent))
65
- .blank()
66
- break
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.push('try {')
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
+ };
@@ -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
- 'use strict'
12
-
13
- const helpers = require('./helpers')
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 = Object.assign({
16
+ const opts = {
19
17
  closingTag: false,
20
18
  indent: ' ',
21
19
  noTags: false,
22
- shortTags: false
23
- }, options)
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.push('$body = new http\\Message\\Body;')
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
- const files = []
47
- const fields = {}
48
-
49
- source.postData.params.forEach(function (param) {
50
- if (param.fileName) {
51
- files.push({
52
- name: param.name,
53
- type: param.contentType,
54
- file: param.fileName,
55
- data: param.value
56
- })
57
- } else if (param.value) {
58
- fields[param.name] = param.value
59
- }
60
- })
61
-
62
- code.push('$body = new http\\Message\\Body;')
63
- .push('$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').indexOf('boundary')) {
71
- delete source.headersObj[headerHelpers.getHeaderName(source.headersObj, 'content-type')]
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
- code.blank()
76
+ code.blank();
76
77
 
77
- hasBody = true
78
- break
78
+ hasBody = true;
79
+ }
80
+ break;
79
81
  }
80
82
 
81
83
  default:
82
84
  if (source.postData.text) {
83
- code.push('$body = new http\\Message\\Body;')
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.push('$request->setRequestUrl(%s);', helpers.convert(source.url))
91
- .push('$request->setRequestMethod(%s);', helpers.convert(source.method))
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.push('$client->enqueue($request)->send();')
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
+ };
@@ -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
- 'use strict'
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, options) {
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.indexOf(source.method.toUpperCase()) === -1) {
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') { // Not allowed
25
- code.push('$headers.Add("%s", "%s")', key, source.headersObj[key])
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("-ContentType '" + helpers.getHeader(source.allHeaders, 'content-type') + "'")
49
- commandOptions.push("-Body '" + source.postData.text + "'")
47
+ commandOptions.push(`-ContentType '${helpers.getHeader(source.allHeaders, 'content-type')}'`);
48
+ commandOptions.push(`-Body '${source.postData.text}'`);
50
49
  }
51
50
 
52
- code.push("$response = %s -Uri '%s' -Method %s %s", command, source.fullUrl, source.method, commandOptions.join(' '))
53
- return code.join()
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
- 'use strict'
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
- 'use strict'
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
- 'use strict'
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 (length, str) {
13
- return Array.apply(null, new Array(length)).map(String.prototype.valueOf, str).join('')
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 (concatType, values, pretty, indentation, indentLevel) {
21
- const currentIndent = buildString(indentLevel, indentation)
22
- const closingBraceIndent = buildString(indentLevel - 1, indentation)
23
- const join = pretty ? ',\n' + currentIndent : ', '
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 + '\n' + currentIndent + values.join(join) + '\n' + closingBraceIndent + closingBrace
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
- indentLevel = indentLevel === undefined ? 1 : indentLevel + 1
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(function (v) {
52
- // Switch to prettify if the value is a dictionary with multiple keys
53
- if (Object.prototype.toString.call(v) === '[object Object]') {
54
- pretty = Object.keys(v).length > 1
55
- }
56
- return this.literalRepresentation(v, opts, indentLevel)
57
- }.bind(this))
58
- return concatValues('array', valuesRepresentation, pretty, opts.indent, indentLevel)
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(util.format('"%s": %s', k, this.literalRepresentation(value[k], opts, indentLevel)))
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 '"' + value.toString().replace(/"/g, '\\"') + '"'
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
+ };