Gathering detailed insights and metrics for csv-string
Gathering detailed insights and metrics for csv-string
Gathering detailed insights and metrics for csv-string
Gathering detailed insights and metrics for csv-string
string
string contains methods that aren't included in the vanilla JavaScript string such as escaping html, decoding html entities, stripping tags, etc.
csv-writer
Convert objects/arrays into a CSV string or write them into a CSV file
parenthesis
Parse parentheses from a string
objects-to-csv
Converts an array of objects into a CSV file. Saves CSV to disk or returns as string.
CSV Strings & Streams for Javascript since 2012
npm install csv-string
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.1
Supply Chain
99.5
Quality
79.9
Maintenance
100
Vulnerability
100
License
TypeScript (91.95%)
JavaScript (6.69%)
Shell (1.36%)
Total Downloads
17,214,344
Last Day
11,600
Last Week
101,826
Last Month
510,244
Last Year
5,494,149
86 Stars
227 Commits
18 Forks
6 Watching
11 Branches
21 Contributors
Latest Version
4.1.1
Package Id
csv-string@4.1.1
Unpacked Size
29.63 kB
Size
8.21 kB
File Count
13
NPM Version
8.11.0
Node Version
16.15.1
Cumulative downloads
Total Downloads
Last day
-48%
11,600
Compared to previous day
Last week
-20.4%
101,826
Compared to previous week
Last month
-4.5%
510,244
Compared to previous month
Last year
28.4%
5,494,149
Compared to previous year
Parse and Stringify for CSV strings.
CSV.parse
and CSV.stringify
).1import * as CSV from 'csv-string'; 2 3// with String 4const arr = CSV.parse('a,b,c\na,b,c'); 5const str = CSV.stringify(arr); 6 7// with Stream 8const stream = CSV.createStream(); 9stream.on('data', rows => { 10 process.stdout.write(CSV.stringify(rows, ',')); 11}); 12process.stdin.pipe(stream);
using npm:
1npm install csv-string
or yarn
1yarn add csv-string
Converts a CSV string input
to array output.
Options :
comma
String to indicate the CSV separator. (optional, default ,
)quote
String to indicate the CSV quote if need. (optional, default "
)output
String choose 'objects' or 'tuples' to change output for Array or Object. (optional, default tuples
)Example 1 :
1const CSV = require('csv-string'); 2const parsedCsv = CSV.parse('a;b;c\nd;e;f', ';'); 3console.log(parsedCsv);
Output:
1[ 2 ["a", "b", "c"], 3 ["d", "e", "f"] 4]
Example 2 :
1const CSV = require('csv-string'); 2const parsedCsv = CSV.parse('a,b,c\n1,2,3\n4,5,6', { output: 'objects' }); 3console.log(parsedCsv);
Output:
1[ 2 { a: '1', b: '2', c: '3' }, 3 { a: '4', b: '5', c: '6' } 4]
If separator parameter is not provided, it is automatically detected.
Converts object input
to a CSV string.
1import * as CSV from 'csv-string'; 2 3console.log(CSV.stringify(['a', 'b', 'c'])); 4console.log( 5 CSV.stringify([ 6 ['c', 'd', 'e'], 7 ['c', 'd', 'e'] 8 ]) 9); 10console.log(CSV.stringify({ a: 'e', b: 'f', c: 'g' }));
Output:
1a,b,c 2 3c,d,e 4c,d,e 5 6e,f,g
Detects the best separator.
1import * as CSV from 'csv-string'; 2 3console.log(CSV.detect('a,b,c')); 4console.log(CSV.detect('a;b;c')); 5console.log(CSV.detect('a|b|c')); 6console.log(CSV.detect('a\tb\tc'));
Output:
1, 2; 3| 4\t
callback(row: array, index: number): void
Calls callback
for each CSV row/line. The Array passed to callback contains the fields of the current row.
1import * as CSV from 'csv-string'; 2 3const data = 'a,b,c\nd,e,f'; 4 5CSV.forEach(data, ',', function (row, index) { 6 console.log('#' + index + ' : ', row); 7});
Output:
1#0 : [ 'a', 'b', 'c' ] 2#1 : [ 'd', 'e', 'f' ]
callback(row: array): void
Calls callback
when a CSV row is read. The Array passed to callback contains the fields of the row.
Returns the first offset after the row.
1import * as CSV from 'csv-string'; 2 3const data = 'a,b,c\nd,e,f'; 4 5const index = CSV.read(data, ',', row => { 6 console.log(row); 7}); 8 9console.log(data.slice(index));
Output:
1[ 'a', 'b', 'c' ] 2d,e,f
callback(rows: array): void
Calls callback
when all CSV rows are read. The Array passed to callback contains the rows of the file.
Returns the offset of the end of parsing (generally it's the end of the input string).
1import * as CSV from 'csv-string'; 2 3const data = 'a,b,c\nd,e,f'; 4 5const index = CSV.readAll(data, row => { 6 console.log(row); 7}); 8 9console.log('-' + data.slice(index) + '-');
Output:
1[ [ 'a', 'b', 'c' ], [ 'd', 'e', 'f' ] ] 2--
callback(rows: array): void
Calls callback
when all CSV rows are read. The last row could be ignored, because the remainder could be in another chunk.
The Array passed to callback contains the rows of the file.
Returns the offset of the end of parsing. If the last row is ignored, the offset will point to the beginnning of the row.
1import * as CSV from 'csv-string'; 2 3const data = 'a,b,c\nd,e'; 4 5const index = CSV.readChunk(data, row => { 6 console.log(row); 7}); 8 9console.log('-' + data.slice(index) + '-');
Output:
1[ [ 'a', 'b', 'c' ] ] 2--
Create a writable stream for CSV chunk. Options are :
Example : Read CSV file from the standard input.
1const stream = CSV.createStream(); 2 3stream.on('data', row => { 4 console.log(row); 5}); 6 7process.stdin.resume(); 8process.stdin.setEncoding('utf8'); 9process.stdin.pipe(stream);
clone
yarn install
yarn test
(ensure all tests pass)yarn bench
(to check the performance impact)There is a quite basic benchmark to compare this project to other related ones, using file streams as input. See ./bench
for source code.
1yarn bench
for a test file with 949,044 rows
Package | Time | Output/Input similarity |
---|---|---|
a-csv | 6.01s | ~99% |
csv-stream | 6.64s | ~73% |
csv-streamer | 7.03s | ~79% |
csv-string | 6.53s | 100% |
fast-csv | 12.33s | 99.99% |
nodecsv | 7.10s | 100% |
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 4/12 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
28 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More