Skip to content

Commit

Permalink
Fixed code indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt committed Jan 2, 2015
1 parent 9cef46e commit 281f591
Showing 1 changed file with 79 additions and 79 deletions.
158 changes: 79 additions & 79 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,25 @@ <h2>The powerful, in-browser CSV parser for big boys and girls</h2>

<div id="title-code">
<pre><code class="language-javascript">// Parse CSV string
var data = Papa.parse(csv);

// Convert back to CSV
var csv = Papa.unparse(data);

// Parse local CSV file
Papa.parse(file, {
complete: function(results) {
console.log("Finished:", results.data);
}
});

// Stream big file in worker thread
Papa.parse(bigFile, {
worker: true,
step: function(results) {
console.log("Row:", results.data);
}
});</code></pre>
var data = Papa.parse(csv);

// Convert back to CSV
var csv = Papa.unparse(data);

// Parse local CSV file
Papa.parse(file, {
complete: function(results) {
console.log("Finished:", results.data);
}
});

// Stream big file in worker thread
Papa.parse(bigFile, {
worker: true,
step: function(results) {
console.log("Row:", results.data);
}
});</code></pre>
</div>
</div>
</div>
Expand Down Expand Up @@ -212,13 +212,13 @@ <h5>"Isn't parsing CSV just <code>String.split(',')</code>?"</h5>
<p>Heavens, no. Papa does it right. Just pass in the CSV string with an optional <a href="/docs#config">configuration</a>.</p>

<pre><code class="language-javascript">var results = Papa.parse(csvString, <a href="/docs#config">config</a>);
/*
results = {
data: [ ... ], // parsed data
errors: [ ... ], // errors encountered
meta: { ... } // extra parse info
}
*/</code></pre>
/*
results = {
data: [ ... ], // parsed data
errors: [ ... ], // errors encountered
meta: { ... } // extra parse info
}
*/</code></pre>
</div>
</div>
</section>
Expand All @@ -234,8 +234,8 @@ <h5>"But I don't know the delimiter..."</h5>
<p>That's okay. Papa will scan the first few rows to find the right delimiter.</p>

<pre><code class="language-javascript">var results = Papa.parse(csvString);
console.log(results.meta.delimiter);
// "\t"</code></pre>
console.log(results.meta.delimiter);
// "\t"</code></pre>
</div>
</div>
</section>
Expand All @@ -251,10 +251,10 @@ <h5>"Great, but I have a <i>file</i> to parse."</h5>
<p>Then give Papa a <a href="https://developer.mozilla.org/en-US/docs/Web/API/File">File</a> instead of a string. Since file parsing is asynchronous, don't forget a callback.</p>

<pre><code class="language-javascript">var results = Papa.parse(fileInput.files[0], {
complete: function(results) {
console.log(results);
}
});</code></pre>
complete: function(results) {
console.log(results);
}
});</code></pre>
</div>
</div>
</section>
Expand All @@ -272,11 +272,11 @@ <h5>"No&mdash;I mean, the file isn't on my computer."</h5>
<p>Oh, well then just pass in the URL and&mdash;of course&mdash;a callback.</p>

<pre><code class="language-javascript">Papa.parse("http://example.com/file.csv", {
download: true,
complete: function(results) {
console.log(results);
}
});</code></pre>
download: true,
complete: function(results) {
console.log(results);
}
});</code></pre>
</div>
</div>
</section>
Expand All @@ -296,14 +296,14 @@ <h5>"Did I mention the file is huge?"</h5>
<p>That's what streaming is for. Specify a step callback to receive the results row-by-row. This way, you won't load the whole file into memory and crash the browser.</p>

<pre><code class="language-javascript">Papa.parse("http://example.com/big.csv", {
download: true,
step: function(row) {
console.log("Row:", row.data);
},
complete: function() {
console.log("All done!");
}
});</code></pre>
download: true,
step: function(row) {
console.log("Row:", row.data);
},
complete: function() {
console.log("All done!");
}
});</code></pre>
</div>
</div>
</section>
Expand All @@ -319,14 +319,14 @@ <h5>"Lovely. Now my web page locked up."</h5>
<p>That happens when a long-running script is executing in the same thread as the page. Use a <a href="https://developer.mozilla.org/en-US/docs/Web/API/Worker">Worker</a> thread by specifying <code>worker: true</code>. It may take slightly longer, but your page will stay reactive.</p>

