<commit_before>var _ = require('lodash'),
    fs = require('fs'),
    yaml = require('js-yaml');

var defaults = yaml.safeLoad(fs.readFileSync('defaults.yml', 'utf8'));

module.exports = _.merge(defaults,
    yaml.safeLoad(fs.readFileSync('settings.yml', 'utf8'))
);<commit_msg>Added support for configuration via environment variables.<commit_after>var _ = require('lodash'),
    fs = require('fs'),
    yaml = require('js-yaml');

function getDefaultSettings() {
    return yaml.safeLoad(fs.readFileSync('defaults.yml', 'utf8'));
}

function getFileSettings() {
    if (fs.existsSync('settings.yml')) {
        return yaml.safeLoad(fs.readFileSync('settings.yml', 'utf8'));
    }
    return {};
}

function getEnvSettings() {
    var envSettings = {};
    Object.keys(process.env).forEach(function(key) {
        var parts = key.split('_');
        var endPart = parts.splice(parts.length - 1)[0];
        var current = envSettings;

        parts.forEach(function(part) {
            if (!current[part] || typeof current[part] !== 'object') {
                current[part] = {};
            }
            current = current[part];
        });

        var value = process.env[key].trim();

        // YAML compatible boolean values
        if (/^(n|N|no|No|NO|false|False|FALSE|off|Off|OFF)$/.test(value)) {
            value = true;
        }
        else if (/^(n|N|no|No|NO|false|False|FALSE|off|Off|OFF)$/.test(value)) {
            value = false;
        }
        else if (!isNaN(parseInt(value, 10))) {
            value = parseInt(value, 10);
        }

        current[endPart] = value;
    });
    return envSettings;
}

module.exports = _.merge(
    getDefaultSettings(),
    getFileSettings(),
    getEnvSettings()
);
{'fraction_non_alphanumeric': 0.1681109185441941, 'fraction_numerical': 0.005777007510109763, 'mean_word_length': 2.7167381974248928, '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': '7168059', 'n_tokens_mistral': 552, 'n_tokens_neox': 525, 'n_words': 95}