Skip to content

Commit 63c6345

Browse files
committed
Refactor ES6 => ES5
1 parent 6ac6028 commit 63c6345

File tree

1 file changed

+40
-34
lines changed

1 file changed

+40
-34
lines changed

src/targets/clojure/clj_http.js

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,71 +12,77 @@
1212

1313
var CodeBuilder = require('../../helpers/code-builder')
1414

15-
class Keyword {
16-
constructor (name) {
17-
this.name = `:${name}`
18-
}
15+
var Keyword = function (name) {
16+
this.name = name
17+
}
1918

20-
toString () {
21-
return this.name
22-
}
19+
Keyword.prototype.toString = function () {
20+
return ':' + this.name
2321
}
2422

25-
class ClojureFile {
26-
constructor (path) {
27-
this.path = `(clojure.java.io/file "${path}")`
28-
}
23+
var File = function (path) {
24+
this.path = path
25+
}
2926

30-
toString () {
31-
return this.path
32-
}
27+
File.prototype.toString = function () {
28+
return '(clojure.java.io/file "' + this.path + '")'
3329
}
3430

35-
var jsType = x => (typeof x !== 'undefined')
36-
? x.constructor.name.toLowerCase()
37-
: null
31+
var jsType = function (x) {
32+
return (typeof x !== 'undefined')
33+
? x.constructor.name.toLowerCase()
34+
: null
35+
}
3836

39-
var objEmpty = x => (jsType(x) !== 'object')
40-
? false
41-
: Object.keys(x).length === 0
37+
var objEmpty = function (x) {
38+
return (jsType(x) === 'object')
39+
? Object.keys(x).length === 0
40+
: false
41+
}
4242

4343
var filterEmpty = function (m) {
4444
Object.keys(m)
45-
.filter(x => objEmpty(m[x]))
46-
.forEach(x => delete m[x])
45+
.filter(function (x) { return objEmpty(m[x]) })
46+
.forEach(function (x) { delete m[x] })
4747
return m
4848
}
4949

5050
var padBlock = function (x, s) {
51-
var padding = [...Array(x)].map(() => ' ').join('')
52-
return s.replace(/\n/g, `\n${padding}`)
51+
var padding = Array.apply(null, Array(x))
52+
.map(function (_) {
53+
return ' '
54+
})
55+
.join('')
56+
return s.replace(/\n/g, '\n' + padding)
5357
}
5458

5559
var jsToEdn = function (js) {
5660
switch (jsType(js)) {
5761
default: // 'number' 'boolean'
5862
return js.toString()
5963
case 'string':
60-
return `"${js.replace(/\"/g, '\\"')}"`
61-
case 'clojurefile':
64+
return '"' + js.replace(/\"/g, '\\"') + '"'
65+
case 'file':
6266
return js.toString()
6367
case 'keyword':
6468
return js.toString()
6569
case 'null':
6670
return 'nil'
6771
case 'regexp':
68-
return `#"${js.source}"`
72+
return '#"' + js.source + '"'
6973
case 'object': // simple vertical format
7074
var obj = Object.keys(js)
71-
.reduce((acc, key) => {
75+
.reduce(function (acc, key) {
7276
var val = padBlock(key.length + 2, jsToEdn(js[key]))
73-
return `${acc}:${key} ${val}\n `
77+
return acc + ':' + key + ' ' + val + '\n '
7478
}, '')
7579
.trim()
76-
return `{${padBlock(1, obj)}}`
80+
return '{' + padBlock(1, obj) + '}'
7781
case 'array': // simple horizontal format
78-
var arr = js.reduce((acc, val) => `${acc} ${jsToEdn(val)}`, '').trim()
79-
return `[${padBlock(1, arr)}]`
82+
var arr = js.reduce(function (acc, val) {
83+
return acc + ' ' + jsToEdn(val)
84+
}, '').trim()
85+
return '[' + padBlock(1, arr) + ']'
8086
}
8187
}
8288

@@ -106,10 +112,10 @@ module.exports = function (source, options) {
106112
delete params.headers['content-type']
107113
break
108114
case 'multipart/form-data':
109-
params.multipart = source.postData.params.map(x => {
115+
params.multipart = source.postData.params.map(function (x) {
110116
if (x.fileName && !x.value) {
111117
return {name: x.name,
112-
content: new ClojureFile(x.fileName)}
118+
content: new File(x.fileName)}
113119
} else {
114120
return {name: x.name,
115121
content: x.value}

0 commit comments

Comments
 (0)