<commit_before>var xml2js = require('xml2js');
var path = require('path');
var fs = require('fs');
var os =require('os');
var log =require('./log');

var EOL = os.platform === 'win32' ? '\r\n' : '\n';

/**
 * Transfer the input xml to output js for nproxy
 *
 * @param {String} sfXML file path of sf combo configuration xml file
 * @param {String} output transfered output file
 */
function transfer(sfXML,output){
  var xmlParser; 
  var groups;
  var responders = [];
  var fileList = [];
  var entry;
  var responder;
  var stat;

  if(typeof sfXML === 'undefined'){
    throw new Error('No input file specified');
  }

  if(!/\.xml$/.test(sfXML)){
    throw new Error('Input file must be a xml file!');
  }

  sfXML = sfXML.indexOf(path.sep) === 0 ? sfXML : path.join(process.pwd, sfXML);

  if(typeof output === 'undefined'){
    output = sfXML.replace('.xml', '.js');
  }else{
    output = output.indexOf(path.sep) === 0 ? output : path.join(process.cwd, output);
    try{
      stat = fs.statSync(output);
    }catch(e){
      throw e;
    }

    if(!stat.isDirectory()){
      throw new Error('Output is not a directory');
    }

    output = path.join(output, path.basename(sfXML, '.xml') + '.js');
  }

  xmlParser = new xml2js.Parser();

  fs.readFile(sfXML, function(err, xml){
    if(err){ throw err; }

    xmlParser.parseString(xml, function(err, result){
      groups = result.groups.group;

      groups.forEach(function(group){
        if(typeof group['@'] === 'undefined'){
          return;
        }

        groupId = group['@']['id'];

        if(typeof groupId !== 'undefined'){
          resources = group['resource'];
          entry = {
            comment: '// pattern for ' + groupId,
            pattern: /group-pattern/,
            responder: {
              dir: 'fill the dir',
              src: []
            }
          };

          responder = entry.responder;

          if(typeof resources === 'object' && 
              typeof resources['@'] === 'object' && 
              typeof resources['@']['uri'] === 'string'){

            responder.src.push(resources['@']['uri']);

          }

          if(Array.isArray(resources)){
            resources.forEach(function(resource){
              if(typeof resource['@'] === 'object' && 
                  typeof resource['@']['uri'] === 'string'){
                responder.src.push(resource['@']['uri']);
              }<commit_msg>change literal regular express to string<commit_after>var xml2js = require('xml2js');
var path = require('path');
var fs = require('fs');
var os =require('os');
var log =require('./log');

var EOL = os.platform === 'win32' ? '\r\n' : '\n';

/**
 * Transfer the input xml to output js for nproxy
 *
 * @param {String} sfXML file path of sf combo configuration xml file
 * @param {String} output transfered output file
 */
function transfer(sfXML,output){
  var xmlParser; 
  var groups;
  var responders = [];
  var fileList = [];
  var entry;
  var responder;
  var stat;

  if(typeof sfXML === 'undefined'){
    throw new Error('No input file specified');
  }

  if(!/\.xml$/.test(sfXML)){
    throw new Error('Input file must be a xml file!');
  }

  sfXML = sfXML.indexOf(path.sep) === 0 ? sfXML : path.join(process.pwd, sfXML);

  if(typeof output === 'undefined'){
    output = sfXML.replace('.xml', '.js');
  }else{
    output = output.indexOf(path.sep) === 0 ? output : path.join(process.cwd, output);
    try{
      stat = fs.statSync(output);
    }catch(e){
      throw e;
    }

    if(!stat.isDirectory()){
      throw new Error('Output is not a directory');
    }

    output = path.join(output, path.basename(sfXML, '.xml') + '.js');
  }

  xmlParser = new xml2js.Parser();

  fs.readFile(sfXML, function(err, xml){
    if(err){ throw err; }

    xmlParser.parseString(xml, function(err, result){
      groups = result.groups.group;

      groups.forEach(function(group){
        if(typeof group['@'] === 'undefined'){
          return;
        }

        groupId = group['@']['id'];

        if(typeof groupId !== 'undefined'){
          resources = group['resource'];
          entry = {
            comment: '// pattern for ' + groupId,
            pattern: 'url pattern',
            responder: {
              dir: 'fill the dir',
              src: []
            }
          };

          responder = entry.responder;

          if(typeof resources === 'object' && 
              typeof resources['@'] === 'object' && 
              typeof resources['@']['uri'] === 'string'){

            responder.src.push(resources['@']['uri']);

          }

          if(Array.isArray(resources)){
            resources.forEach(function(resource){
              if(typeof resource['@'] === 'object' && 
                  typeof resource['@']['uri'] === 'string'){
                responder.src.push(resource['@']['uri']);
              }
{'fraction_non_alphanumeric': 0.17320731456749539, 'fraction_numerical': 0.0028765153071707416, 'mean_word_length': 2.31156462585034, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 28}, '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': '2784867', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1429, 'n_words': 366}