simplecsv
Version:
Fast and compact CSV parser for parsing CSV with CSV to JSON support.
1,557 lines (460 loc) • 18.1 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: csv</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">Class: csv</h1>
<section>
<header>
<h2>
csv
</h2>
</header>
<article>
<div class="container-overview">
<h4 class="name" id="csv"><span class="type-signature"></span>new csv<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
<p>Creates a new csv parser.</p>
</div>
<dl class="details">
<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#line17">line 17</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="csvdataToJSON"><span class="type-signature"></span>csvdataToJSON<span class="signature">(input)</span><span class="type-signature"> → {string}</span></h4>
<div class="description">
<p>Produces the JSON of the csvdata.
Uses JSON table schema: <a href="http://dataprotocols.org/json-table-schema/">http://dataprotocols.org/json-table-schema/</a></p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>input</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>a csvdata object.</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<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#line113">line 113</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>JSON represantion of the csvdata object.</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">string</span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>// Given csvdata of:
{ column_names: { "magician", "born"},
rows: { { "houdini", 1874 },
{ "copperfield", 1956} }
}
csvdataToJSON() // will produce:
[ { "magician":"houdini",
"born": 1874 },
{ "magician":"copperfield",
"born":1956 } ]</code></pre>
<h4 class="name" id="csvdataToString"><span class="type-signature"></span>csvdataToString<span class="signature">(input, argdic)</span><span class="type-signature"> → {string}</span></h4>
<div class="description">
<p>Produces simple string output of csvdata.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>input</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>a csvdata object.</p></td>
</tr>
<tr>
<td class="name"><code>argdic</code></td>
<td class="type">
<span class="param-type">dictionary</span>
</td>
<td class="description last"><p>arguments for creating the csv string.</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<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#line66">line 66</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>csv string corresponding to the csvdata object.</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">string</span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>// Given csvdata of:
{ column_names: { "magician", "born"},
rows: { { "houdini", 1874 },
{ "copperfield", 1956} }
}
csvdataToString() // will produce
"magician, born\r\nhoudini, 1874\r\ncopperfield, 1956\r\n"</code></pre>
<h4 class="name" id="CSVToJSON"><span class="type-signature"></span>CSVToJSON<span class="signature">(input, argdic)</span><span class="type-signature"> → {string}</span></h4>
<div class="description">
<p>Converts CSV string to JSON.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>input</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>csv string</p></td>
</tr>
<tr>
<td class="name"><code>argdic</code></td>
<td class="type">
<span class="param-type">dictionary</span>
</td>
<td class="description last"><p>arguments for parsing the csv string</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<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#line33">line 33</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>JSON represantion of the csv string.</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">string</span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>CSVToJSON("magician, born\r\nhoudini, 1874\r\ncopperfield, 1956\r\n",
{hasHeaders: true});
// outputs:
[ { "magician":"houdini",
"born": 1874 },
{ "magician":"copperfield",
"born":1956 } ]</code></pre>
<h4 class="name" id="findErrors"><span class="type-signature"></span>findErrors<span class="signature">(input)</span><span class="type-signature"> → {Array.<string>}</span></h4>
<div class="description">
<p>Find errors.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>input</code></td>
<td class="type">
<span class="param-type"><a href="csvdata.html">csvdata</a></span>
</td>
<td class="description last"><p>input a csvdata object.</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<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#line252">line 252</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>The errors in the csvdata object.</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Array.<string></span>
</dd>
</dl>
<h4 class="name" id="JSONToCSV"><span class="type-signature"></span>JSONToCSV<span class="signature">(input, argdic)</span><span class="type-signature"> → {string}</span></h4>
<div class="description">
<p>Converts JSON to CSV string.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>input</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>JSON table string</p></td>
</tr>
<tr>
<td class="name"><code>argdic</code></td>
<td class="type">
<span class="param-type">dictionary</span>
</td>
<td class="description last"><p>arguments for creating the csv string.</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<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#line48">line 48</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>csv string corresponding to the JSON input.</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">string</span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>JSONToCSV( [ { "magician":"houdini", "born": 1874 },
{ "magician":"copperfield", "born":1956 } ]);
// outputs:
"magician, born\r\nhoudini, 1874\r\ncopperfield, 1956\r\n",</code></pre>
<h4 class="name" id="JSONToCsvdata"><span class="type-signature"></span>JSONToCsvdata<span class="signature">(jsonStr)</span><span class="type-signature"> → {<a href="csvdata.html">csvdata</a>}</span></h4>
<div class="description">
<p>Produces the csvdata of table formatted JSON
Uses JSON table schema: <a href="http://dataprotocols.org/json-table-schema/">http://dataprotocols.org/json-table-schema/</a></p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>jsonStr</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>JSON table.</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<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#line159">line 159</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>the csvdata object representing the JSON input.</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="csvdata.html">csvdata</a></span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>// Given JSON of:
{ "magician":"houdini",
"born": 1874 },
{ "magician":"copperfield",
"born":1956 }
// will produce
{ column_names: { "magician", "born"},
rows: { { "houdini", 1874 },
{ "copperfield", 1956} }
}</code></pre>
<h4 class="name" id="makeCsvdataFromObj"><span class="type-signature"></span>makeCsvdataFromObj<span class="signature">(obj)</span><span class="type-signature"> → {<a href="csvdata.html">csvdata</a>}</span></h4>
<div class="description">
<p>Can take an object and if the object has the same properties
as csvdata, it creates a csvdata from those properties by deep copying.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>obj</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>obj Any JS object with csvdata like properties.</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<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#line225">line 225</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>a new csvdata object deep copied from obj.</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="csvdata.html">csvdata</a></span>
</dd>
</dl>
<h4 class="name" id="parseString"><span class="type-signature"></span>parseString<span class="signature">(input, argdic)</span><span class="type-signature"> → {<a href="csvdata.html">csvdata</a>}</span></h4>
<div class="description">
<p>Produces the csvdata of csv string.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>input</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>csv string</p></td>
</tr>
<tr>
<td class="name"><code>argdic</code></td>
<td class="type">
<span class="param-type">dictionary</span>
</td>
<td class="description last"><p>arguments for parsing the csv string</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<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#line199">line 199</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>the csvdata object representing the csv string.</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="csvdata.html">csvdata</a></span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>parseString("magician, born\r\nhoudini, 1874\r\ncopperfield, 1956\r\n",
{hasHeaders: true});
// will produce
{ column_names: { "magician", "born"},
rows: { { "houdini", 1874 },
{ "copperfield", 1956} }
}</code></pre>
</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>