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

csv-string

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csv-string - npm Package Compare versions

Comparing version 2.3.3 to 3.0.0

43

lib/csv.js

@@ -72,3 +72,3 @@ 'use strict';

ret = '';
input.forEach(function (item, index) {
input.forEach(function (item) {
ret += exports.stringify(item, sep);

@@ -92,3 +92,3 @@ }

exports.parse = function (input, sep) {
exports.parse = function (input, sep, quo) {
if (sep === undefined) {

@@ -98,4 +98,3 @@ // try to detect the separator if not provided

}
var csv = new Parser(input, sep);
var csv = new Parser(input, sep, quo);
return csv.File();

@@ -105,3 +104,3 @@ }

exports.forEach = function (input, sep, callback) {
exports.forEach = function (input, sep, quo, callback) {
if (arguments.length < 3) {

@@ -111,4 +110,8 @@ callback = sep;

}
else if (arguments.length < 4) {
callback = quo;
quo = '"';
}
var i = 0, s = 0, r;
while (r = exports.read(input.slice(s), sep, function (fields) {
while (r = exports.read(input.slice(s), sep, quo, function (fields) {
callback(fields, i++);

@@ -122,3 +125,3 @@ }

exports.read = function (input, sep, callback) {
exports.read = function (input, sep, quo, callback) {
if (arguments.length < 3) {

@@ -128,3 +131,7 @@ callback = sep;

}
var csv = new Parser(input, sep);
else if (arguments.length < 4) {
callback = quo;
quo = '"';
}
var csv = new Parser(input, sep, quo);
var fields = csv.Row();

@@ -135,3 +142,3 @@ callback(fields);

exports.readAll = function (input, sep, callback) {
exports.readAll = function (input, sep, quo, callback) {
if (arguments.length < 3) {

@@ -141,3 +148,7 @@ callback = sep;

}
var csv = new Parser(input, sep);
else if (arguments.length < 4) {
callback = quo;
quo = '"';
}
var csv = new Parser(input, sep, quo);
var rows = csv.File();

@@ -148,3 +159,3 @@ callback(rows);

exports.readChunk = function (input, sep, callback) {
exports.readChunk = function (input, sep, quo, callback) {
if (arguments.length < 3) {

@@ -154,3 +165,7 @@ callback = sep;

}
var csv = new Parser(input, sep);
else if (arguments.length < 4) {
callback = quo;
quo = '"';
}
var csv = new Parser(input, sep, quo);
var rows = csv.File();

@@ -171,5 +186,5 @@ var ret = 0;

exports.fetch = function (input, sep) {
exports.fetch = function (input, sep, quo) {
var output;
exports.read(input, sep, function (fields) {
exports.read(input, sep, quo, function (fields) {
output = fields;

@@ -176,0 +191,0 @@ }

@@ -33,3 +33,3 @@ /*jshint node:true,laxcomma:true*/

function Parser(input, comma) {
function Parser(input, comma, quote) {
if (!(this instanceof Parser)) {

@@ -41,3 +41,10 @@ return new Parser(input, comma);

this.linePointer = 0;
this.comma = comma || ',';
this.comma = ',';
this.quote = '"';
if (comma && comma[0]) {
this.comma = comma[0];
}
if (quote && quote[0]) {
this.quote = quote[0];
}
}

@@ -104,3 +111,3 @@

if (quotedvalue) {
var value = quotedvalue.slice(1, -1).replace(/\"\"/g, '"');
var value = quotedvalue.slice(1, -1).replace(new RegExp(this.quote + this.quote, 'g'), this.quote);
this.Residue();

@@ -140,3 +147,3 @@ return value;

var value = '', index = this.input.slice(this.pointer).search(new RegExp('[' + this.comma + '\r\n]'));
if (this.input.charAt(this.pointer) === '"') {
if (this.input.charAt(this.pointer) === this.quote) {
return;

@@ -157,10 +164,10 @@ }

Parser.prototype.QuotedValue = function () {
if (this.input.charAt(this.pointer) === '"') {
if (this.input.charAt(this.pointer) === this.quote) {
var searchIndex, index = 1;
while (1) {
searchIndex = this.input.slice(this.pointer + index).search('"');
searchIndex = this.input.slice(this.pointer + index).search(this.quote);
if (searchIndex === -1) {
return;
}
if (this.input.charAt(this.pointer + index + searchIndex + 1) === '"') {
if (this.input.charAt(this.pointer + index + searchIndex + 1) === this.quote) {
index += searchIndex + 2;

@@ -167,0 +174,0 @@ continue;

@@ -10,2 +10,3 @@ 'use strict';

this.sep = (options && options.separator) ? options.separator : undefined;
this.quo = (options && options.quote) ? options.quote : undefined;
}

@@ -27,3 +28,3 @@

var csv = new Parser(this.buffer, this.sep);
var csv = new Parser(this.buffer, this.sep, this.quo);
var rows = csv.File();

@@ -30,0 +31,0 @@

{
"name": "csv-string",
"version": "2.3.3",
"version": "3.0.0",
"author": "Nicolas Thouvenin <nthouvenin@gmail.com>",

@@ -5,0 +5,0 @@ "contributors": [

@@ -58,3 +58,3 @@ # Javascript CSV Strings

## parse(input : String, [separator : String]) : Object
## parse(input : String, [separator : String], [quote : String]) : Object

@@ -114,2 +114,3 @@ Converts a CSV string `input` to array output.

## forEach(input : String, sep : String, quo : String, callback : Function)
## forEach(input : String, sep : String, callback : Function)

@@ -135,2 +136,3 @@ ## forEach(input : String, callback : Function)

## read(input : String, sep : String, quo : String, callback : Function) : Number
## read(input : String, sep : String, callback : Function) : Number

@@ -158,2 +160,3 @@ ## read(input : String, callback : Function) : Number

## readAll(input : String, sep : String, quo : String, callback : Function) : Number
## readAll(input : String, sep : String, callback : Function) : Number

@@ -179,2 +182,3 @@ ## readAll(input : String, callback : Function) : Number

--
## readChunk(input : String, sep : String, quo : String, callback : Function) : Number
## readChunk(input : String, sep : String, callback : Function) : Number

@@ -207,2 +211,3 @@ ## readChunk(input : String, callback : Function) : Number

* **separator** : To indicate the CSV separator. By default is auto (see the detect function)
* quote** : To indicate the CSVquote.

@@ -209,0 +214,0 @@ Example : Read CSV file from the standard input.

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