@readme/httpsnippet 2.5.0 → 3.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.
Files changed (69) 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 +78 -51
  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
  69. package/src/.DS_Store +0 -0
@@ -8,83 +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
- 'use strict'
12
-
13
- const util = require('util')
14
- const helpers = require('./helpers')
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 = Object.assign({
17
+ const opts = {
20
18
  indent: ' ',
21
19
  short: false,
22
20
  binary: false,
23
- globOff: false
24
- }, options)
21
+ globOff: false,
22
+ escapeBrackets: false,
23
+ ...options,
24
+ };
25
+
26
+ const code = new CodeBuilder(opts.indent, opts.indent !== false ? ` \\\n${opts.indent}` : ' ');
25
27
 
26
- const code = new CodeBuilder(opts.indent, opts.indent !== false ? ' \\\n' + opts.indent : ' ')
28
+ const globOption = opts.short ? '-g' : '--globoff';
29
+ const requestOption = opts.short ? '-X' : '--request';
30
+ let formattedUrl = helpers.quote(source.fullUrl);
27
31
 
28
- const globOption = opts.short ? '-g' : '--globoff'
29
- const requestOption = opts.short ? '-X' : '--request'
30
- let formattedUrl = helpers.quote(source.fullUrl)
32
+ if (opts.escapeBrackets) {
33
+ formattedUrl = formattedUrl.replace(/\[/g, '\\[').replace(/\]/g, '\\]');
34
+ }
31
35
 
32
- code.push('curl %s %s', requestOption, source.method)
36
+ code.push('curl %s %s', requestOption, source.method);
33
37
  if (opts.globOff) {
34
- formattedUrl = unescape(formattedUrl)
35
- code.push(globOption)
38
+ formattedUrl = unescape(formattedUrl);
39
+ code.push(globOption);
36
40
  }
37
- code.push(util.format('%s%s', opts.short ? '' : '--url ', formattedUrl))
41
+ code.push(format('%s%s', opts.short ? '' : '--url ', formattedUrl));
38
42
 
39
43
  if (source.httpVersion === 'HTTP/1.0') {
40
- 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
+ }
41
61
  }
42
62
 
43
63
  // construct headers
44
- Object.keys(source.headersObj).sort().forEach(function (key) {
45
- const header = util.format('%s: %s', key, source.headersObj[key])
46
- code.push('%s %s', opts.short ? '-H' : '--header', helpers.quote(header))
47
- })
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
+ });
48
70
 
49
71
  if (source.allHeaders.cookie) {
50
- 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));
51
73
  }
52
74
 
53
75
  // construct post params
54
76
  switch (source.postData.mimeType) {
55
77
  case 'multipart/form-data':
56
- source.postData.params.forEach(function (param) {
57
- let post = ''
58
- if (param.fileName) {
59
- post = util.format('%s=@%s', param.name, param.fileName)
60
- } else {
61
- post = util.format('%s=%s', param.name, param.value)
62
- }
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
+ }
63
86
 
64
- code.push('%s %s', opts.short ? '-F' : '--form', helpers.quote(post))
65
- })
66
- break
87
+ code.push('%s %s', opts.short ? '-F' : '--form', helpers.quote(post));
88
+ });
89
+ }
90
+ break;
67
91
 
68
92
  case 'application/x-www-form-urlencoded':
69
93
  if (source.postData.params) {
70
94
  source.postData.params.forEach(function (param) {
71
95
  code.push(
72
- '%s %s', opts.binary ? '--data-binary' : (opts.short ? '-d' : '--data'),
73
- helpers.quote(util.format('%s=%s', param.name, param.value))
74
- )
75
- })
96
+ '%s %s',
97
+ opts.binary ? '--data-binary' : opts.short ? '-d' : '--data',
98
+ helpers.quote(format('%s=%s', param.name, param.value))
99
+ );
100
+ });
76
101
  } else {
77
102
  code.push(
78
- '%s %s', opts.binary ? '--data-binary' : (opts.short ? '-d' : '--data'),
103
+ '%s %s',
104
+ opts.binary ? '--data-binary' : opts.short ? '-d' : '--data',
79
105
  helpers.quote(source.postData.text)
80
- )
106
+ );
81
107
  }
82
- break
108
+ break;
83
109
 
84
110
  default:
85
111
  // raw request body
