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

dom-csv.js

v1.0.0

Published

Simple javascript CSV library focused on the browser with **zero dependencies**.

Downloads

5

Readme

CSV.js

Simple, ultra light (10kb uncompressed) javascript CSV library for browser and node with zero dependencies.

Originally developed as part of ReclineJS but now fully standalone.

Usage

Grab the csv.js file and include it in your application.

Depends on jQuery or underscore.deferred (for deferred) in fetch (and jQuery if you need ajax). parse and serialize have zero dependencies.

fetch

A convenient way to load a CSV file from various different sources. fetch supports 3 options depending on the attribute provided on the info argument:

CSV.fetch({
    data: 'raw csv string'
    // or ...
    url: 'url to a csv file'
    // or ...
    file: an HTML 5 file object

    // optional options about structure of the CSV file
    // following the CSV Dialect Description Format 
    // https://frictionlessdata.io/specs/csv-dialect/
    dialect: {
      ...
    }
  }
).done(function(dataset) {
  // dataset object doc'd below
  console.log(dataset);
});

Some more detail on the argument object:

  • data is a string in CSV format. This is passed directly to the CSV parser
  • url: a url to an online CSV file that is ajax accessible (note this usually requires either local or on a server that is CORS enabled). The file is then loaded using jQuery.ajax and parsed using the CSV parser (NB: this requires jQuery) All options generates similar data and use the memory store outcome, that is they return something like:
  • file: is an HTML5 file object. This is opened and parsed with the CSV parser.
  • dialect: hash / dictionary following the same structure as for parse method below.

Returned dataset object looks like:

Raw parsing

var out = CSV.parse(csvString, dialect);

Converts a Comma Separated Values string into an array of arrays. Each line in the CSV becomes an array.

Empty fields are converted to nulls and non-quoted numbers are converted to integers or floats.

  • csvString: the csv string to parse

  • dialect: [optional] hash with keys as per the CSV dialect description format. It also supports the following additional keys:

    • skipInitialRows: [optional] integer number of rows to skip (default 0)

    For backwards compatability with earlier versions of the library the dialect also supports the following:

Serialize

Convert an Object or a simple array of arrays into a Comma Separated Values string.

var out = CSV.serialize(dataToSerialize, dialect);

Returns a string representing the array serialized as a CSV.

dataToSerialize is an Object or array of arrays to convert. Object structure must be as follows:

{
  fields: [ {id: .., ...}, {id: ..., 
  records: [ { record }, { record }, ... ]
  ... // more attributes we do not care about
}

Nulls are converted to empty fields and integers or floats are converted to non-quoted numbers.

You may optionally specify a label inside each field so that the serialized data will use it as the column heading instead of the id.


Other JS CSV Libs

  • http://www.uselesscode.org/javascript/csv/ - basic CSV parser on which this library was originally based
  • https://github.com/maxogden/browser-csv-stream - Pure browser version of node-csv from @maxogden via browserify
  • https://github.com/onyxfish/csvkit.js - pure JS CSV reader from @onyxfish (author of the "legendary" python csvkit)
  • https://github.com/mholt/PapaParse - fast CSV parser that can handle large files and malformed data

Node

  • https://github.com/wdavidw/node-csv - this is the Node CSV lib we use by preference
  • https://github.com/maxogden/binary-csv - new CSV lib from @maxogden with a focus on being very fast

Development

Requirements

  • webpack
  • jquery
npm install
npm install jquery
webpack-dev-server

Run tests

Requirements

  • karma
  • phantomjs
npm -g install karma karma-cli phantomjs-prebuilt
npm install
npm install jquery
npm test