@ -26,7 +26,7 @@ can be installed with the following command:
@@ -26,7 +26,7 @@ can be installed with the following command:
npm install papaparse
If you don't want to use npm, [papaparse.min.js](https://github.com/mholt/PapaParse/blob/master/papaparse.min.js) can be downloaded to your project source.
If you don't want to use npm, [papaparse.min.js](https://unpkg.com/papaparse@latest/papaparse.min.js) can be downloaded to your project source.
Homepage & Demo
@ -39,9 +39,8 @@ To learn how to use Papa Parse:
@@ -39,9 +39,8 @@ To learn how to use Papa Parse:
- [Documentation](http://papaparse.com/docs)
The website is hosted on on [Github Pages](https://pages.github.com/). If
you want to contribute just clone the gh-branch of this repository and
open a pull request.
The website is hosted on on [Github Pages](https://pages.github.com/). It's content is also inclued on the docs folder of this repository. If
you want to contribute on it just clone the master of this repository and open a pull request.
to alter the flow of parsing. Actions can be <code>"abort"</code> to skip this and all other files in the queue, <code>"skip"</code> to skip just this file, or <code>"continue"</code> to carry on (equivalent to returning nothing). <code>reason</code> can be a reason for aborting. <code>config</code> can be a modified <ahref="#config">configuration</a> for parsing just this file.</li>
to alter the flow of parsing. Actions can be <code>"abort"</code> to skip this and all other files in the queue, <code>"skip"</code> to skip just this file, or <code>"continue"</code> to carry on (equivalent to returning nothing). <code>reason</code> can be a reason for aborting. <code>config</code> can be a modified <ahref="#config">configuration</a> for parsing just this file.
</li>
<li>The <code>complete</code> callback shown here is executed after <i>all</i> files are finished and does not receive any data. Use the complete callback in <ahref="#config">config</a> for per-file results.</li>
<code>config</code> is an optional <ahref="#unparse-config-default">config object</a>
</li>
</ul>
</div>
<divclass="clear"></div>
<divclass="grid-100">
<h5id="unparse-config-default">Default Unparse Config with all options</h5>
</div>
<divclass="prefix-25 grid-50 suffix-25">
<pre><codeclass="language-javascript">
{
quotes: false,
quotes: false, //or array of booleans
quoteChar: '"',
escapeChar: '"',
delimiter: ",",
header: true,
newline: "\r\n"
}</code></pre>
Set <code>quotes</code> to <code>true</code> to always enclose each field in quotes, or an array of true/false values correlating to specific to columns to force-quote. The character used to quote can be customized using <code>quoteChar</code>. The character used to escape the <code>quoteChar</code> within a field can be customized using <code>escapeChar</code>. The <code>delimiter</code> can be any valid delimiting character. The <code>newline</code> character(s) may also be customized. Setting <code>header</code> to <code>false</code> will omit the header row.
</li>
</ul>
newline: "\r\n",
skipEmptyLines: false, //or 'greedy',
columns: null //or array of strings
}
</code></pre>
</div>
<divclass="clear"></div>
<divclass="grid-100">
<h5>Unparse Config Options</h5>
</div>
<divclass="grid-100"style="overflow-x: auto;">
<table>
<tr>
<thstyle="width: 20%;">Option</th>
<thstyle="width: 80%;">Explanation</th>
</tr>
<tr>
<td>
<code>quotes</code>
</td>
<td>
If <code>true</code>, forces all fields to be enclosed in quotes. If an array of <code>true/false</code> values, specifies which fields should be force-quoted (first boolean is for the first column, second boolean for the second column, ...).
</td>
</tr>
<tr>
<td><code>quoteChar</code></td>
<td>
The character used to quote fields.
</td>
</tr>
<tr>
<td><code>escapeChar</code></td>
<td>
The character used to escape <code>quoteChar</code> inside field values.
</td>
</tr>
<tr>
<td>
<code>delimiter</code>
</td>
<td>
The delimiting character. It must not be found in <ahref="#readonly">Papa.BAD_DELIMITERS</a>.
</td>
</tr>
<tr>
<td>
<code>header</code>
</td>
<td>
If <code>false</code>, will omit the header row. If <code>data</code> is an array of arrays this option is ignored. If <code>data</code> is an array of objects the keys of the first object are the header row. If <code>data</code> is an object with the keys <code>fields</code> and <code>data</code> the <code>fields</code> are the header row.
</td>
</tr>
<tr>
<td>
<code>newline</code>
</td>
<td>
The newline sequence. Must be one of <code>"\r"</code>, <code>"\n"</code>, or <code>"\r\n"</code>.
</td>
</tr>
<tr>
<td>
<code>skipEmptyLines</code>
</td>
<td>
If <code>true</code>, lines that are completely empty (those which evaluate to an empty string) will be skipped. If set to <code>'greedy'</code>, lines that don't have any content (those which have only whitespace after parsing) will also be skipped.
</td>
</tr>
<tr>
<td>
<code>columns</code>
</td>
<td>
If <code>data</code> is an array of objects this option can be used to manually specify the keys (columns) you expect in the objects. If not set the keys of the first objects are used as column.
</td>
</tr>
</table>
</div>
<divclass="clear"></div>
@ -289,8 +374,8 @@ var csv = Papa.unparse([
@@ -289,8 +374,8 @@ var csv = Papa.unparse([
<divclass="grid-33">
<pre><codeclass="language-javascript">// Specifying fields and data explicitly
var csv = Papa.unparse({
fields: ["Column 1", "Column 2"],
data: [
"fields": ["Column 1", "Column 2"],
"data": [
["foo", "bar"],
["abc", "def"]
]
@ -350,12 +435,14 @@ var csv = Papa.unparse({
@@ -350,12 +435,14 @@ var csv = Papa.unparse({
@ -375,7 +462,7 @@ var csv = Papa.unparse({
@@ -375,7 +462,7 @@ var csv = Papa.unparse({
<code>delimiter</code>
</td>
<td>
The delimiting character. Leave blank to auto-detect from a list of most common delimiters. It can be a string or a function. If string, it must be one of length 1. If a function, it must accept the input as first parameter and it must return a string which will be used as delimiter. In both cases it cannot be found in <ahref="#readonly">Papa.BAD_DELIMITERS</a>.
The delimiting character. Leave blank to auto-detect from a list of most common delimiters, or any values passed in through <code>delimitersToGuess</code>. It can be a string or a function. If string, it must be one of length 1. If a function, it must accept the input as first parameter and it must return a string which will be used as delimiter. In both cases it cannot be found in <ahref="#readonly">Papa.BAD_DELIMITERS</a>.
</td>
</tr>
<tr>
@ -415,7 +502,8 @@ var csv = Papa.unparse({
@@ -415,7 +502,8 @@ var csv = Papa.unparse({
<code>transformHeader</code>
</td>
<td>
A function to apply on each header. Requires <code>header</code> to be <code>true</code>. The function receives the header as its first argument.
A function to apply on each header. Requires <code>header</code> to be <code>true</code>. The function receives the header as its first argument.<br>
Only available starting with version 5.0.
</td>
</tr>
<tr>
@ -431,7 +519,7 @@ var csv = Papa.unparse({
@@ -431,7 +519,7 @@ var csv = Papa.unparse({
<code>preview</code>
</td>
<td>
If > 0, only that many rows will be parsed.
If > 0, only that many rows will be parsed.
</td>
</tr>
<tr>
@ -500,6 +588,19 @@ var csv = Papa.unparse({
@@ -500,6 +588,19 @@ var csv = Papa.unparse({
If true, this indicates that the string you passed as the first argument to <code>parse()</code> is actually a URL from which to download a file and parse its contents.
</td>
</tr>
<tr>
<td>
<code>downloadRequestHeaders</code>
</td>
<td>
If defined, should be an object that describes the headers, example:
@ -548,6 +649,14 @@ var csv = Papa.unparse({
@@ -548,6 +649,14 @@ var csv = Papa.unparse({
A function to apply on each value. The function receives the value as its first argument and the column number or header name when enabled as its second argument. The return value of the function will replace the value it received. The transform function is applied before dynamicTyping.
</td>
</tr>
<tr>
<td>
<code>delimitersToGuess</code>
</td>
<td>
An array of delimiters to guess from if the <code>delimiter</code> option is not set.
description:"created a simple regression test for Papa Parse.",
@ -78,5 +78,11 @@ var peopleLovePapa = [
@@ -78,5 +78,11 @@ var peopleLovePapa = [
name:"Novel.js",
description:"is a text adventure framework that uses Papa Parse to enable user-friendly translations.",
quote:"Papa saves countless hours of work and makes reading large CSV files so easy!"
},
{
link:"https://mailcheck.co",
name:"Mailcheck.co",
description:"Mailcheck is email validation service. All emails usually stored in CSV's. We use Papa Parse to process data from our customers in browser",
quote:"Papa Parser allowed our customers to preview and process csv's in browser, without uploading them to server. It saves lots of time and space :)"
notes:"Must parse correctly when single quote is specified as a quote character",
@ -1722,6 +1732,25 @@ var UNPARSE_TESTS = [
@@ -1722,6 +1732,25 @@ var UNPARSE_TESTS = [
input:[{a:null,b:' '},{},{a:'1',b:'2'}],
config:{skipEmptyLines:'greedy',header:true},
expected:'a,b\r\n1,2'
},
{
description:"Column option used to manually specify keys",
notes:"Should not throw any error when attempting to serialize key not present in object. Columns are different than keys of the first object. When an object is missing a key then the serialized value should be an empty string.",