This npm package is used by nodeJS developers for parsing CSV files into JSON objects, arrays numbers or strings. Recently added the callback feature to this package, you can pass a callback function in your code and see it implemented.
- Run
npm install csv-for-you
- Fork the git repository
https://github.com/Minka1902/csv-for-you.git
const csv = require('csv-for-you');
const parseOptions = {
arraySeparator: '|', // not required, default value is ';'
objectSeparator: '^', // not required, default value is ';'
lineAsArray: false, // not required, default value is 'true'
fileAsArray: true, // not required, default value is 'true'
returnAsString: ['name', 'ID'], // not required, default value is an empty array
innerCallbacks: true, // not required, default value is 'true
};
const addOptions = {
lineNumber: 0 // not required, default value is 0 (deletes first line)
};
const deleteOptions = {
rowNumber: 5, // required! default value is -1
rowsToDelete: 3 // not required, default value is 1
};
const editOptions = {
data: { name: "john smith", age: 77 }, // required! must be an object
lineNumber: 3 // required! must be an integer and bigger than 1
};
async function myFunction() {
const myCsvFileData = await csv.parse('C:\\path\\to\\my\\file.csv', parseOptions, { lineCallback: yourLineCallback, objectCallback: yourObjectCallback } );
// Use the data however you'd like
};
csv.addRow('C:\\path\\to\\my\\file.csv', { name: "john smith" }, addOptions );
csv.editRow('C:\\path\\to\\my\\file.csv', editOptions );
csv.deleteRow('C:\\path\\to\\other\\file.csv', deleteOptions);
This object contains the parse function options.
- arraySeparator - the Char that represents the separator between Array elements
- objectSeparator - the Char that represents the separator between Object elements
- lineAsArray - Boolean that represents rather a line should be represented as an Array or Object
- fileAsArray - Boolean that represents rather the file should be represented as an Array or Object
- returnAsString - Array of property names that should be returned as a string
- innerCallbacks - Boolean that represents rather value callbacks should be implemented if there is a callback for the line/file
- Parses strings in CSV
- Parses numbers in CSV
- Parses arrays - numbers, strings, arrays and objects
- Parses objects - numbers, strings, arrays and objects
- Add data with the
addRow
function - Delete data with the
deleteRow
function - Edit line with the
editRow
function - callbacks - you can pass a custom callback function for each line and type of value
- getHeaders function - returns an array of the file headers
- Properties - The first line of the file must be the properties of the objects
- Numbers - Any integer or float number
- Strings - Strings of any length
- Arrays - Must start with
[
and end with]
while the separator is not,
(arraySeparator
in the options object to change) - Objects - Must start with
{
and end with}
while the separator is not,
(objectSeparator
in the options object to change) - Values are separated by
,
- Parsing text to JSON
- Fetching data from servers using URL
- Reading file structure starting from a folder
- Creating a CSV file from JSON object
- Error notifier - Lets you know what is the problem
- Generating numeric data to CSV or JSON
- Generating lingual data to CSV or JSON
- Reading a specific value for example only the name property, or an array of properties
For issues or feature requests go to https://github.com/Minka1902/csv-for-you/issues and add a new one. In the title write Request/Issue and elaborate in the description.