Socket
Socket
Sign inDemoInstall

json-2-csv

Package Overview
Dependencies
Maintainers
1
Versions
140
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-2-csv - npm Package Compare versions

Comparing version 3.4.1 to 3.4.2

8

package.json

@@ -8,3 +8,3 @@ {

"description": "A JSON to CSV and CSV to JSON converter that natively supports sub-documents and auto-generates the CSV heading.",
"version": "3.4.1",
"version": "3.4.2",
"repository": {

@@ -25,3 +25,3 @@ "type": "git",

"test": "mocha test/tests.js",
"coverage": "istanbul cover mocha -- -R spec",
"coverage": "istanbul cover _mocha -- -R spec",
"lint": "npm run lint:eslint && npm run lint:tslint",

@@ -52,7 +52,7 @@ "lint:eslint": "eslint src bin test",

"commander": "2.19.0",
"eslint": "5.11.1",
"eslint": "5.15.3",
"istanbul": "0.4.5",
"mocha": "5.2.0",
"should": "13.2.3",
"tslint": "5.12.1",
"tslint": "5.14.0",
"typescript": "3.3.3"

@@ -59,0 +59,0 @@ },

# json-2-csv
**Convert JSON to CSV _or_ CSV to JSON**
[![Dependencies](https://img.shields.io/david/mrodrig/json-2-csv.svg?style=flat-square)](https://www.npmjs.org/package/json-2-csv)
[![Dependencies](https://img.shields.io/david/mrodrig/json-2-csv.svg)](https://www.npmjs.org/package/json-2-csv)
[![Downloads](http://img.shields.io/npm/dm/json-2-csv.svg)](https://www.npmjs.org/package/json-2-csv)

@@ -179,6 +179,6 @@ [![NPM version](https://img.shields.io/npm/v/json-2-csv.svg)](https://www.npmjs.org/package/json-2-csv)

```
Statements : 100% ( 272/272 )
Branches : 100% ( 143/143 )
Statements : 100% ( 275/275 )
Branches : 100% ( 149/149 )
Functions : 100% ( 49/49 )
Lines : 100% ( 266/266 )
Lines : 100% ( 269/269 )
```

@@ -185,0 +185,0 @@

@@ -77,4 +77,4 @@ export interface ISharedOptions {

export function csv2json(csv: string,
callback: (err?: Error, data?: Array<unknown>) => void, options?: ISharedOptions): void;
callback: (err?: Error, data?: unknown[]) => void, options?: ISharedOptions): void;
export function csv2jsonAsync(csv: string, options?: ISharedOptions): Promise<Array<unknown>>;
export function csv2jsonAsync(csv: string, options?: ISharedOptions): Promise<unknown[]>;

@@ -96,7 +96,26 @@ 'use strict';

if (index === lastCharacterIndex) {
// If we reached the end of the line, add the remaining value
if (index === lastCharacterIndex && character === options.delimiter.field) {
// If we reached the end of the line and the current character is a field delimiter...
// Push the value for the field that we were parsing
splitLine.push(
// If the start index is the current index (and since the character is a comma),
// then the value being parsed is an empty value accordingly, add an empty string
stateVariables.startIndex === index
? ''
// Otherwise there is a valid value, but we do not want to include the current character (field delimiter)
: line.substring(stateVariables.startIndex, index)
);
// Since the last character is a comma, there's still an additional implied field value trailing the comma.
// Since this value is empty, we push an extra empty value
splitLine.push('');
} else if (index === lastCharacterIndex) {
// Otherwise if we reached the end of the line (and current character is not a field delimiter)
// Retrieve the remaining value and add it to the split line list of values
splitLine.push(line.substring(stateVariables.startIndex));
} else if (character === options.delimiter.wrap && index === 0) {
// If the line starts with a wrap delimiter
// If the line starts with a wrap delimiter (ie. "*)
stateVariables.insideWrapDelimiter = true;

@@ -107,2 +126,3 @@ stateVariables.parsingValue = true;

// If we reached a wrap delimiter with a field delimiter after it (ie. *",)
splitLine.push(line.substring(stateVariables.startIndex, index + 1));

@@ -112,4 +132,6 @@ stateVariables.startIndex = index + 2; // next value starts after the field delimiter

stateVariables.parsingValue = false;
} else if (character === options.delimiter.wrap && charBefore === options.delimiter.field && !stateVariables.insideWrapDelimiter && stateVariables.parsingValue) {
} else if (character === options.delimiter.wrap && charBefore === options.delimiter.field &&
!stateVariables.insideWrapDelimiter && stateVariables.parsingValue) {
// If we reached a wrap delimiter with a field delimiter after it (ie. ,"*)
splitLine.push(line.substring(stateVariables.startIndex, index - 1));

@@ -120,15 +142,18 @@ stateVariables.insideWrapDelimiter = true;

} else if (character === options.delimiter.wrap && charAfter === options.delimiter.wrap) {
// If we run into an escaped quote
// If we run into an escaped quote (ie. "") skip past the second quote
index += 2;
continue;
} else if (character === options.delimiter.field && charBefore !== options.delimiter.wrap &&
// If we reached a field delimiter and are not inside the wrap delimiters (ie. *,*)
charAfter !== options.delimiter.wrap && !stateVariables.insideWrapDelimiter &&
stateVariables.parsingValue) {
// If we reached a field delimiter and are not inside the wrap delimiters (ie. *,*)
splitLine.push(line.substring(stateVariables.startIndex, index));
stateVariables.startIndex = index + 1;
} else if (character === options.delimiter.field && charBefore === options.delimiter.wrap &&
// If we reached a field delimiter, the previous character was a wrap delimiter, and the next character is not a wrap delimiter (ie. ",*)
charAfter !== options.delimiter.wrap && !stateVariables.parsingValue) {
// If we reached a field delimiter, the previous character was a wrap delimiter, and the
// next character is not a wrap delimiter (ie. ",*)
stateVariables.insideWrapDelimiter = false;

@@ -135,0 +160,0 @@ stateVariables.parsingValue = true;

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