npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-csvjsonlite

v1.1.4

Published

Lightweight CSV to JSON for Node.JS

Downloads

6

Readme

node-csvjsonlite Build Status npm version

###Lightweight CSV to JSON for Node.JS

Usage


    var csv  = require('node-csvjsonlite');

    var filename = './path/to/your.csv';
    // OR this can be a URL like
    // filename = 'http://sample.com/data.csv';
    // OR filename can be a string of CSV data
    //
    // Suppose your.csv is following:
    //
    // Date,Open,High,Low
    // 2015-03-27,2.58,2.65,2.53
    // 2015-03-26,2.73,2.74,2.57
    // 2015-03-25,2.64,2.73,2.61

    csv
        .convert(filename)
            // Detects whether filname is
            // a local file, URL, or string of data
        .then(function(successData){
            console.log('CSV in JSON', successData);
            // resolves to
            // [{ Date: 2015-03-27, Open: 2.58, High: 2.65, Low: 2.53 },
            //  { Date: 2015-03-26, Open: 2.73, High: 2.74, Low: 2.57 },
            //  { Date: 2015-03-25, Open: 2.64, High: 2.73, Low: 2.61 }]
        });

Or you can be specific

    var promiseFile = csv.convertFile(filename);
    var promiseURL  = csv.convertURL(fileURL);
    var promiseStr  = csv.convertString(stringData);

Get Started

npm install node-csvjsonlite
var csv = require('node-csvjsonlite');

Features

###Bluebird as promise

Bluebird is used as promise to keep it lightweight.

###Commas within double quotes


    var csv  = require('node-csvjsonlite');

    var filename = './path/to/your.csv';

    // where your.csv has the following data:
    // Date, Value
    // 2015-02-14,"2,2"
    // 2015-02-15,"4,3"
    // 2015-02-16,"1,2"
    // resolves to
    // [{ Date: 2015-02-14, Value: 2,2 },
    //  { Date: 2015-02-15, Value: 4,3 },
    //  { Date: 2015-02-16, Value: 1,2 }]

###CSV from online source


    var csv  = require('node-csvjsonlite');

    var filename = 'http://something.com';

where filename can be HTTP or HTTPS.

Note: If file does not exist, then it will reject the promise.

###Error Handling

Error will be resolved in the Promise rejection.


    var csv  = require('node-csvjsonlite');

    var badFilename = './path/to/invalid.csv';

    csv
        .convert(badFilename)
        .then(function(successData){
            console.log('This shouldn\'t show');
        }, function(errorReason){
            console.log(errorReason);
            // Error Reason is either a string ("File does not exist")
            // or an error object returned from require('fs').readFile
        });

Note that since it uses bluebird as promise, if the promise is rejected and there is no rejection handler, it will throw an error.