<commit_before>'use strict';

var fs = require('fs');
var path = require('path');
var glob = require('glob');

/**
 * Deprecated, use glob instead
 * @param dir
 * @param done
 */
var walk = function(dir, done) {
  var results = [];
  fs.readdir(dir, function(err, list) {
    if (err) return done(err);
    var pending = list.length;
    if (!pending) return done(null, results);
    list.forEach(function(file) {
      file = path.resolve(dir, file);
      fs.stat(file, function(err, stat) {
        if (stat && stat.isDirectory()) {
          walk(file, function(err, res) {
            results = results.concat(res);
            if (!--pending) done(null, results);
          });
        } else {
          results.push(file);
          if (!--pending) done(null, results);
        }
      });
    });
  });
};

/**
 * Deprecated, use glob instead
 * @param path
 * @param searchString
 * @returns {*}
 */
function getViewsPath(path, searchString){
  var result;

  walk(path, function(err, results){
    result = results.filter(function(path){
      if(path.match(searchString)) return path;
    })
    .map(function(path){
      return path.substring(0, path.indexOf(searchString) + 7);
    })
    .filter(function(item, i ,ar){
      return ar.indexOf(item) === i;
    });
  });

  while(result === undefined){
    require('deasync').runLoopOnce();
  }

  return result;
}

/**
 * Deprecated, use bulk-require instead
 */
function initRoutes(router){
  var routes = getFilesInPathSync('modules/**/routes');
  routes.forEach(function(route){
    require('../' + route + '/index.js')(router);
  });

  return router;
}

function getFilesInPathSync(pattern){
  var result;

  getFilesInPath(pattern, function(files){
    result = files;
  });

  while(result === undefined){
    require('deasync').runLoopOnce();
  }

  return result;
}<commit_msg>Comment updated<commit_after>'use strict';

var fs = require('fs');
var path = require('path');
var glob = require('glob');

/**
 * Deprecated, use glob instead
 * @param dir
 * @param done
 */
var walk = function(dir, done) {
  var results = [];
  fs.readdir(dir, function(err, list) {
    if (err) return done(err);
    var pending = list.length;
    if (!pending) return done(null, results);
    list.forEach(function(file) {
      file = path.resolve(dir, file);
      fs.stat(file, function(err, stat) {
        if (stat && stat.isDirectory()) {
          walk(file, function(err, res) {
            results = results.concat(res);
            if (!--pending) done(null, results);
          });
        } else {
          results.push(file);
          if (!--pending) done(null, results);
        }
      });
    });
  });
};

/**
 * Deprecated, use glob instead
 * @param path
 * @param searchString
 * @returns {*}
 */
function getViewsPath(path, searchString){
  var result;

  walk(path, function(err, results){
    result = results.filter(function(path){
      if(path.match(searchString)) return path;
    })
    .map(function(path){
      return path.substring(0, path.indexOf(searchString) + 7);
    })
    .filter(function(item, i ,ar){
      return ar.indexOf(item) === i;
    });
  });

  while(result === undefined){
    require('deasync').runLoopOnce();
  }

  return result;
}

/**
 * Used to require all routes within index.js files of every 'route' that is
 * contained in each module folder
 */
function initRoutes(router){
  var routes = getFilesInPathSync('modules/**/routes');
  routes.forEach(function(route){
    require('../' + route + '/index.js')(router);
  });

  return router;
}

function getFilesInPathSync(pattern){
  var result;

  getFilesInPath(pattern, function(files){
    result = files;
  });

  while(result === undefined){
    require('deasync').runLoopOnce();
  }

  return result;
}
{'fraction_non_alphanumeric': 0.16666666666666666, 'fraction_numerical': 0.0010582010582010583, 'mean_word_length': 2.9467640918580376, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3653148', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1170, 'n_words': 277}