<commit_before>var fs = require('fs')
	, D = require('d.js')
	, methods = (
		'rename,ftruncate,truncate,chown,fchown,lchown,chmod,fchmod,lchmod,stat,lstat,fstat,link,symlink,readlink,realpath'
		+ ',unlink,rmdir,mkdir,readdir,close,open,utimes,futimes,fsync,write,read,readFile,writeFile,appendFile'
	).split(',')
;
methods.forEach(function(m){
	fs[m + 'Promise'] = D.nodeCapsule(fs, fs[m]);
});

fs.readJsonSync = function readJsonSync(filename, options, callback){
	return fs.readFileSync(filename, options, function(err, data){
		if( !err ){
			try{
				data = JSON.parse(data);
			}catch(e){
				return callback(e);
			}
			callback(err,data);
		}
		callback(err, data);
	});
};
fs.readJsonPromise = function readJsonPromise(filename, options){
	return fs.readFilePromise(filename, options).success(JSON.parse);
};
fs.writeJsonSync = function writeJsonSync(filename, data, options, callback){
	try{
		data = JSON.stringify(data);
	}catch(e){
		callback(e);
		return;
	}
	return fs.writeFileSync(filename, data, options, callback);
};
fs.writeJsonPromise = function writeJsonPromise(filename, data, options){
	return fs.writeFilePromise(filename, JSON.stringify(data), options);
};

module.exports = fs;
<commit_msg>better red/writeJSONSync<commit_after>/*jshint laxbreak:true*/
"use strict";
var fs = require('fs')
	, D = require('d.js')
	, methods = (
		'rename,ftruncate,truncate,chown,fchown,lchown,chmod,fchmod,lchmod,stat,lstat,fstat,link,symlink,readlink,realpath'
		+ ',unlink,rmdir,mkdir,readdir,close,open,utimes,futimes,fsync,write,read,readFile,writeFile,appendFile'
	).split(',')
;
methods.forEach(function(m){
	fs[m + 'Promise'] = D.nodeCapsule(fs, fs[m]);
});

fs.readJsonSync = function readJsonSync(filename, options){
	if( options && !options.encoding ){
		options.encoding='utf8';
	}
	var data = fs.readFileSync(filename, options || 'utf8');
	return JSON.parse(data);
};
fs.readJsonPromise = function readJsonPromise(filename, options){
	return fs.readFilePromise(filename, options).success(JSON.parse);
};
fs.writeJsonSync = function writeJsonSync(filename, data, options){
	data = JSON.stringify(data, options && options.space || '\t');
	if( options && !options.encoding ){
		options.encoding='utf8';
	}
	return fs.writeFileSync(filename, data, options || 'utf8');
};
fs.writeJsonPromise = function writeJsonPromise(filename, data, options){
	return fs.writeFilePromise(filename, JSON.stringify(data), options);
};

module.exports = fs;

{'fraction_non_alphanumeric': 0.1653127538586515, 'fraction_numerical': 0.0016246953696181965, 'mean_word_length': 6.696875, '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': '1957987', 'n_tokens_mistral': 889, 'n_tokens_neox': 856, 'n_words': 141}