Coder Social home page Coder Social logo

csv-parser's Introduction

csv-parser

This module contains functions for writing new .csv file or parsing existing .csv file.

Using

Firstly you should clone this repository in your application using git clone command.

git clone https://github.com/NikitaKemarskiy/csv-parser.git

Then you should require it in your application. This module is an object with two methods: "parseCSV" for parsing existing .csv file to array and "toCSV" for creating a value to write a new .csv file.

const csvParser = require('./csv-parser'); // Require csv-parser package
const fs = require('fs'); // Require file stream module to read / write .csv files

const filePath = 'cars.csv'; // Path to your .csv file 
const cars = [ // Array of arrays which contains table data to write it in .csv file
	[1997, 'Ford', 'E350', 'Hello, "Daydreamin"', 3000.00, true],
	[1999, 'Chevy', "Venture «Extended Edition»", "", 4900.00, false],
	[1996, 'Jeep', 'Grand Cherokee', "MUST SELL! air, moon roof, loaded", 4799.00, false]
];

// Writing to .csv file
const csv = csvParser.toCSV(cars);
fs.writeFile(filePath, csv, function(error) {
	if (error) {
		console.error(`Error: ${error.message}`);
	} else {
		console.log(`${filePath} was successfully written`);
	}
});

// Reading existing .csv file
fs.readFile(filePath, function(error, data) {
	if (error) {
		console.error(`Error: ${error.message}`);
	} else {
		const csv = csvParser.parseCSV(data);
		console.log(csv);
	}
});

csv-parser's People

Contributors

nikitakemarskiy avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.