1.1.4 • Published 28 days ago

s_e_l_e_c_t_c_s_v v1.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
28 days ago

Parse CSV with JavaScript

It is the fastest, simplest and most powerful package of all existing libraries in npmjs. It converts .csv files into an array and even into lines. It contains two important functions parseCsv that handles a csv file, you only need a link to the file. And parseText deals with text, and they both have the same roles and and methods, and it comes with these features:

  • Package with small content (< 30 KB)
  • Easy to use
  • Parse CSV files directly (local)
  • Fast mode
  • Stream large files
  • It is a synchronous package
  • Uses a piece
  • Uses row offset (get rows from line x to line x+n)
  • Returns rows or lines
  • No external dependencies
  • Flexible with lots of options (header, quote, line break, delimiter)
  • One of the only parsers that correctly handles line-breaks and quotations

select-csv has no dependencies .

Install:

select-csv is available on npm. It can be installed with the following command:

npm install select-csv

Usage:

The example below shows how you can write records defined as the array of objects into a file.

const {parseCsv,parseText} = require("select-csv");

var parse;

// Initial object from .csv file
parse = parseCsv('file_path.csv');

// Or if you just want initial object from text
parse = parseText(
`Index,User Id,First Name,Last Name,Sex
1,5f10e9D33fC5f2b,Sara,Mcguire,Female
2,751cD1cbF77e005,Alisha,Hebert,Male
3,DcEFDB2D2e62bF9,Gwendolyn,Sheppard,Male`
);
  • If you want to get all rows :
const obj = parse.get(); //Return all rows
  • If you want to get a chunks of rows :
var obj;
obj = parse.chunk(c) 
//The 'c' parameter must be an integer and greater than or equal to 1

//Examples:
obj = parse.chunk(2) //Return row 0 and 1
obj = parse.chunk(4) //Return row 2,3,4 and 5
obj = parse.chunk(3) //Return row 6,7 and 8
  • If you want to get specific rows :
var obj
obj = parse.rowOffset(from) 
// The 'from' parameter must be an integer and greater than or equal to 0

// Or
obj = parse.rowOffset(from,to)
// The 'to' parameter must be an integer and greater than or equal to 1

//Examples:
obj = parse.rowOffset(6) //Returns all rows from the sixth row to the last row
obj = parse.rowOffset(5,14) //Returns all rows from 5th to 14th grade
  • If you want to change the row offset :
parse.setRowOffset(offs) 
// The 'offs' parameter must be an integer and greater than or equal to 0
  • The default object option :
{
	'header': true,
	'quote': false,
	'linebreak': '\r\n',
	'delimiter': ","
}
		// 'delimiter': false (Get rows containing columns, and if set 'false', get lines  without columns)
  • If you want to use specific option :
const option = {
	'header': false, 	/* or true */
	'quote': true, 		/* or false */
	'linebreak': '\n', 	/* '\n' or '\r' or any other string  */
	'delimiter': ","	/* ';' or any other string or false */
}

var parse;
// Initial object from .csv file
parse = parseCsv('file_path.csv',option);

// Or if you just want initial object from text
parse = parseText(
`Index,User Id,First Name,Last Name,Sex
1,5f10e9D33fC5f2b,Sara,Mcguire,Female
2,751cD1cbF77e005,Alisha,Hebert,Male
3,DcEFDB2D2e62bF9,Gwendolyn,Sheppard,Male`
, option);
  • If you want reset option after multiple uses of your code :
const option = {       // Just an exapmle
	'header': false,
	'quote': true,
	'linebreak': '\n'
}

parse.resetOption(option);
1.1.4

28 days ago

1.1.3

28 days ago

1.1.2

28 days ago

1.1.1

28 days ago

1.1.0

29 days ago

1.0.12

29 days ago

1.0.10

29 days ago

1.0.9

29 days ago

1.0.7

29 days ago

1.0.6

29 days ago

1.0.5

29 days ago

1.0.4

29 days ago

1.0.3

29 days ago

1.0.2

29 days ago

1.0.1

29 days ago