<commit_before>/**
 * Object representing a XRoad message from which request and response objects
 * inherit from.
 *
 * @module xroad4js/xrmsg
 */

'use strict';

var xml2js = require('xml2js'),
  Builder = xml2js.Builder,
  builder = new Builder(),
  parseString = xml2js.parseString;

/**
 * Creates a new XRMsg
 */
function XRMsg (msg) {
  var xrmsg;

  if (typeof msg !== 'undefined' && msg !== null) {
    xrmsg = msg;
  } else {
    xrmsg = {};
    xrmsg.envelope = {
      header: {
        client: {},
        service: {}
      },
      body: {}
    };
  }

  /**
   * Transfrom data from JS to XRoad SOAP
   *
   * TODO: Validate self
   *
   * @param {Object} obj
   * @param {Function} cb
   * @return {String}
   */
  xrmsg.toXR = function (obj, cb) {
    var xml, callback;

    if ((obj !== null || typeof obj !== 'undefined') && 
        typeof cb === 'function') {
      xml = builder.buildObject(obj);
      callback = cb;
    } else if (obj !== null || typeof obj !== 'undefined') {
      xml = builder.buildObject(xrmsg.envelope);
      callback = obj;
    } else {
      throw new Error('Invalid arguments to toXR function'); 
    }


    return callback(null, xml);
  };

  /**
   * Parse XRoad SOAP to JS
   *
   * Provides defaults if options argument is not specified.
   *
   * @param {String} xml
   * @param {Object} a
   * @param {Function} b
   * @return {Object}
   */
  xrmsg.fromXR = function (xml, a, b) {
    var options, callback;

    if (xml !== null || xml !== undefined) {
      if (typeof a === 'function' && (b === null || b === undefined)) {
        callback = a;

        /** Default options for parseString */
        options = {
          explicitArray: false
        };

      } else if (typeof a === 'object' && typeof b === 'function') {
        callback = b;
        options = a;
      } else {
        throw new Error('Invalid arguments for fromXR function.');
      }
    } else {
      throw new Error('No XML argument for parsing.');
    }

    return parseString(xml, options, callback);
  };

  return xrmsg;
}

module.exports = XRMsg;<commit_msg>Remove functions from the object.<commit_after>/**
 * Object representing a XRoad message from which request and response objects
 * inherit from.
 *
 * @module xroad4js/xrmsg
 */

'use strict';

/**
 * Creates a new XRMsg
 */
function XRMsg (msg) {
  var xrmsg;

  if (typeof msg !== 'undefined' && msg !== null) {
    xrmsg = msg;
  } else {
    xrmsg = {};
    xrmsg.envelope = {
      header: {
        client: {},
        service: {}
      },
      body: {}
    };
  }


  return xrmsg;
}

module.exports = XRMsg;
{'fraction_non_alphanumeric': 0.14612743227775657, 'fraction_numerical': 0.002289202594429607, 'mean_word_length': 2.18978102189781, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 13}, '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': '5163247', 'n_tokens_mistral': 854, 'n_tokens_neox': 835, 'n_words': 251}