<commit_before>/*
*
* A simple script to create (or print) a JSON file from an XML file
*
*/

var fs = require('fs');
var path = require('path');
var xml2js = require('xml2js');
var parser = new xml2js.Parser();

var output = './';

module.exports = (function () {

    this.publishJSON = function (file, outputDir) {
        parser.parseString(file, function (err, result) {
            if (err) throw err;
            var outputFilename = outputDir + file.split(".xml")[0] + '.json';
            fs.writeFile(outputFilename, JSON.stringify(result, null, 4), function (err) {
                if (err) throw err
                console.log("JSON saved to " + outputFilename);
            });
        });
    }

    this.convertToJSON = function (file, callBack) {
        fs.readFile(file, 'utf-8', function (err, xml) {
            if (err) console.log(err)
            try {
              parser.parseString(xml, function (err, result) {
                  if (err) callBack("Error!");
                  else callBack({"result": result, "file": file});
              });
            }
            catch (err) {
                callBack("Error!");
            }
        });
    }

    this.convertToJSONSync = function (file) {
        fs.readFile(file, 'utf-8', function (err, xml) {
            if (err) console.log(err)
            parser.parseString(xml, function (err, result) {
                if (err);
                else return {"result": result, "file": file};
            });
        });
    }

    return this;
})();<commit_msg>Remove try/catch<commit_after>/*
*
* A simple script to create (or print) a JSON file from an XML file
*
*/

var fs = require('fs');
var path = require('path');
var xml2js = require('xml2js');
var parser = new xml2js.Parser();

var output = './';

module.exports = (function () {

    this.publishJSON = function (file, outputDir) {
        parser.parseString(file, function (err, result) {
            if (err) throw err;
            var outputFilename = outputDir + file.split(".xml")[0] + '.json';
            fs.writeFile(outputFilename, JSON.stringify(result, null, 4), function (err) {
                if (err) throw err
                console.log("JSON saved to " + outputFilename);
            });
        });
    }

    this.convertToJSON = function (file, callBack) {
        fs.readFile(file, 'utf-8', function (err, xml) {
            if (err) console.log(err)
            parser.parseString(xml, function (err, result) {
              if (err) callBack("Error!");
              else callBack({"result": result, "file": file});
            });
        });
    }

    this.convertToJSONSync = function (file) {
        fs.readFile(file, 'utf-8', function (err, xml) {
            if (err) console.log(err)
            parser.parseString(xml, function (err, result) {
                if (err);
                else return {"result": result, "file": file};
            });
        });
    }

    return this;
})();
{'fraction_non_alphanumeric': 0.15008431703204048, 'fraction_numerical': 0.004721753794266442, 'mean_word_length': 1.8880233690360273, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '554801', 'n_tokens_mistral': 867, 'n_tokens_neox': 845, 'n_words': 229}