Converts an array of JavaScript objects into a CSV file, optionally saving it to filesystem.
Installations
npm install objects-to-csv
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
10.16.3
NPM Version
6.9.0
Score
50.9
Supply Chain
99.5
Quality
76
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
anton-bot
Download Statistics
Total Downloads
12,952,790
Last Day
14,094
Last Week
123,705
Last Month
638,764
Last Year
4,946,890
GitHub Statistics
100 Stars
39 Commits
39 Forks
4 Watching
11 Branches
2 Contributors
Package Meta Information
Latest Version
1.3.6
Package Id
objects-to-csv@1.3.6
Size
4.57 kB
NPM Version
6.9.0
Node Version
10.16.3
Publised On
04 Jan 2020
Total Downloads
Cumulative downloads
Total Downloads
12,952,790
Last day
-39.1%
14,094
Compared to previous day
Last week
-24.9%
123,705
Compared to previous week
Last month
21.6%
638,764
Compared to previous month
Last year
62.8%
4,946,890
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Convert array of objects into a CSV file
Converts an array of JavaScript objects into the CSV format. You can save the CSV to file or return it as a string.
The keys in the first object of the array will be used as column names.
Any special characters in the values (such as commas) will be properly escaped.
Usage
1const ObjectsToCsv = require('objects-to-csv'); 2 3// Sample data - two columns, three rows: 4const data = [ 5 {code: 'CA', name: 'California'}, 6 {code: 'TX', name: 'Texas'}, 7 {code: 'NY', name: 'New York'}, 8]; 9 10// If you use "await", code must be inside an asynchronous function: 11(async () => { 12 const csv = new ObjectsToCsv(data); 13 14 // Save to file: 15 await csv.toDisk('./test.csv'); 16 17 // Return the CSV file as string: 18 console.log(await csv.toString()); 19})();
Methods
There are two methods, toDisk(filename)
and toString()
.
async toDisk(filename, options)
Converts the data and saves the CSV file to disk. The filename
must include the
path as well.
The options
is an optional parameter which is an object that contains the
settings. Supported options:
append
- whether to append to the file. Default isfalse
(overwrite the file). Set totrue
to append. Column names will be added only once at the beginning of the file. If the file does not exist, it will be created.bom
- whether to add the Unicode Byte Order Mark at the beginning of the file. Default isfalse
; set totrue
to be able to view Unicode in Excel properly. Otherwise Excel will display Unicode incorrectly.allColumns
- whether to check all array items for keys to convert to columns rather than only the first. This will sort the columns alphabetically. Default isfalse
; set totrue
to check all items for potential column names.
1const ObjectsToCsv = require('objects-to-csv');
2const sampleData = [{ id: 1, text: 'this is a test' }];
3
4// Run asynchronously, without awaiting:
5new ObjectsToCsv(sampleData).toDisk('./test.csv');
6
7// Alternatively, you can append to the existing file:
8new ObjectsToCsv(sampleData).toDisk('./test.csv', { append: true });
9
10// `allColumns: true` collects column names from all objects in the array,
11// instead of only using the first one. In this case the CSV file will
12// contain three columns:
13const mixedData = [
14 { id: 1, name: 'California' },
15 { id: 2, description: 'A long description.' },
16];
17new ObjectsToCsv(mixedData).toDisk('./test.csv', { allColumns: true });
async toString(header = true, allColumns = false)
Returns the CSV file as a string.
Two optional parameters are available:
header
controls whether the column names will be returned as the first row of the file. Default istrue
. Set it tofalse
to get only the data rows, without the column names.allColumns
controls whether to check every item for potential keys to process, rather than only the first item; this will sort the columns alphabetically by key name. Default isfalse
. Set it totrue
to process keys that may not be present in the first object of the array.
1const ObjectsToCsv = require('objects-to-csv'); 2const sampleData = [{ id: 1, text: 'this is a test' }]; 3 4async function printCsv(data) { 5 console.log( 6 await new ObjectsToCsv(data).toString() 7 ); 8} 9 10printCsv(sampleData);
Requirements
Use Node.js version 8 or above.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: The Unlicense: LICENSE:0
Reason
Found 2/14 approved changesets -- score normalized to 1
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
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 18 are checked with a SAST tool
Reason
37 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3
- Warn: Project is vulnerable to: MAL-2023-462
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-79jw-6wg7-r9g4 / GHSA-r5cq-9537-9rpf
- Warn: Project is vulnerable to: GHSA-84p7-fh9c-6g8h
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw
- Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
1.9
/10
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 MoreOther packages similar to objects-to-csv
@types/objects-to-csv
TypeScript definitions for objects-to-csv
tabletojson
Convert HTML tables to JSON objects
alasql
Use SQL to select and filter javascript data - including relational joins and search in nested objects (JSON). Export to and import from Excel and CSV
to-csv
Convert objects to CSV