objfile
Version:
Read from + write to + update INI and JSON files via a simple asynchronous API
40 lines (34 loc) • 984 B
JavaScript
// Generated by CoffeeScript 1.9.1
var IniFile, JsonFile;
IniFile = require('./file/ini-file');
JsonFile = require('./file/json-file');
module.exports = function(path, opts, cb) {
var ref, ref1;
if (!cb && typeof opts === 'function') {
ref = [opts, {}], cb = ref[0], opts = ref[1];
}
if (opts == null) {
opts = {};
}
if (typeof opts !== 'object') {
throw new Error('options must be object: objfile(path, options, callback)');
}
if (opts.type != null) {
if ((ref1 = opts.type) !== 'ini' && ref1 !== 'json') {
throw new Error('options.type must be either \'ini\', \'json\' or undefined');
}
} else {
if (String(path).toLowerCase().split('.').pop() === 'ini') {
opts.type = 'ini';
} else {
opts.type = 'json';
}
}
if (opts.type === 'ini') {
return new IniFile(path, opts, cb);
} else {
return new JsonFile(path, opts, cb);
}
};
module.exports.IniFile = IniFile;
module.exports.JsonFile = JsonFile;