@@ -20,20 +20,20 @@ module.exports = function (source, options) {
2020 var includeFS = false
2121 var code = new CodeBuilder ( opts . indent )
2222
23- code . push ( 'var unirest = require("unirest");' )
23+ code . push ( 'const unirest = require("unirest");' )
2424 . blank ( )
25- . push ( 'var req = unirest("%s", "%s");' , source . method , source . url )
25+ . push ( 'const req = unirest("%s", "%s");' , source . method , source . url )
2626 . blank ( )
2727
2828 if ( source . cookies . length ) {
29- code . push ( 'var CookieJar = unirest.jar();' )
29+ code . push ( 'const CookieJar = unirest.jar();' )
3030
3131 source . cookies . forEach ( function ( cookie ) {
3232 code . push ( 'CookieJar.add("%s=%s","%s");' , encodeURIComponent ( cookie . name ) , encodeURIComponent ( cookie . value ) , source . url )
3333 } )
3434
3535 code . push ( 'req.jar(CookieJar);' )
36- . blank ( )
36+ . blank ( )
3737 }
3838
3939 if ( Object . keys ( source . queryObj ) . length ) {
@@ -50,13 +50,15 @@ module.exports = function (source, options) {
5050 case 'application/x-www-form-urlencoded' :
5151 if ( source . postData . paramsObj ) {
5252 code . push ( 'req.form(%s);' , JSON . stringify ( source . postData . paramsObj , null , opts . indent ) )
53+ . blank ( )
5354 }
5455 break
5556
5657 case 'application/json' :
5758 if ( source . postData . jsonObj ) {
5859 code . push ( 'req.type("json");' )
5960 . push ( 'req.send(%s);' , JSON . stringify ( source . postData . jsonObj , null , opts . indent ) )
61+ . blank ( )
6062 }
6163 break
6264
@@ -84,20 +86,21 @@ module.exports = function (source, options) {
8486 } )
8587
8688 code . push ( 'req.multipart(%s);' , JSON . stringify ( multipart , null , opts . indent ) )
89+ . blank ( )
8790 break
8891
8992 default :
9093 if ( source . postData . text ) {
91- code . push ( opts . indent + 'req.send(%s);' , JSON . stringify ( source . postData . text , null , opts . indent ) )
94+ code . push ( 'req.send(%s);' , JSON . stringify ( source . postData . text , null , opts . indent ) )
95+ . blank ( )
9296 }
9397 }
9498
9599 if ( includeFS ) {
96- code . unshift ( 'var fs = require("fs");' )
100+ code . unshift ( 'const fs = require("fs");' )
97101 }
98102
99- code . blank ( )
100- . push ( 'req.end(function (res) {' )
103+ code . push ( 'req.end(function (res) {' )
101104 . push ( 1 , 'if (res.error) throw new Error(res.error);' )
102105 . blank ( )
103106 . push ( 1 , 'console.log(res.body);' )
0 commit comments