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

simplecsv

v0.0.49

Published

Fast and compact CSV parser for parsing CSV with CSV to JSON support.

Downloads

93

Readme

SimpleCSV.js Logo

SimpleCSV.js is a fast and compact JavaScript CSV library for parsing csv strings, and parsing JSON table objects.

Features

  • In-the-Browser, For-The-Browser: Only 3 lines of code to parse CSV strings, and JSON tables.
  • Python csv compatible: Guaranteed to produce the same results as Python 2.7 csv parser.
  • JSON parser: Convert CSV to JSON, or JSON to CSV.
  • No dependancies: Tiny standalone .js file.

Downloads

Examples

Browser

In any web page:

<script src="http://simplecsvjs.com/dist/simplecsv.0.0.47.standalone.min.js"></script>
<script>
  var simplecsv = require('simplecsv');
  var csv = new simplecsv.csv();

  var parsedCsvdata = csv.parseString('Turing, 35, chess\nSamuel, 21, checkers');
</script>

Node.js

var simplecsv = require('simplecsv');
var csv = new simplecsv.csv();

var parsedCsvdata = csv.parseString('Turing, 35, chess\nSamuel, 21, checkers');

More Examples

CSV to JSON

var simplecsv = require('simplecsv');
var csv = new simplecsv.csv();

var jsonObj = csv.CSVToJSON('Planet Name, Color\nMars,red-orange\nUranus,light-blue',
                            { hasHeaders: true });
console.log(jsonObj);

output is:

[{"Planet Name":"Mars"," Color":"red-orange"},{"Planet Name":"Uranus"," Color":"light-blue"}]

JSON -> CSV

var simplecsv = require('simplecsv');
var csv = new simplecsv.csv();

var str  = csv.JSONToCSV('[{"Planet Name":"Mars"," Color":"red-orange"},' +
                         '{"Planet Name":"Uranus"," Color":"light-blue"}]');
console.log(str);

output is:

Planet Name, Color
Mars,red-orange
Uranus,light-blue

console.log() every cell

var simplecsv = require('simplecsv');
var csv = new simplecsv.csv();

var cdata = csv.parseString('Planet Name, Color\nMars,red-orange\nUranus,light-blue', { hasHeaders: true });
for (var i = 0; i < cdata.rowCount; i++) {
  for (var j = 0; j < cdata.columnCount; j++) {
    console.log(cdata.rows[i][j]);
  }
}

find errors

var simplecsv = require('simplecsv');
var csv = new simplecsv.csv();

var cdata = csv.parseString('Planet Name, Color\nMars\nred-orange, Uranus,light-blue', { hasHeaders: true });
console.log(csv.findErrors(cdata));

Quick Start

Install

Install with npm.

$ npm install simplecsv

Newline

SimpleCSV.js uses \n and \r\n for newline when parsing. Currently there is no support for Mac's \r for newline (i.e. universal mode in Python csv).

Support

For bug reports, feature requests and general questions, please feel free to email [email protected].

Development

Refer to development notes

Documentation

Library manual