|
12 | 12 |
|
13 | 13 | var CodeBuilder = require('../../helpers/code-builder') |
14 | 14 |
|
15 | | -class Keyword { |
16 | | - constructor (name) { |
17 | | - this.name = `:${name}` |
18 | | - } |
| 15 | +var Keyword = function (name) { |
| 16 | + this.name = name |
| 17 | +} |
19 | 18 |
|
20 | | - toString () { |
21 | | - return this.name |
22 | | - } |
| 19 | +Keyword.prototype.toString = function () { |
| 20 | + return ':' + this.name |
23 | 21 | } |
24 | 22 |
|
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 | +} |
29 | 26 |
|
30 | | - toString () { |
31 | | - return this.path |
32 | | - } |
| 27 | +File.prototype.toString = function () { |
| 28 | + return '(clojure.java.io/file "' + this.path + '")' |
33 | 29 | } |
34 | 30 |
|
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 | +} |
38 | 36 |
|
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 | +} |
42 | 42 |
|
43 | 43 | var filterEmpty = function (m) { |
44 | 44 | 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] }) |
47 | 47 | return m |
48 | 48 | } |
49 | 49 |
|
50 | 50 | 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) |
53 | 57 | } |
54 | 58 |
|
55 | 59 | var jsToEdn = function (js) { |
56 | 60 | switch (jsType(js)) { |
57 | 61 | default: // 'number' 'boolean' |
58 | 62 | return js.toString() |
59 | 63 | case 'string': |
60 | | - return `"${js.replace(/\"/g, '\\"')}"` |
61 | | - case 'clojurefile': |
| 64 | + return '"' + js.replace(/\"/g, '\\"') + '"' |
| 65 | + case 'file': |
62 | 66 | return js.toString() |
63 | 67 | case 'keyword': |
64 | 68 | return js.toString() |
65 | 69 | case 'null': |
66 | 70 | return 'nil' |
67 | 71 | case 'regexp': |
68 | | - return `#"${js.source}"` |
| 72 | + return '#"' + js.source + '"' |
69 | 73 | case 'object': // simple vertical format |
70 | 74 | var obj = Object.keys(js) |
71 | | - .reduce((acc, key) => { |
| 75 | + .reduce(function (acc, key) { |
72 | 76 | var val = padBlock(key.length + 2, jsToEdn(js[key])) |
73 | | - return `${acc}:${key} ${val}\n ` |
| 77 | + return acc + ':' + key + ' ' + val + '\n ' |
74 | 78 | }, '') |
75 | 79 | .trim() |
76 | | - return `{${padBlock(1, obj)}}` |
| 80 | + return '{' + padBlock(1, obj) + '}' |
77 | 81 | 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) + ']' |
80 | 86 | } |
81 | 87 | } |
82 | 88 |
|
@@ -106,10 +112,10 @@ module.exports = function (source, options) { |
106 | 112 | delete params.headers['content-type'] |
107 | 113 | break |
108 | 114 | case 'multipart/form-data': |
109 | | - params.multipart = source.postData.params.map(x => { |
| 115 | + params.multipart = source.postData.params.map(function (x) { |
110 | 116 | if (x.fileName && !x.value) { |
111 | 117 | return {name: x.name, |
112 | | - content: new ClojureFile(x.fileName)} |
| 118 | + content: new File(x.fileName)} |
113 | 119 | } else { |
114 | 120 | return {name: x.name, |
115 | 121 | content: x.value} |
|
0 commit comments