simplecsv
Version:
Fast and compact CSV parser for parsing CSV with CSV to JSON support.
534 lines (183 loc) • 9.84 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Home</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Home</h1>
<h3> </h3>
<section>
<article><p><a href="/"><img src="http://simplecsvjs.com/simplecsv.png" alt="SimpleCSV.js Logo"></a></p>
<p>SimpleCSV.js is a fast and compact JavaScript CSV library for parsing csv strings, and parsing JSON table objects.</p>
<h2>Features</h2><ul>
<li><strong>In-the-Browser, For-The-Browser:</strong> Only 3 lines of code to parse CSV strings, and JSON tables.</li>
<li><strong>Python csv compatible:</strong> Guaranteed to produce the same results as Python 2.7 csv parser.</li>
<li><strong>JSON parser:</strong> Convert CSV to JSON, or JSON to CSV.</li>
<li><strong>No dependancies:</strong> Tiny standalone .js file.</li>
</ul>
<h2>Downloads</h2><ul>
<li><a href="http://simplecsvjs.com/dist/simplecsv.0.0.47.standalone.min.js">Version 0.0.47, minimized, 4.4K : http://simplecsvjs.com/dist/simplecsv.0.0.47.standalone.min.js</a></li>
<li><a href="http://simplecsvjs.com/dist/simplecsv.0.0.47.standalone.js">Version 0.0.47, un-minimized, 13K : http://simplecsvjs.com/dist/simplecsv.0.0.47.standalone.js</a></li>
</ul>
<h2>Examples</h2><h3>Browser</h3><p>In any web page:</p>
<pre class="prettyprint source lang-html"><code><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></code></pre><h3>Node.js</h3><pre class="prettyprint source lang-js"><code>var simplecsv = require('simplecsv');
var csv = new simplecsv.csv();
var parsedCsvdata = csv.parseString('Turing, 35, chess\nSamuel, 21, checkers');</code></pre><h2>More Examples</h2><h3>CSV to JSON</h3><pre class="prettyprint source lang-js"><code>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);</code></pre><p>output is:</p>
<pre class="prettyprint source lang-json"><code>[{"Planet Name":"Mars"," Color":"red-orange"},{"Planet Name":"Uranus"," Color":"light-blue"}]</code></pre><h3>JSON -> CSV</h3><pre class="prettyprint source lang-js"><code>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);</code></pre><p>output is:</p>
<pre class="prettyprint source"><code>Planet Name, Color
Mars,red-orange
Uranus,light-blue</code></pre><h3>console.log() every cell</h3><pre class="prettyprint source lang-js"><code>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]);
}
}</code></pre><h3>find errors</h3><pre class="prettyprint source lang-js"><code>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));</code></pre><h1>Quick Start</h1><h1>Install</h1><p>Install with <a href="https://www.npmjs.com/">npm</a>.</p>
<pre class="prettyprint source"><code>$ npm install simplecsv</code></pre><h1>Newline</h1><p>SimpleCSV.js uses <code>\n</code> and <code>\r\n</code> for newline when parsing. Currently there is no support for Mac's <code>\r</code> for newline (i.e. universal mode in Python csv).</p>
<h1>Support</h1><p>For bug reports, feature requests and general questions, please feel free to email baris@onehundredyearsofcode.com.</p>
<h1>Development</h1><p><a href="https://github.com/byuksel/simplecsv/blob/master/CONTRIBUTING.md">Refer to development notes</a></p>
<h1>Documentation</h1><p><a href="https://cdn.rawgit.com/byuksel/simplecsv/master/docs/index.html">Library manual</a></p></article>
</section>
<section>
<header>
<h2>
lib/csv.js
</h2>
</header>
<article>
<div class="container-overview">
<div class="description"><p>Module that exports the csv() class. Should be used
with new() to create new parser classes.</p></div>
<dl class="details">
<dt class="tag-author">Author:</dt>
<dd class="tag-author">
<ul>
<li><a href="mailto:baris@onehundredyearsofcode.com">Baris Yuksel</a></li>
</ul>
</dd>
<dt class="tag-copyright">Copyright:</dt>
<dd class="tag-copyright"><ul class="dummy"><li>Copyright (c) 2015 All Rights Reserved.</li></ul></dd>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_csv.js.html">lib/csv.js</a>, <a href="lib_csv.js.html#line1">line 1</a>
</li></ul></dd>
</dl>
</div>
</article>
</section>
<section>
<header>
<h2>
lib/csvdata.js
</h2>
</header>
<article>
<div class="container-overview">
<div class="description"><p>Module that export csvdata, a datastructure for csv data.</p></div>
<dl class="details">
<dt class="tag-author">Author:</dt>
<dd class="tag-author">
<ul>
<li><a href="mailto:baris@onehundredyearsofcode.com">Baris Yuksel</a></li>
</ul>
</dd>
<dt class="tag-copyright">Copyright:</dt>
<dd class="tag-copyright"><ul class="dummy"><li>Copyright (c) 2015 All Rights Reserved.</li></ul></dd>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_csvdata.js.html">lib/csvdata.js</a>, <a href="lib_csvdata.js.html#line1">line 1</a>
</li></ul></dd>
</dl>
</div>
</article>
</section>
<section>
<header>
<h2>
lib/private.js
</h2>
</header>
<article>
<div class="container-overview">
<div class="description"><p>Module which exports private object with static methods.</p></div>
<dl class="details">
<dt class="tag-author">Author:</dt>
<dd class="tag-author">
<ul>
<li><a href="mailto:baris@onehundredyearsofcode.com">Baris Yuksel</a></li>
</ul>
</dd>
<dt class="tag-copyright">Copyright:</dt>
<dd class="tag-copyright"><ul class="dummy"><li>Copyright (c) 2015 All Rights Reserved.</li></ul></dd>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_private.js.html">lib/private.js</a>, <a href="lib_private.js.html#line1">line 1</a>
</li></ul></dd>
</dl>
</div>
</article>
</section>
<section>
<header>
<h2>
test/csvtest.js
</h2>
</header>
<article>
<div class="container-overview">
<div class="description"><p>Simple CSV library unittests</p></div>
<dl class="details">
<dt class="tag-author">Author:</dt>
<dd class="tag-author">
<ul>
<li><a href="mailto:baris@onehundredyearsofcode.com">Baris Yuksel</a></li>
</ul>
</dd>
<dt class="tag-copyright">Copyright:</dt>
<dd class="tag-copyright"><ul class="dummy"><li>Copyright (c) 2015 All Rights Reserved.</li></ul></dd>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="test_csvtest.js.html">test/csvtest.js</a>, <a href="test_csvtest.js.html#line1">line 1</a>
</li></ul></dd>
</dl>
</div>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-simplecsv.html">simplecsv</a></li></ul><h3>Classes</h3><ul><li><a href="csv.html">csv</a></li><li><a href="csvdata.html">csvdata</a></li><li><a href="private.html">private</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a> on Fri Jul 17 2015 02:09:00 GMT-0400 (EDT)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>