StackGenVis: Alignment of Data, Algorithms, and Models for Stacking Ensemble Learning Using Performance Metrics
https://doi.org/10.1109/TVCG.2020.3030352
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.2 KiB
60 lines
1.2 KiB
/**
|
|
* read-file <https://github.com/assemble/read-file>
|
|
*
|
|
* Copyright (c) 2014, 2015 Jon Schlinkert.
|
|
* Licensed under the MIT license.
|
|
*/
|
|
|
|
var fs = require('fs');
|
|
|
|
function read(fp, opts, cb) {
|
|
if (typeof opts === 'function') {
|
|
cb = opts;
|
|
opts = {};
|
|
}
|
|
|
|
if (typeof cb !== 'function') {
|
|
throw new TypeError('read-file async expects a callback function.');
|
|
}
|
|
|
|
if (typeof fp !== 'string') {
|
|
cb(new TypeError('read-file async expects a string.'));
|
|
}
|
|
|
|
fs.readFile(fp, opts, function (err, buffer) {
|
|
if (err) return cb(err);
|
|
cb(null, normalize(buffer, opts));
|
|
});
|
|
}
|
|
|
|
read.sync = function(fp, opts) {
|
|
if (typeof fp !== 'string') {
|
|
throw new TypeError('read-file sync expects a string.');
|
|
}
|
|
try {
|
|
return normalize(fs.readFileSync(fp, opts), opts);
|
|
} catch (err) {
|
|
err.message = 'Failed to read "' + fp + '": ' + err.message;
|
|
throw new Error(err);
|
|
}
|
|
};
|
|
|
|
function normalize(str, opts) {
|
|
str = stripBom(str);
|
|
if (typeof opts === 'object' && opts.normalize === true) {
|
|
return String(str).replace(/\r\n|\n/g, '\n');
|
|
}
|
|
return str;
|
|
}
|
|
|
|
function stripBom(str) {
|
|
return typeof str === 'string' && str.charAt(0) === '\uFEFF'
|
|
? str.slice(1)
|
|
: str;
|
|
}
|
|
|
|
/**
|
|
* Expose `read`
|
|
*/
|
|
|
|
module.exports = read; |