<commit_before>var Transform = require('stream').Transform;

function transform(target) {
  var data = '';
  var tr = new Transform;
  tr._transform = function(chunk, encoding, callback) {
    if (!target) {
      return callback(null, chunk);
    }
    data += chunk;
    return callback(null, chunk);
  };
  tr._flush = function(callback) {
    if (!target) {
      return callback();
    }
    tr.push(compile(data));
    return callback();
  };
  return tr;
}

function compile(data) {
  var out = '';
  var names = /widget\.classes = (\[[^\]]+\]);/.exec(data)[1];
  names = JSON.parse(names.replace(/'/g, '"')).forEach(function(name) {
    name = name.toLowerCase();
    out += '\nrequire(\'./widgets/' + name + '\');';
  });
  return out;
}

module.exports = function(file) {
  if (!~file.indexOf('widget.js')) {
    return transform();
  }
  return transform(true);
};<commit_msg>less insane browserify workaround. see #158.<commit_after>/**
 * transform.js - browserify workaround for blessed
 * Copyright (c) 2013-2015, <NAME> and contributors (MIT License).
 * https://github.com/chjj/blessed
 */

var Transform = require('stream').Transform
  , path = require('path')
  , fs = require('fs');

var requireList = (function() {
  var out = '';
  fs.readdirSync(__dirname + '/../lib/widgets').forEach(function(name) {
    name = path.basename(name, '.js');
    out += '\nrequire(\'./widgets/' + name + '\');';
  });
  return out;
})();

function transform(target) {
  var data = '';
  var tr = new Transform;
  tr._transform = function(chunk, encoding, callback) {
    if (!target) {
      return callback(null, chunk);
    }
    data += chunk;
    return callback(null, chunk);
  };
  tr._flush = function(callback) {
    if (!target) {
      return callback();
    }
    // tr.push(compile(data));
    tr.push(requireList);
    return callback();
  };
  return tr;
}

function compile(data) {
  var out = '';
  var names = /widget\.classes = (\[[^\]]+\]);/.exec(data)[1];
  names = JSON.parse(names.replace(/'/g, '"')).forEach(function(name) {
    name = name.toLowerCase();
    out += '\nrequire(\'./widgets/' + name + '\');';
  });
  return out;
}

module.exports = function(file) {
  if (!~file.indexOf('widget.js')) {
    return transform();
  }
  return transform(true);
};
{'fraction_non_alphanumeric': 0.20157411456055968, 'fraction_numerical': 0.005684302579798863, 'mean_word_length': 3.1524500907441015, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 1, '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': '7179542', 'n_tokens_mistral': 751, 'n_tokens_neox': 737, 'n_words': 164}