Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

csvtojson

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csvtojson - npm Package Compare versions

Comparing version 0.5.10 to 0.5.11

51

bin/csvtojson.js

@@ -9,3 +9,3 @@ function csvtojson() {

var exps = options.examples;
var pkg=require("../package.json");
var pkg = require("../package.json");
/**

@@ -20,2 +20,3 @@ *{

var parsedCmd;
function _showHelp(errno) {

@@ -25,3 +26,3 @@ var key;

console.log("csvtojson: Convert csv to JSON format");
console.log("version:",pkg.version);
console.log("version:", pkg.version);
console.log("Usage: csvtojson [<command>] [<options>] filepath\n");

@@ -50,3 +51,8 @@ console.log("Commands: ");

parsedCmd.options.constructResult = false;
parsedCmd.options.toArrayString = true;
if (parsedCmd.options.toArrayString === undefined) {
parsedCmd.options.toArrayString = true;
}
if (parsedCmd.options.maxRowLength === undefined) {
parsedCmd.options.maxRowLength = 10240;
}
if (is === process.stdin && is.isTTY) {

@@ -56,3 +62,14 @@ console.log("Please specify csv file path or pipe the csv data through.\n");

}
is.pipe(new Converter(parsedCmd.options)).pipe(process.stdout);
var conv = new Converter(parsedCmd.options);
conv.on("error", function (err, pos) {
if (!parsedCmd.options.quiet) {
console.error("csvtojson got an error: ", err);
if (pos) {
console.error("The error happens at following line: ");
console.log(pos);
}
}
process.exit(1);
})
is.pipe(conv).pipe(process.stdout);
}

@@ -65,5 +82,5 @@

web.startWebServer(options);
} else if (cmd ==="version"){
} else if (cmd === "version") {
console.log(pkg.version);
}else {
} else {
console.log("unknown command %s.", cmd);

@@ -80,9 +97,10 @@ _showHelp(1);

};
function parseObject(val,optional){
function parseObject(val, optional) {
try {
return JSON.parse(val);
}catch(e){
if (optional){
} catch (e) {
if (optional) {
return val;
}else{
} else {
console.error(e);

@@ -93,2 +111,3 @@ process.exit(1);

}
function parseBool(str, optName) {

@@ -104,3 +123,3 @@ str = str.toLowerCase();

}
process.argv.slice(2).forEach(function(item) {
process.argv.slice(2).forEach(function (item) {
if (item.indexOf("--") > -1) {

@@ -121,8 +140,8 @@ var itemArr = item.split("=");

parsedCmd.options[key] = parseBool(val, optName);
} else if (type ==="number"){
} else if (type === "number") {
parsedCmd.options[key] = parseFloat(val);
} else if (type ==="object"){
parsedCmd.options[key] = parseObject(val,false);
}else if (type === "~object"){
parsedCmd.options[key] = parseObject(val,true);
} else if (type === "object") {
parsedCmd.options[key] = parseObject(val, false);
} else if (type === "~object") {
parsedCmd.options[key] = parseObject(val, true);
} else {

@@ -129,0 +148,0 @@ throw ({

{
"commands": {
"parse": "(Default)Parse a csv file to json",
"startserver": "(Deprecated)Start a web server",
"version": "Show version of current csvtojson"
},
"options": {
"--delimiter": {
"desc": "delimiter to separate columns. Possible to give an array or just use 'auto'. default comma (,). e.g. --delimiter=# --delimiter='[\",\",\";\"]' --delimiter=auto",
"type": "~object"
"commands": {
"parse": "(Default)Parse a csv file to json",
"startserver": "(Deprecated)Start a web server",
"version": "Show version of current csvtojson"
},
"--quote": {
"desc": "quote surrounding a column content containing delimiters. default double quote (\"). e.g. --quote=# ",
"type": "string"
},
"--trim": {
"desc": "Indicate if parser trim off spaces surrounding column content. e.g. \" content \" will be trimmed to \"content\". Default: true",
"type": "boolean"
},
"--checkType": {
"desc": "This parameter turns on and off whether check field type. default is true.",
"type": "boolean"
"options": {
"--delimiter": {
"desc": "delimiter to separate columns. Possible to give an array or just use 'auto'. default comma (,). e.g. --delimiter=# --delimiter='[\",\",\";\"]' --delimiter=auto",
"type": "~object"
},
"--quote": {
"desc": "quote surrounding a column content containing delimiters. default double quote (\"). e.g. --quote=# ",
"type": "string"
},
"--trim": {
"desc": "Indicate if parser trim off spaces surrounding column content. e.g. \" content \" will be trimmed to \"content\". Default: true",
"type": "boolean"
},
"--checkType": {
"desc": "This parameter turns on and off whether check field type. default is true.",
"type": "boolean"
},
"--ignoreEmpty": {
"desc": "This parameter turns on and off whether ignore empty column values while parsing. default is false",
"type": "boolean"
},
"--workerNum": {
"desc": "Number of worker processes. The worker process will use multi-cores to help process CSV data. Set to number of Core to improve the performance of processing large csv file. Keep 1 for small csv files. Default 1.",
"type": "number"
},
"--noheader": {
"desc": "Indicating csv data has no header row and first row is data row. Default is false",
"type": "boolean"
},
"--headers": {
"desc": "An array to specify the headers of CSV data. If --noheader is false, this value will override CSV header. Default: null. Example: [\"my field\",\"name\"]",
"type": "object"
},
"--flatKeys": {
"desc": "Don't interpret dots (.) and square brackets in header fields as nested object or array identifiers at all (treat them like regular characters for JSON field identifiers). Default: false.",
"type": "boolean"
},
"--maxRowLength": {
"desc": "the max character a csv row could have. 0 means infinite. If max number exceeded, parser will emit \"error\" of \"row_exceed\". if a possibly corrupted csv data provided, give it a number like 65535 so the parser wont consume memory. default: 10240",
"type": "number"
},
"--checkColumn": {
"desc": "whether check column number of a row is the same as headers. If column number mismatched headers number, an error of \"mismatched_column\" will be emitted.. default: false",
"type": "boolean"
},
"--eol": {
"desc": "Explicitly specify the end of line character to use.",
"type": "string"
},
"--toArrayString": {
"desc": "Output result as JSON array. Default is true, set to false to output JSON objects (not array)",
"type": "boolean"
},
"--quiet": {
"desc": "If any error happens, quit the process quietly rather than log out the error. Default is false.",
"type": "boolean"
}
},
"--ignoreEmpty": {
"desc": "This parameter turns on and off whether ignore empty column values while parsing. default is false",
"type": "boolean"
},
"--workerNum": {
"desc": "Number of worker processes. The worker process will use multi-cores to help process CSV data. Set to number of Core to improve the performance of processing large csv file. Keep 1 for small csv files. Default 1.",
"type": "number"
},
"--noheader": {
"desc": "Indicating csv data has no header row and first row is data row. Default is false",
"type": "boolean"
},
"--headers": {
"desc": "An array to specify the headers of CSV data. If --noheader is false, this value will override CSV header. Default: null. Example: [\"my field\",\"name\"]",
"type": "object"
},
"--flatKeys": {
"desc": "Don't interpret dots (.) and square brackets in header fields as nested object or array identifiers at all (treat them like regular characters for JSON field identifiers). Default: false.",
"type": "boolean"
},
"--maxRowLength": {
"desc": "the max character a csv row could have. 0 means infinite. If max number exceeded, parser will emit \"error\" of \"row_exceed\". if a possibly corrupted csv data provided, give it a number like 65535 so the parser wont consume memory. default: 0",
"type": "number"
},
"--checkColumn": {
"desc": "whether check column number of a row is the same as headers. If column number mismatched headers number, an error of \"mismatched_column\" will be emitted.. default: false",
"type": "boolean"
},
"--eol": {
"desc": "Explicitly specify the end of line character to use.",
"type": "string"
}
},
"examples": [
"csvtojson < csvfile",
"csvtojson <path to csvfile>",
"cat <csvfile> | csvtojson",
"csvtojson <csvfilepath> --checkType=false --trim=false --delimiter=#"
]
}
"examples": [
"csvtojson < csvfile",
"csvtojson <path to csvfile>",
"cat <csvfile> | csvtojson",
"csvtojson <csvfilepath> --checkType=false --trim=false --delimiter=#"
]
}

@@ -21,3 +21,3 @@ {

],
"version": "0.5.10",
"version": "0.5.11",
"keywords": [

@@ -24,0 +24,0 @@ "csv",

@@ -1,3 +0,2 @@

<img src="https://travis-ci.org/Keyang/node-csvtojson.svg?branch=master"/>
[![Build Status](https://travis-ci.org/Keyang/node-csvtojson.svg?branch=master)](https://travis-ci.org/Keyang/node-csvtojson)
# CSVTOJSON

@@ -4,0 +3,0 @@ All you need nodejs csv to json converter.

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc