Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Using npm
npm install @ricb/csv
This project provides functionality to write and read CSV files, as well as parse and serialize CSV data.
","
as separator and "|"
as array separator when writing.See CsvOptions for more info
import { writeCsv, readCsv } from '@ricb/csv';
const data = [
{ id: 1, name: 'John Doe', born: new Date(), nicks: ['man', 'dude'] },
{ id: 2, name: 'Jane Doe', born: new Date('2000-01-01'), nicks: ['girl', 'woman'] }
];
const filePath = await writeCsv(data, 'test.csv');
const loadedData = await readCsv(filePath)
console.log(loadedData);
import { fromCsv, toCsv } from '@ricb/csv'
const text = `Id,Name,Born,Colors,Joined,KidsAge
1,"Doe, John",2000,red|blue,2021-01-01,5|7
2,"Doe, Jane",2001,green|yellow,2021-01-02,3|4
3,"Mouse,Mickey",2002,black|white,2021-01-03,1|2
4,"Mick "The man" Jagger",1943,purple|orange,2021-01-04,8|9`;
const data = await fromCsv(text, { separator: ',' });
const csvText = toCsv(data, { separator: '\t' });
const data2 = await fromCsv(csvText, { separator: '\t' });
console.log(data2);
CsvOptions
is a type that allows you to customize how CSV data is processed. Here are the properties it can have:
fields
: An array of strings specifying the order of the fields when writing CSV data. If not provided, the fields will be written in the order they appear in the data object.
separator
: A string that specifies the character used to separate fields in the CSV data. If not provided, a comma (",") is used by default.
arraySeparator
: A string that specifies the character used to separate array elements in the CSV data. If not provided, a pipe ("|") is used by default.
mapping
: An object that maps field names to their types. This is used when reading CSV data to convert string values to their appropriate types. If not provided, all values are treated as strings.
detectTypes
: A boolean that specifies whether to automatically detect and convert types when reading CSV data. If not provided, this is true
by default.
const options: CsvOptions = {
fields: ['id', 'name', 'born', 'nicks'],
separator: ',',
arraySeparator: '|',
mapping: { id: { type: 'number' }, born: { type: 'date' } },
detectTypes: true
};
const loadedData = await readCsv(filePath, options);
FAQs
Reads and writes data to and from flat files
The npm package @ricb/csv receives a total of 80 weekly downloads. As such, @ricb/csv popularity was classified as not popular.
We found that @ricb/csv demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.