Skip to content

Commit

Permalink
Merge 7cb2cb6 into d59c365
Browse files Browse the repository at this point in the history
  • Loading branch information
FauxFaux committed Nov 22, 2019
2 parents d59c365 + 7cb2cb6 commit b71cb69
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ build/Release
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules
npm-shrinkwrap.json
.nyc_output/
.idea/
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
sudo: false
dist: bionic
language: node_js
node_js:
- '0.12'
- '0.11'
- '0.10'
- iojs
- '6'
- '8'
- '10'
- '12'
after_success: npm run coverage
deploy:
provider: npm
email: marcello.desales@gmail.com
Expand Down
22 changes: 14 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

"use strict";

var Promise = require("bluebird");
var fs = Promise.promisifyAll(require("fs"));
const fs = require("fs");
var xml2js = require("xml2js");
var traverse = require('traverse');

Expand Down Expand Up @@ -33,26 +32,23 @@ module.exports.parse = function(opt, callback) {
// If the xml content is was not provided by the api client.
// https://github.com/petkaantonov/bluebird/blob/master/API.md#error-rejectedhandler----promise
if (!opt.xmlContent) {
fs.readFileAsync(opt.filePath, "utf8").then(function(xmlContent) {
readFileAsync(opt.filePath, "utf8").then(function(xmlContent) {
return xmlContent;

}).then(_parseWithXml2js).then(function(result) {
callback(null, result);

}).catch(function(e) {
callback(e, null);

}).error(function (e) {
callback(e, null);
});

} else {
// parse the xml provided by the api client.
_parseWithXml2js(opt.xmlContent).then(function(result) {
delete result.xmlContent;
delete result.xmlContent;
callback(null, result);

}).error(function (e) {
}).catch(function (e) {
callback(e);
});
}
Expand Down Expand Up @@ -99,3 +95,13 @@ function removeSingleArrays(obj) {
}
});
}

function readFileAsync(path, encoding) {
return new Promise((resolve, reject) => fs.readFile(path, {encoding}, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
}));
}
15 changes: 6 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,18 @@
"url": "https://about.me/marcellodesales"
},
"scripts": {
"test": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/.bin/codacy-coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
"test": "nyc mocha",
"coverage": "nyc report --reporter=text-lcov | coveralls"
},
"dependencies": {
"bluebird": "^2.9.34",
"traverse": "^0.6.6",
"xml2js": "^0.4.9"
},
"devDependencies": {
"chai": "^3.0.0",
"codacy-coverage": "^1.1.2",
"coveralls": "^2.11.3",
"istanbul": "^0.3.17",
"mocha": "^2.2.5",
"mocha-lcov-reporter": "0.0.2",
"sinon": "^1.15.4"
"chai": "^4.2.0",
"coveralls": "^3.0.8",
"mocha": "^6.2.2",
"nyc": "^14.1.1"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit b71cb69

Please sign in to comment.