Skip to content

Commit a31eee0

Browse files
committed
Finished setting up new test structure
1 parent a5701ca commit a31eee0

29 files changed

+1052
-2806
lines changed

lib/constants.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,16 @@
1717
"noDataRetrieveHeading": "No data provided to retrieve heading."
1818
}
1919

20+
},
21+
22+
"DefaultOptions" : {
23+
"DELIMITER" : {
24+
"FIELD" : ",",
25+
"ARRAY" : ";",
26+
"WRAP" : ""
27+
},
28+
"EOL" : "\n",
29+
"PARSE_CSV_NUMBERS" : false,
30+
"KEYS" : null
2031
}
2132
}

lib/converter.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,7 @@ var json2Csv = require('./json-2-csv'), // Require our json-2-csv code
88
/**
99
* Default options
1010
*/
11-
var defaultOptions = {
12-
DELIMITER : {
13-
FIELD : ',',
14-
ARRAY : ';',
15-
WRAP : ''
16-
},
17-
EOL : '\n',
18-
PARSE_CSV_NUMBERS : false,
19-
KEYS : null
20-
};
11+
var defaultOptions = constants.DefaultOptions;
2112

2213
/**
2314
* Build the options to be passed to the appropriate function
@@ -31,7 +22,7 @@ var buildOptions = function (opts, cb) {
3122
// If the delimiter fields are the same, report an error to the caller
3223
if (opts.DELIMITER.FIELD === opts.DELIMITER.ARRAY) { return cb(new Error(constants.Errors.delimitersMustDiffer)); }
3324
// Otherwise, send the options back
34-
else { return cb(null, opts); }
25+
return cb(null, opts);
3526
};
3627

3728
// Export the following functions that will be client accessible

lib/csv-2-json.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ module.exports = {
9999
// Takes options as a document, data as a CSV string, and a callback that will be used to report the results
100100
csv2json: function (opts, data, callback) {
101101
if (!callback) { throw new Error(constants.Errors.callbackRequired); } // If a callback wasn't provided, throw an error
102-
if (!opts) { callback(new Error(constants.Errors.optionsRequired)); return null; } // Shouldn't happen, but just in case
102+
if (!opts) { return callback(new Error(constants.Errors.optionsRequired)); return null; } // Shouldn't happen, but just in case
103103
else { options = opts; } // Options were passed, set the global options value
104-
if (!data) { callback(new Error(constants.Errors.csv2json.cannotCallCsv2JsonOn + data + '.')); return null; } // If we don't receive data, report an error
104+
if (!data) { return callback(new Error(constants.Errors.csv2json.cannotCallCsv2JsonOn + data + '.')); return null; } // If we don't receive data, report an error
105105
if (!_.isString(data)) { // The data is not a string
106-
callback(new Error(constants.Errors.csv2json.csvNotString)); // Report an error back to the caller
106+
return callback(new Error(constants.Errors.csv2json.csvNotString)); // Report an error back to the caller
107107
}
108108
var lines = data.split(options.EOL); // Split the CSV into lines using the specified EOL option
109109
var json = convertCSV(lines, callback); // Retrieve the JSON document array

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
},
1010
"main": "./lib/converter.js",
1111
"scripts": {
12-
"test": "./node_modules/.bin/mocha --reporter spec"
12+
"test": "./node_modules/.bin/mocha test/tests.js",
13+
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- -R spec"
1314
},
1415
"keywords": [
1516
"json",
@@ -28,6 +29,7 @@
2829
},
2930
"devDependencies": {
3031
"mocha": "~2.2.4",
32+
"istanbul": "~0.3.13",
3133
"should": "~5.2.0",
3234
"async": "~0.9.0"
3335
},
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)