GithubHelp home page GithubHelp logo

harendranathvegi9 / csv-array Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sguha-work/csv-array

0.0 2.0 0.0 4.15 MB

Lightweight Intelligent CSV-parser for node-js

License: MIT License

JavaScript 100.00%

csv-array's Introduction

#csv-array

Simple. lighweight, intelligent CSV-parser for nodeJS

Dependencies

This package got only one dependencies of "line-by-line".

Change log

  • Dramatic improvement in speed.. Please forget version 0.0.1x

Usage Guide

Installing

The installation is just a command

 npm install csv-array

After installing the package you can use the "parseCSV" method as follows

 parseCSV("CSV-file-name.csv", callBack, considerFirstRowAsHeading)
   /*
      Where callBack is the method which have the output array as argument, and you can do 
      anything you like inside the function with the array

      "considerFirstRowAsHeading" is a configuration variable which holds "true" value 
      by default. If it is true or nothing then the first row of the csv data will be considered 
      as heading and the out put data will use the first row's content as attribute names.
      If it is "false" then all of the rows of the file will be returned as array.

      See example below.
   */

Example

test.csv file contains

 Question Statement,Option 1,Option 2,Option 3,Option 4,Option 5,Answer,Deficulty,Category
this is a test question answer it?,answer 1,answer 2,answer3,answer 4,,answer 2,3,test
this is another test question answer it?,"answer1,answer2","answer2,answer3","answer4,answer5","answer5,answer6","answer7,answer8","answer1,answer2",2,test
 var csv = require('csv-array');
 csv.parseCSV("test.csv", function(data){
   console.log(JSON.stringify(data));
 });

Output

[  
   {  
      "Question Statement":"this is a test question answer it?",
      "Option 1":"answer 1",
      "Option 2":"answer 2",
      "Option 3":"answer3",
      "Option 4":"answer 4",
      "Option 5":"",
      "Answer":"answer 2",
      "Deficulty":"3",
      "Category":"test"
   },
   {  
      "Question Statement":"this is another test question answer it?",
      "Option 1":"answer1,answer2",
      "Option 2":"answer2,answer3",
      "Option 3":"answer4,answer5",
      "Option 4":"answer5,answer6",
      "Option 5":"answer7,answer8",
      "Answer":"answer1,answer2",
      "Deficulty":"2",
      "Category":"test"
   }
]
 var csv = require('csv-array');
 csv.parseCSV("test.csv", function(data){
   console.log(JSON.stringify(data));
 }, false);

Output

[  
   [  
      "Question Statement",
      "Option 1",
      "Option 2",
      "Option 3",
      "Option 4",
      "Option 5",
      "Answer",
      "Deficulty",
      "Category"
   ],
   [  
      "this is a test question answer it?",
      "answer 1",
      "answer 2",
      "answer3",
      "answer 4",
      "",
      "answer 2",
      "3",
      "test"
   ],
   [  
      "this is another test question answer it?",
      "answer1,answer2",
      "answer2,answer3",
      "answer4,answer5",
      "answer5,answer6",
      "answer7,answer8",
      "answer1,answer2",
      "2",
      "test"
   ]
]
 var csv = require('csv-array');
 csv.parseCSV("test.csv", function(data){
   console.log(JSON.stringify(data));
 }, true);
 /*
   The output will be as same as
   var csv = require('csv-array');
    csv.parseCSV("test.csv", function(data){
      console.log(JSON.stringify(data));
    });
 */

Output

[  
   {  
      "Question Statement":"this is a test question answer it?",
      "Option 1":"answer 1",
      "Option 2":"answer 2",
      "Option 3":"answer3",
      "Option 4":"answer 4",
      "Option 5":"",
      "Answer":"answer 2",
      "Deficulty":"3",
      "Category":"test"
   },
   {  
      "Question Statement":"this is another test question answer it?",
      "Option 1":"answer1,answer2",
      "Option 2":"answer2,answer3",
      "Option 3":"answer4,answer5",
      "Option 4":"answer5,answer6",
      "Option 5":"answer7,answer8",
      "Answer":"answer1,answer2",
      "Deficulty":"2",
      "Category":"test"
   }
]

If any issue found feel free to contact me at [email protected]

csv-array's People

Contributors

pdehaan avatar sguha-work avatar

Watchers

 avatar  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.