<commit_before>'use strict';

var merge = require('lodash').merge,
	fs = require('fs'),
	freeze = require('./freeze'),
	load = require('./load'),
	resolve = require('./resolve');

module.exports = sync;
module.exports.sync = sync;
module.exports.async = async;
module.exports.freeze = freeze;

function async(paths, opts, callback) {
	var err;
	if (typeof opts === 'function' && !callback) {
		callback = opts;
		opts = {};
	}
	opts = defaultOptions(opts);
	err = validateParams(paths, opts, callback);
	if (err) {
		if (typeof callback === 'function') return callback(err);
		throw err;
	}

	load.async(paths, opts, function(err, config) {
		if (err) return callback(err);
		try {
			config = resolve(config, opts);
		} catch(e) {
			return callback(e);
		}
		config = opts.freeze ? freeze(config) : config;
		callback(null, config);
	});
}

function sync(paths, opts) {
	var err, config;
	opts = defaultOptions(opts);
	err = validateParams(paths, opts);
	if (err) throw err;
	config = load.sync(paths, opts);
	config = resolve(config, opts);
	config = opts.freeze ? freeze(config) : config;
	return config;
}

function validateParams(paths, opts, callback) {
	if (opts && typeof opts !== 'object') {
		return new Error('Expected parameter with options');
	}
	if (callback && typeof callback !== 'function') {
		return new Error('Expected callback parameter');
	}
	if (typeof paths !== 'string' && !Array.isArray(paths)) {
		return new Error('Expected a string (or array) with configuration file path');
	}
	if (opts.replaceLocal && opts.replaceLocal && opts.replaceLocal === opts.replaceEnv) {
		return new Error('Values opts.replaceLocal and opts.replaceEnv must be different');
	}
	if (opts.basedir && !fs.existsSync(opts.basedir)) {
		return new Error('Base directory not found: ' + opts.basedir);
	}
}

function defaultOptions(opts) {
	return merge({
		parentField: '__parent',
		basedir: null,
		replaceEnv: '%',
		replaceLocal: '@',
		skipUnresolved: false,
		freeze: false
	}, opts);
}<commit_msg>change default basedir.<commit_after>'use strict';

var merge = require('lodash').merge,
	fs = require('fs'),
	freeze = require('./freeze'),
	load = require('./load'),
	resolve = require('./resolve');

module.exports = sync;
module.exports.sync = sync;
module.exports.async = async;
module.exports.freeze = freeze;

function async(paths, opts, callback) {
	var err;
	if (typeof opts === 'function' && !callback) {
		callback = opts;
		opts = {};
	}
	opts = defaultOptions(opts);
	err = validateParams(paths, opts, callback);
	if (err) {
		if (typeof callback === 'function') return callback(err);
		throw err;
	}

	load.async(paths, opts, function(err, config) {
		if (err) return callback(err);
		try {
			config = resolve(config, opts);
		} catch(e) {
			return callback(e);
		}
		config = opts.freeze ? freeze(config) : config;
		callback(null, config);
	});
}

function sync(paths, opts) {
	var err, config;
	opts = defaultOptions(opts);
	err = validateParams(paths, opts);
	if (err) throw err;
	config = load.sync(paths, opts);
	config = resolve(config, opts);
	config = opts.freeze ? freeze(config) : config;
	return config;
}

function validateParams(paths, opts, callback) {
	if (opts && typeof opts !== 'object') {
		return new Error('Expected parameter with options');
	}
	if (callback && typeof callback !== 'function') {
		return new Error('Expected callback parameter');
	}
	if (typeof paths !== 'string' && !Array.isArray(paths)) {
		return new Error('Expected a string (or array) with configuration file path');
	}
	if (opts.replaceLocal && opts.replaceLocal && opts.replaceLocal === opts.replaceEnv) {
		return new Error('Values opts.replaceLocal and opts.replaceEnv must be different');
	}
	if (opts.basedir && !fs.existsSync(opts.basedir)) {
		return new Error('Base directory not found: ' + opts.basedir);
	}
}

function defaultOptions(opts) {
	return merge({
		parentField: '__parent',
		basedir: '.',
		replaceEnv: '%',
		replaceLocal: '@',
		skipUnresolved: false,
		freeze: false
	}, opts);
}
{'fraction_non_alphanumeric': 0.1591643869684158, 'fraction_numerical': 0.0, 'mean_word_length': 4.457259158751696, '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': '4509170', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1272, 'n_words': 359}