Skip to content

Commit

Permalink
switch to native promises
Browse files Browse the repository at this point in the history
Signed-off-by: Chris West (Faux) <git@goeswhere.com>
  • Loading branch information
FauxFaux committed Nov 22, 2019
1 parent ae817cb commit 7cb2cb6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
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);
}
}));
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"coverage": "nyc report --reporter=text-lcov | coveralls"
},
"dependencies": {
"bluebird": "^2.9.34",
"traverse": "^0.6.6",
"xml2js": "^0.4.9"
},
Expand Down

0 comments on commit 7cb2cb6

Please sign in to comment.