<commit_before>/**
 * 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 widgets = fs.readdirSync(__dirname + '/../lib/widgets');

var requires = widgets.reduce(function(out, name) {
  name = path.basename(name, '.js');
  out += '\nrequire(\'./widgets/' + name + '\');';
  return out;
}, '');

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

module.exports = function(file) {
  if (!~file.indexOf('widget.js')) {
    return transform();
  }
  return transform(true);
};<commit_msg>refactor browserify fix. 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 widgets = fs.readdirSync(__dirname + '/../lib/widgets');

var requires = widgets.reduce(function(out, name) {
  name = path.basename(name, '.js');
  out += '\nrequire(\'./widgets/' + name + '\');';
  return out;
}, '');

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

module.exports = function(file) {
  if (path.basename(file) === 'widget.js') {
    return transform(true);
  }
  return transform();
};
{'fraction_non_alphanumeric': 0.18054809242342826, 'fraction_numerical': 0.010209564750134336, 'mean_word_length': 3.552567237163814, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '4584506', 'n_tokens_mistral': 619, 'n_tokens_neox': 594, 'n_words': 141}