<commit_before>var async = require('async');
var escape = require('escape-string-regexp');
var filesystem = require('fs');
var logger = require('loggy');
var lodash = require('lodash');


/**
 * @class ReplaceCompiler
 * @param {Object} [config]
 * @constructor
 */
function ReplaceCompiler(config) {
    this.config = lodash.cloneDeep(config || {});
    this.config = lodash.defaultsDeep(
        this.config,
        {
            plugins: {
                replace: {}
            }
        }
    );
}

/**
 * @property brunchPlugin
 * @type {Boolean}
 */
ReplaceCompiler.prototype.brunchPlugin = true;

/**
 * @method getConfig
 * @returns {Object}
 */
ReplaceCompiler.prototype.getConfig = function() {
    return lodash.defaultsDeep(
        this.config.plugins.replace,
        {
            encoding: 'utf8',
            log: true,
            mappings: {
                date: (new Date()).toISOString(),
                timestamp:  Math.floor(Date.now() / 1000)
            },
            paths: [],
            replacePrefix: '{!',
            replaceSuffix: '!}'
        }
    );
};

/**
 * @method getPaths
 * @param {Array} files
 * @param {Object} config
 * @returns {Array}
 */
ReplaceCompiler.prototype.getPaths = function(files, config) {
    return lodash
        .chain(files)
        .map(function(file) {
            return file.destinationPath || file.path;
        })
        .filter(function(path) {
            return !config.paths.length || config.paths.indexOf(path) > -1;
        })
        .value();
};

/**
 * @method replaceFile
 * @param {String} path
 * @param {Object} config
 * @param {Function} [callback]
 */
ReplaceCompiler.prototype.replaceFile = function(path, config, callback) {
    filesystem.readFile(
        path,
        config.encoding,
        function(error, data) {
            if (error) {
                if (typeof callback === 'function') {
                    callback(error, path);
                }<commit_msg>Replace back slashes with forward slashes for paths on windows.<commit_after>var async = require('async');
var escape = require('escape-string-regexp');
var filesystem = require('fs');
var logger = require('loggy');
var lodash = require('lodash');


/**
 * @class ReplaceCompiler
 * @param {Object} [config]
 * @constructor
 */
function ReplaceCompiler(config) {
    this.config = lodash.cloneDeep(config || {});
    this.config = lodash.defaultsDeep(
        this.config,
        {
            plugins: {
                replace: {}
            }
        }
    );
}

/**
 * @property brunchPlugin
 * @type {Boolean}
 */
ReplaceCompiler.prototype.brunchPlugin = true;

/**
 * @method getConfig
 * @returns {Object}
 */
ReplaceCompiler.prototype.getConfig = function() {
    return lodash.defaultsDeep(
        this.config.plugins.replace,
        {
            encoding: 'utf8',
            log: true,
            mappings: {
                date: (new Date()).toISOString(),
                timestamp:  Math.floor(Date.now() / 1000)
            },
            paths: [],
            replacePrefix: '{!',
            replaceSuffix: '!}'
        }
    );
};

/**
 * @method getPaths
 * @param {Array} files
 * @param {Object} config
 * @returns {Array}
 */
ReplaceCompiler.prototype.getPaths = function(files, config) {
    return lodash
        .chain(files)
        .map(function(file) {
            return (file.destinationPath || file.path).replace(/\\/g, '/');
        })
        .filter(function(path) {
            return !config.paths.length || config.paths.indexOf(path) > -1;
        })
        .value();
};

/**
 * @method replaceFile
 * @param {String} path
 * @param {Object} config
 * @param {Function} [callback]
 */
ReplaceCompiler.prototype.replaceFile = function(path, config, callback) {
    filesystem.readFile(
        path,
        config.encoding,
        function(error, data) {
            if (error) {
                if (typeof callback === 'function') {
                    callback(error, path);
                }
{'fraction_non_alphanumeric': 0.14613466334164588, 'fraction_numerical': 0.0029925187032418953, 'mean_word_length': 2.047872340425532, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5570848', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1119, 'n_words': 235}