
Research
/Security News
Contagious Interview Campaign Escalates With 67 Malicious npm Packages and New Malware Loader
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
convert-csv-to-array
Advanced tools
Convert a csv formatted string to an array
I needed a simple way to convert csv formatted string to an array to display it in a table component.
$ npm i convert-csv-to-array -S
or
$ yarn add convert-csv-to-array
Take a look into the usage section for a detailed example.
Note: you can also use the default export.
This function converts a csv formatted string into an array of objects, or into an array of arrays.
Returns a new array.
const array = convertCSVToArray(data, options);
true
or false
, default: true
'object'
or 'array'
, default: 'object'
','
Some examples on how to use this library.
const { convertCSVToArray } = require('convert-csv-to-array');
const converter = require('convert-csv-to-array');
// would be a use input (upload) or read from a file
const data = 'number;first;last;handle\n1;Mark;Otto;@mdo\n2;Jacob;Thornton;@fat\n3;Larry;the Bird;@twitter\n';
/*
const arrayofArrays = [
['number', 'first', 'last', 'handle'],
[1, 'Mark', 'Otto', '@mdo'],
[2, 'Jacob', 'Thornton', '@fat'],
[3, 'Larry', 'the Bird', '@twitter'],
];
*/
const arrayofArrays = convertCSVToArray(data, {
type: 'array',
separator: ';', // use the separator you use in your csv (e.g. '\t', ',', ';' ...)
});
/*
const arrayofObjects = [
['number', 'first', 'last', 'handle'],
{
number: 1,
first: 'Mark',
last: 'Otto',
handle: '@mdo',
},
{
number: 2,
first: 'Jacob',
last: 'Thornton',
handle: '@fat',
},
{
number: 3,
first: 'Larry',
last: 'the Bird',
handle: '@twitter',
},
];
*/
const arrayofObjects = convertCSVToArray(data, {
separator: ';', // use the separator you use in your csv (e.g. '\t', ',', ';' ...)
});
/*
const arrayofArraysWithoutHeader = [
[1, 'Mark', 'Otto', '@mdo'],
[2, 'Jacob', 'Thornton', '@fat'],
[3, 'Larry', 'the Bird', '@twitter'],
];
*/
const arrayofArraysWithoutHeader = convertCSVToArray(data, {
header: false,
type: 'array',
separator: ';', // use the separator you use in your csv (e.g. '\t', ',', ';' ...)
});
/*
const arrayofObjectsWithoutHeader = [
{
number: 1,
first: 'Mark',
last: 'Otto',
handle: '@mdo',
},
{
number: 2,
first: 'Jacob',
last: 'Thornton',
handle: '@fat',
},
{
number: 3,
first: 'Larry',
last: 'the Bird',
handle: '@twitter',
},
];
*/
const arrayofObjectsWithoutHeader = convertCSVToArray(data, {
header: false,
separator: ';', // use the separator you use in your csv (e.g. '\t', ',', ';' ...)
});
MIT © Lukas Aichbauer
FAQs
Convert a csv formatted string to an array
The npm package convert-csv-to-array receives a total of 1,511 weekly downloads. As such, convert-csv-to-array popularity was classified as popular.
We found that convert-csv-to-array demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.