index.js
function parse(contents, retained, parser) {
    var errors = [], data = [], lines = 0;

    // optional parser
    if (!parser) parser = JSON;

    // process each line of the file
    contents.toString().split('\n').forEach(function(line) {
        if (!line) return;
        lines++;
        try {
            data.push(parser.parse(line));
        } catch (e) {
            e.line = line;
            errors.push(e);
        }
    });

    // if no errors/data, don't return an empty array
    var ret = {};
    if (errors.length) ret.errors = errors;
    if (data.length) ret.data = data;

    // if every line failed, probably not line-delimited
    if (errors.length == lines) ret.errors = retained;

    return ret;
}
function parse(contents, retained, parser) {
    var errors = [], data = [], lines = 0;

    // optional parser
    if (!parser) parser = JSON;

    // process each line of the file
    contents.toString().split('\n').forEach(function(line) {
        if (!line) return;
        lines++;
        try {
            data.push(parser.parse(line));
        } catch (e) {
            e.line = line;
            errors.push(e);
        }
    });

    // if no errors/data, don't return an empty array
    var ret = {};
    if (errors.length) ret.errors = errors;
    if (data.length) ret.data = data;

    // if every line failed, probably not line-delimited
    if (errors.length == lines) ret.errors = retained;

    return ret;
}
function parse ( contents , retained , parser ) { var errors = [ ] , data = [ ] , lines = 0 ; // optional parser if ( ! parser ) parser = JSON ; // process each line of the file contents . toString ( ) . split ( '\n' ) . forEach ( function ( line ) { if ( ! line ) return ; lines ++ ; try { data . push ( parser . parse ( line ) ) ; } catch ( e ) { e . line = line ; errors . push ( e ) ; } } ) ; // if no errors/data, don't return an empty array var ret = { } ; if ( errors . length ) ret . errors = errors ; if ( data . length ) ret . data = data ; // if every line failed, probably not line-delimited if ( errors . length == lines ) ret . errors = retained ; return ret ; }
process line-delimited files
process line - delimited files