<pre><code class="language-javascript">Papa.parse(bigFile, {
worker: true,
step: function(row) {
console.log("Row:", row.data);
},
complete: function() {
console.log("All done!");
}
});</code></pre>
worker: true,
step: function(row) {
console.log("Row:", row.data);
},
complete: function() {
console.log("All done!");
}
});</code></pre>
</div>
</div>
</section>
Expand All @@ -343,9 +343,9 @@ <h5>"Great! Now I want data keyed by field name."</h5>
<p>If you tell Papa there is a header row, each row will be organized by field name instead of index.</p>

<pre><code class="language-javascript">// Key data by field name instead of index/position
var results = Papa.parse(csv, {
header: true
});</code></pre>
var results = Papa.parse(csv, {
header: true
});</code></pre>
</div>
</div>
</section>
Expand All @@ -362,9 +362,9 @@ <h5>"Hey, these numbers are parsed as strings."</h5>
<p><i>Everything</i> is parsed as strings. If you want numbers and booleans, you can enable dynamic typing to do the conversion for you.</p>

<pre><code class="language-javascript">// Converts numeric/boolean data
var results = Papa.parse(csv, {
dynamicTyping: true
});</code></pre>
var results = Papa.parse(csv, {
dynamicTyping: true
});</code></pre>
</div>
</div>
</section>
Expand All @@ -383,10 +383,10 @@ <h5>"I forgot to mention: my CSV files have comments in them."</h5>
<p>Okay, first off: that's really weird. But fortunately, you can skip those lines... just specify the comment string.</p>

<pre><code class="language-javascript">// Mostly found in academia, some CSV files
// may have commented lines in them
var results = Papa.parse(csv, {
comments: "#"
});</code></pre>
// may have commented lines in them
var results = Papa.parse(csv, {
comments: "#"
});</code></pre>
</div>
</div>
</section>
Expand All @@ -404,12 +404,12 @@ <h5>"Aw, shoot. Errors."</h5>
<p>Papa handles errors pretty well. The <a href="http://tools.ietf.org/html/rfc4180">CSV standard</a> is somewhat <strike>loose</strike> ambiguous, so Papa is designed for edge cases. For example, mismatched fields won't break parsing.</p>

<pre><code class="language-javascript">// Example error:
{
type: "FieldMismatch",
code: "TooManyFields",
message: "Expected 3 fields, but parsed 4",
row: 1
}</code></pre>
{
type: "FieldMismatch",
code: "TooManyFields",
message: "Expected 3 fields, but parsed 4",
row: 1
}</code></pre>
</div>
</div>
</section>
Expand All @@ -426,15 +426,15 @@ <h5>"Can I use Papa with jQuery?"</h5>
<p>Sure, but it's not required. You can use jQuery to select file input elements and then parse their files. Papa exposes its file parsing API as a jQuery plugin only when jQuery is defined. Papa Parse has <b>no dependencies</b>.</p>

<pre><code class="language-javascript">$("input[type=file]").parse({
config: {
complete: function(results, file) {
console.log("This file done:", file, results);
}
},
complete: function() {
console.log("All files done!");
config: {
complete: function(results, file) {
console.log("This file done:", file, results);
}
});</code></pre>
},
complete: function() {
console.log("All files done!");
}
});</code></pre>
</div>
</div>
</section>
Expand All @@ -451,8 +451,8 @@ <h5>"Last thing: what about converting JSON to CSV?"</h5>
<p>Call <code>unparse()</code> instead of <code>parse()</code>, passing in your array of arrays or array of objects. Papa will figure it out.</p>

<pre><code class="language-javascript">// Output is a properly-formatted CSV string.
// See <a href="/docs#json-to-csv">the docs</a> for more configurability.
var csv = Papa.unparse(yourData);</code></pre>
// See <a href="/docs#json-to-csv">the docs</a> for more configurability.
var csv = Papa.unparse(yourData);</code></pre>
</div>
</div>
</section>
Expand Down

0 comments on commit 281f591

Please sign in to comment.