()
| 48 | return new RegExp(source,flag); |
| 49 | } |
| 50 | function parse() { |
| 51 | var is = parsedCmd.inputStream; |
| 52 | if (parsedCmd.options.maxRowLength === undefined) { |
| 53 | parsedCmd.options.maxRowLength = 10240; |
| 54 | } |
| 55 | if (is === process.stdin && is.isTTY) { |
| 56 | console.log("Please specify csv file path or pipe the csv data through.\n"); |
| 57 | _showHelp(1); |
| 58 | } |
| 59 | if (parsedCmd.options.delimiter === "\\t") { |
| 60 | parsedCmd.options.delimiter = "\t"; |
| 61 | } |
| 62 | if (parsedCmd.options.ignoreColumns) { |
| 63 | parsedCmd.options.ignoreColumns=stringToRegExp(parsedCmd.options.ignoreColumns); |
| 64 | |
| 65 | } |
| 66 | if (parsedCmd.options.includeColumns) { |
| 67 | parsedCmd.options.includeColumns=stringToRegExp(parsedCmd.options.includeColumns); |
| 68 | |
| 69 | } |
| 70 | var conv = new Converter(parsedCmd.options); |
| 71 | var isFirst = true; |
| 72 | conv.on("error", function (err, pos) { |
| 73 | if (!parsedCmd.options.quiet) { |
| 74 | console.error("csvtojson got an error: ", err); |
| 75 | if (pos) { |
| 76 | console.error("The error happens at following line: "); |
| 77 | console.log(pos); |
| 78 | } |
| 79 | } |
| 80 | process.exit(1); |
| 81 | }) |
| 82 | .on("data",function (dataStr) { |
| 83 | process.stdout.write((isFirst ? "" : "," + os.EOL) + dataStr.toString().substr(0,dataStr.length-1)); |
| 84 | isFirst = false; |
| 85 | }) |
| 86 | .on("done", function () { |
| 87 | console.log(os.EOL + "]"); |
| 88 | }) |
| 89 | console.log("["); |
| 90 | is.pipe(conv); |
| 91 | // is.pipe(conv); |
| 92 | } |
| 93 | |
| 94 | function run(cmd, options) { |
| 95 | if (cmd === "parse") { |
no test coverage detected