packages/perspective-cli/src/js/index.js
async function convert(filename, options) {
    let file;
    if (filename) {
        file = fs.readFileSync(filename).toString();
    } else {
        file = await read_stdin();
    }
    try {
        file = JSON.parse(file);
    } catch {}
    let tbl = table(file);
    let view = tbl.view();
    let out;
    options.format = options.format || "arrow";
    if (options.format === "csv") {
        out = await view.to_csv();
    } else if (options.format === "columns") {
        out = JSON.stringify(await view.to_columns());
    } else if (options.format === "json") {
        out = JSON.stringify(await view.to_json());
    } else {
        out = await view.to_arrow();
    }
    if (options.format === "arrow") {
        if (options.output) {
            fs.writeFileSync(options.output, new Buffer(out), "binary");
        } else {
            console.log(new Buffer(out).toString());
        }
    } else {
        if (options.output) {
            fs.writeFileSync(options.output, out);
        } else {
            console.log(out);
        }
    }
    view.delete();
    tbl.delete();
}
async function convert(filename, options) {
    let file;
    if (filename) {
        file = fs.readFileSync(filename).toString();
    } else {
        file = await read_stdin();
    }
    try {
        file = JSON.parse(file);
    } catch {}
    let tbl = table(file);
    let view = tbl.view();
    let out;
    options.format = options.format || "arrow";
    if (options.format === "csv") {
        out = await view.to_csv();
    } else if (options.format === "columns") {
        out = JSON.stringify(await view.to_columns());
    } else if (options.format === "json") {
        out = JSON.stringify(await view.to_json());
    } else {
        out = await view.to_arrow();
    }
    if (options.format === "arrow") {
        if (options.output) {
            fs.writeFileSync(options.output, new Buffer(out), "binary");
        } else {
            console.log(new Buffer(out).toString());
        }
    } else {
        if (options.output) {
            fs.writeFileSync(options.output, out);
        } else {
            console.log(out);
        }
    }
    view.delete();
    tbl.delete();
}
async function convert ( filename , options ) { let file ; if ( filename ) { file = fs . readFileSync ( filename ) . toString ( ) ; } else { file = await read_stdin ( ) ; } try { file = JSON . parse ( file ) ; } catch { } let tbl = table ( file ) ; let view = tbl . view ( ) ; let out ; options . format = options . format || "arrow" ; if ( options . format === "csv" ) { out = await view . to_csv ( ) ; } else if ( options . format === "columns" ) { out = JSON . stringify ( await view . to_columns ( ) ) ; } else if ( options . format === "json" ) { out = JSON . stringify ( await view . to_json ( ) ) ; } else { out = await view . to_arrow ( ) ; } if ( options . format === "arrow" ) { if ( options . output ) { fs . writeFileSync ( options . output , new Buffer ( out ) , "binary" ) ; } else { console . log ( new Buffer ( out ) . toString ( ) ) ; } } else { if ( options . output ) { fs . writeFileSync ( options . output , out ) ; } else { console . log ( out ) ; } } view . delete ( ) ; tbl . delete ( ) ; }
Convert data from one format to another.

@param {*} filename
@param {*} options
Convert data from one format to another .