Skip to content

Commit

Permalink
Support --auto-type flag from csv2json cli
Browse files Browse the repository at this point in the history
  • Loading branch information
David Marr committed Jan 5, 2024
1 parent a2facce commit b297dd4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bin/dsv2json.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {fileURLToPath} from "url";
import rw from "rw";
import {program} from "commander";
import iconv from "iconv-lite";
import {dsvFormat} from "../src/index.js";
import {autoType, dsvFormat} from "../src/index.js";

const progname = basename(process.argv[1]);
const defaultInDelimiter = progname.slice(0, 3) === "tsv" ? "\t" : ",";
Expand All @@ -28,7 +28,7 @@ const inFormat = dsvFormat(options.inputDelimiter);

rw.dash.readFile(program.args[0] || "-", (error, text) => {
if (error) throw error;
const rowConverter = options.autoType ? dsv.autoType : null
const rowConverter = options.autoType ? autoType : null
const rows = inFormat.parse(iconv.decode(text, options.inputEncoding), rowConverter);
rw.dash.writeFile(options.out, iconv.encode(options.newlineDelimited
? rows.map((row) => JSON.stringify(row)).join("\n") + "\n"
Expand Down

0 comments on commit b297dd4

Please sign in to comment.