86
112
  if (source.postData.text) {
87
- let builtPayload = false
113
+ let builtPayload = false;
88
114
 
89
115
  // If we're dealing with a JSON variant, and our payload is JSON let's make it look a little nicer.
90
116
  if (headerHelpers.isMimeTypeJson(source.postData.mimeType)) {
@@ -92,18 +118,18 @@ module.exports = function (source, options) {
92
118
  // overly lengthy
93
119
  if (source.postData.text.length > 20) {
94
120
  try {
95
- const jsonPayload = JSON.parse(source.postData.text)
121
+ const jsonPayload = JSON.parse(source.postData.text);
96
122
 
97
123
  // If the JSON object has a single quote we should prepare it inside of a HEREDOC because the single
98
124
  // quote in something like `string's` can't be escaped when used with `--data`.
99
125
  //
100
126
  // Basically this boils down to `--data @- <<EOF...EOF` vs `--data '...'`.
101
- builtPayload = true
127
+ builtPayload = true;
102
128
  code.push(
103
129
  source.postData.text.indexOf("'") > 0 ? '%s @- <<EOF\n%s\nEOF' : "%s '\n%s\n'",
104
- opts.binary ? '--data-binary' : (opts.short ? '-d' : '--data'),
130
+ opts.binary ? '--data-binary' : opts.short ? '-d' : '--data',
105
131
  JSON.stringify(jsonPayload, null, opts.indent)
106
- )
132
+ );
107
133
  } catch (err) {
108
134
  // no-op
109
135
  }
@@ -112,19 +138,20 @@ module.exports = function (source, options) {
112
138
 
113
139
  if (!builtPayload) {
114
140
  code.push(
115
- '%s %s', opts.binary ? '--data-binary' : (opts.short ? '-d' : '--data'),
141
+ '%s %s',
142
+ opts.binary ? '--data-binary' : opts.short ? '-d' : '--data',
116
143
  helpers.quote(source.postData.text)
117
- )
144
+ );
118
145
  }
119
146
  }
120
147
  }
121
148
 
122
- return code.join()
123
- }
149
+ return code.join();
150
+ };
124
151
 
125
152
  module.exports.info = {
126
153
  key: 'curl',
127
154
  title: 'cURL',
128
155
  link: 'http://curl.haxx.se/',
129
- description: 'cURL is a command line tool and library for transferring data with URL syntax'
130
- }
156
+ description: 'cURL is a command line tool and library for transferring data with URL syntax',
157
+ };
@@ -1,6 +1,4 @@
1
- 'use strict'
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 util.format('\'%s\'', value.replace(/'/g, "'\\''"))
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
- 'use strict'
12
-
13
- const util = require('util')
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 = Object.assign({
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
- }, options)
28
+ verify: false,
29
+ ...options,
30
+ };
32
31
 
33
- const code = new CodeBuilder(opts.indent, opts.indent !== false ? ' \\\n' + opts.indent : ' ')
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(util.format('%s=%s', opts.short ? '-p' : '--print', opts.print))
50
+ flags.push(format('%s=%s', opts.short ? '-p' : '--print', opts.print));
52
51
  }
53
52
 
54
53
  if (opts.verify) {
55
- flags.push(util.format('--verify=%s', opts.verify))
54
+ flags.push(format('--verify=%s', opts.verify));
56
55
  }
57
56
 
58
57
  if (opts.cert) {
59
- flags.push(util.format('--cert=%s', opts.cert))
58
+ flags.push(format('--cert=%s', opts.cert));
60
59
  }
61
60
 
62
61
  if (opts.pretty) {
63
- flags.push(util.format('--pretty=%s', opts.pretty))
62
+ flags.push(format('--pretty=%s', opts.pretty));
64
63
  }
65
64
 
66
65
  if (opts.style) {
67
- flags.push(util.format('--style=%s', opts.pretty))
66
+ flags.push(format('--style=%s', opts.pretty));
68
67
  }
69
68
 
70
69
  if (opts.timeout) {
71
- flags.push(util.format('--timeout=%s', opts.timeout))
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).sort().forEach(function (key) {
93
- code.push('%s:%s', key, shell.quote(source.allHeaders[key]))
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('http %s%s %s', flags.length ? flags.join(' ') + ' ' : '', source.method, shell.quote(opts.queryParams ? source.url : source.fullUrl))
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
- 'use strict'
12
-
13
- const util = require('util')
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 = Object.assign({
16
+ const opts = {
19
17
  indent: ' ',
20
18
  short: false,
21
- verbose: false
22
- }, options)
19
+ verbose: false,
20
+ ...options,
21
+ };
23
22
 
24
- const code = new CodeBuilder(opts.indent, opts.indent !== false ? ' \\\n' + opts.indent : ' ')
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 = util.format('%s: %s', key, source.allHeaders[key])
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('--body-data ' + helpers.escape(helpers.quote(source.postData.text)))
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
- '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,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 (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 concatArray (arr, pretty, indentation, indentLevel) {
21
- const currentIndent = buildString(indentLevel, indentation)
22
- const closingBraceIndent = buildString(indentLevel - 1, indentation)
23
- const join = pretty ? ',\n' + currentIndent : ', '
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 '[\n' + currentIndent + arr.join(join) + '\n' + closingBraceIndent + ']'
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 util.format('let %s = %s', name, this.literalRepresentation(parameters, opts))
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
- indentLevel = indentLevel === undefined ? 1 : indentLevel + 1
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(function (v) {
63
- // Switch to prettify if the value is a dictionary with multiple keys
64
- if (Object.prototype.toString.call(v) === '[object Object]') {
65
- pretty = Object.keys(v).length > 1
66
- }
67
- return this.literalRepresentation(v, opts, indentLevel)
68
- }.bind(this))
69
- return concatArray(valuesRepresentation, pretty, opts.indent, indentLevel)
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(util.format('"%s": %s', k, this.literalRepresentation(value[k], opts, indentLevel)))
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 '"' + value.toString().replace(/"/g, '\\"') + '"'
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
+ };