Skip to content

Commit b038972

Browse files
committed
Merge pull request #17 from mrodrig/make-promisifiable
Make json-2-csv promisifiable
2 parents e1ed4ec + 91006bc commit b038972

File tree

8 files changed

+1048
-132
lines changed

8 files changed

+1048
-132
lines changed

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
test/
22
.git*
3+
npm-debug.log
34
.travis.yml
5+
node_modules/
6+
node_modules/*

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ _Note_: This requires `mocha`, `should`, `async`, and `underscore`.
143143
- Custom ordering of columns (see F.A.Q. for more information)
144144
- Ability to re-generate the JSON documents that were used to generate the CSV (including nested documents)
145145
- Allows for custom field delimiters, end of line delimiters, etc.
146+
- Promisifiable via bluebird's .promisify(<function) and .promisifyAll() (as of 1.1.1)
146147

147148
## F.A.Q.
148149

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-2-csv",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"homepage": "https://github.com/mrodrig/json-2-csv",
55
"moduleType": [
66
"node"

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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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-
"version": "1.1.0",
5+
"version": "1.1.1",
66
"repository": {
77
"type": "git",
88
"url": "http://github.com/mrodrig/json-2-csv.git"
@@ -27,9 +27,9 @@
2727
"bluebird": "~2.9.24"
2828
},
2929
"devDependencies": {
30-
"mocha": "~1.14.0",
31-
"should": "~2.0.2",
32-
"async": "~0.2.9"
30+
"mocha": "~2.2.4",
31+
"should": "~5.2.0",
32+
"async": "~0.2.10"
3333
},
3434
"engines": {
3535
"node": "*"

0 commit comments

Comments
 (0)