Skip to content

Commit c635889

Browse files
committed
Making the json2csv and csv2json functions promisifiable
1 parent e1ed4ec commit c635889

File tree

4 files changed

+649
-72
lines changed

4 files changed

+649
-72
lines changed

lib/converter.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ module.exports = {
4040
// a callback that will be called with (err, csv) after
4141
// processing is completed, and optional options
4242
json2csv: function (array, callback, opts) {
43+
// If this was promisified (callback and opts are swapped) then fix the argument order.
44+
if (_.isObject(callback) && !_.isFunction(callback)) {
45+
var func = opts;
46+
opts = callback;
47+
callback = func;
48+
}
4349
buildOptions(opts, function (err, options) { // Build the options
4450
if (err) {
4551
return callback(err);
@@ -55,6 +61,12 @@ module.exports = {
5561
// a callback that will be called with (err, csv) after
5662
// processing is completed, and optional options
5763
csv2json: function (csv, callback, opts) {
64+
// If this was promisified (callback and opts are swapped) then fix the argument order.
65+
if (_.isObject(callback) && !_.isFunction(callback)) {
66+
var func = opts;
67+
opts = callback;
68+
callback = func;
69+
}
5870
buildOptions(opts, function (err, options) { // Build the options
5971
if (err) {
6072
return callback(err);

package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
"author": "mrodrig",
33
"name": "json-2-csv",
44
"description": "A JSON to CSV and CSV to JSON converter that natively supports sub-documents and auto-generates the CSV heading.",
5+
<<<<<<< HEAD
56
"version": "1.1.0",
7+
=======
8+
"version": "1.0.9",
9+
>>>>>>> Making the json2csv and csv2json functions promisifiable
610
"repository": {
711
"type": "git",
812
"url": "http://github.com/mrodrig/json-2-csv.git"
@@ -27,12 +31,13 @@
2731
"bluebird": "~2.9.24"
2832
},
2933
"devDependencies": {
30-
"mocha": "~1.14.0",
31-
"should": "~2.0.2",
32-
"async": "~0.2.9"
34+
"mocha": "~2.2.4",
35+
"should": "~5.2.0",
36+
"async": "~0.2.10",
37+
"bluebird": "~2.9.24"
3338
},
3439
"engines": {
3540
"node": "*"
3641
},
3742
"license": "MIT"
38-
}
43+
}

0 commit comments

Comments
 (0)