MCPcopy Index your code
hub / github.com/Keyang/node-csvtojson / csvtojson

Function csvtojson

bin/csvtojson.js:1–176  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1function csvtojson() {
2 var Converter = require("../v2").Converter;
3 var fs = require("fs");
4 var options = require("./options.json");
5 var cmds = options.commands;
6 var opts = options.options;
7 var exps = options.examples;
8 var pkg = require("../package.json");
9 var os = require("os");
10 /**
11 *{
12 "cmd": "parse", command to run
13 "options": {}, options to passe to the command
14 "inputStream": process.stdin // input stream for the command. default is stdin. can be a file read stream.
15 };
16 *
17 */
18 var parsedCmd;
19
20 function _showHelp(errno) {
21 var key;
22 errno = typeof errno === "number" ? errno : 0;
23 console.log("csvtojson: Convert csv to JSON format");
24 console.log("version:", pkg.version);
25 console.log("Usage: csvtojson [<command>] [<options>] filepath\n");
26 console.log("Commands: ");
27 for (key in cmds) {
28 if (cmds.hasOwnProperty(key)) {
29 console.log("\t%s: %s", key, cmds[key]);
30 }
31 }
32 console.log("Options: ");
33 for (key in opts) {
34 if (opts.hasOwnProperty(key)) {
35 console.log("\t%s: %s", key, opts[key].desc);
36 }
37 }
38 console.log("Examples: ");
39 for (var i = 0; i < exps.length; i++) {
40 console.log("\t%s", exps[i]);
41 }
42 process.exit(errno);
43 }
44 function stringToRegExp(str) {
45 var lastSlash = str.lastIndexOf("/");
46 var source = str.substr(1, lastSlash);
47 var flag = str.substr(lastSlash + 1);
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";

Callers 1

csvtojson.jsFile · 0.85

Calls 2

commandParserFunction · 0.85
runFunction · 0.85

Tested by

no test coverage detected