Browse Source

Like this????

I hope this is what you meant.
pull/431/head
lunatixcoder 7 years ago
parent
commit
ac3b4532be
  1. 19
      Gruntfile.js
  2. 20
      LICENSE
  3. 57
      README.md
  4. 40
      bower.json
  5. 60
      package.json
  6. 7
      papaparse.min.js
  7. 1045
      player/player.css
  8. 78
      player/player.html
  9. 178
      player/player.js
  10. 8
      tests/long-sample.csv
  11. 64
      tests/node-tests.js
  12. 2
      tests/sample.csv
  13. 1735
      tests/test-cases.js
  14. 19
      tests/test.js
  15. 29
      tests/tests.html

19
Gruntfile.js

@ -1,19 +0,0 @@ @@ -1,19 +0,0 @@
module.exports = function(grunt) {
grunt.initConfig({
uglify: {
options: {
preserveComments: 'some',
},
min: {
files: {
'papaparse.min.js': ['papaparse.js']
},
},
},
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.registerTask('build', ['uglify']);
grunt.registerTask('default', ['uglify']);
}

20
LICENSE

@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
The MIT License (MIT)
Copyright (c) 2015 Matthew Holt
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

57
README.md

@ -1,57 +0,0 @@ @@ -1,57 +0,0 @@
Parse CSV with JavaScript
========================================
Papa Parse is the [fastest](http://jsperf.com/javascript-csv-parsers/4) in-browser CSV (or delimited text) parser for JavaScript. It is reliable and correct according to [RFC 4180](https://tools.ietf.org/html/rfc4180), and it comes with these features:
- Easy to use
- Parse CSV files directly (local or over the network)
- Fast mode ([is really fast](http://jsperf.com/javascript-csv-parsers/3))
- Stream large files (even via HTTP)
- Reverse parsing (converts JSON to CSV)
- Auto-detect delimiter
- Worker threads to keep your web page reactive
- Header row support
- Pause, resume, abort
- Can convert numbers and booleans to their types
- Optional jQuery integration to get files from `<input type="file">` elements
- One of the only parsers that correctly handles line-breaks and quotations
Papa Parse has **no dependencies** - not even jQuery.
Homepage & Demo
----------------
- [Homepage](http://papaparse.com)
- [Demo](http://papaparse.com/demo)
To learn how to use Papa Parse:
- [Documentation](http://papaparse.com/docs)
Papa Parse for Node
--------------------
Papa Parse can parse a [Readable Stream](https://nodejs.org/api/stream.html#stream_readable_streams) instead of a [File](https://www.w3.org/TR/FileAPI/) when used in Node.js environments (in addition to plain strings). In this mode, `encoding` must, if specified, be a Node-supported character encoding. The `Papa.LocalChunkSize`, `Papa.RemoteChunkSize` , `download`, `withCredentials` and `worker` config options are unavailable.
Get Started
-----------
Use [papaparse.min.js](https://github.com/mholt/PapaParse/blob/master/papaparse.min.js) for production.
For usage instructions, see the [homepage](http://papaparse.com) and, for more detail, the [documentation](http://papaparse.com/docs).
Tests
-----
Papa Parse is under test. Download this repository, run `npm install`, then `npm test` to run the tests in your browser.
Contributing
------------
To discuss a new feature or ask a question, open an issue. To fix a bug, submit a pull request to be credited with the [contributors](https://github.com/mholt/PapaParse/graphs/contributors)! Remember, a pull request, *with test*, is best. You may also discuss on Twitter with [#PapaParse](https://twitter.com/search?q=%23PapaParse&src=typd&f=realtime) or directly to me, [@mholt6](https://twitter.com/mholt6).

40
bower.json

@ -1,40 +0,0 @@ @@ -1,40 +0,0 @@
{
"name": "papaparse",
"main": "papaparse.js",
"homepage": "http://papaparse.com",
"authors": [
"Matthew Holt"
],
"description": "Fast and powerful CSV parser for the browser. Converts CSV->JSON and JSON->CSV. Supports web workers and streaming large files.",
"keywords": [
"csv",
"parse",
"parsing",
"parser",
"delimited",
"text",
"data",
"auto-detect",
"comma",
"tab",
"pipe",
"file",
"filereader",
"stream",
"worker",
"workers",
"ajax",
"thread",
"threading",
"multi-threaded"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests",
"player"
]
}

60
package.json

@ -1,60 +0,0 @@ @@ -1,60 +0,0 @@
{
"name": "papaparse",
"version": "4.3.6",
"description": "Fast and powerful CSV parser for the browser that supports web workers and streaming large files. Converts CSV to JSON and JSON to CSV.",
"keywords": [
"csv",
"parser",
"parse",
"parsing",
"delimited",
"text",
"data",
"auto-detect",
"comma",
"tab",
"pipe",
"file",
"filereader",
"stream",
"worker",
"workers",
"thread",
"threading",
"multi-threaded",
"jquery-plugin"
],
"homepage": "http://papaparse.com",
"repository": {
"type": "git",
"url": "https://github.com/mholt/PapaParse.git"
},
"author": {
"name": "Matthew Holt",
"url": "https://twitter.com/mholt6"
},
"licenses": [
{
"type": "MIT",
"url": "http://opensource.org/licenses/MIT"
}
],
"main": "papaparse.js",
"devDependencies": {
"chai": "^3.0.0",
"connect": "^3.3.3",
"grunt": "^0.4.5",
"grunt-contrib-uglify": "^0.6.0",
"mocha": "^3.5.3",
"mocha-phantomjs": "^3.5.4",
"open": "0.0.5",
"phantomjs": "1.9.1 - 1.9.7-15",
"serve-static": "^1.7.1"
},
"scripts": {
"test-browser": "node tests/test.js",
"test-phantomjs": "node tests/test.js --phantomjs",
"test-node": "mocha tests/node-tests.js tests/test-cases.js",
"test": "npm run test-node && npm run test-phantomjs"
}
}

7
papaparse.min.js vendored

File diff suppressed because one or more lines are too long

1045
player/player.css

File diff suppressed because it is too large Load Diff

78
player/player.html

@ -1,78 +0,0 @@ @@ -1,78 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Papa Parse Player</title>
<meta charset="utf-8">
<link rel="stylesheet" href="player.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="../papaparse.js"></script>
<script src="player.js"></script>
</head>
<body>
<h1><a href="http://papaparse.com">Papa Parse</a> Player</h1>
<div class="grid-container">
<div class="grid-25">
<label><input type="checkbox" id="download"> Download</label>
<label><input type="checkbox" id="stream"> Stream</label>
<label><input type="checkbox" id="chunk"> Chunk</label>
<label><input type="checkbox" id="worker"> Worker thread</label>
<label><input type="checkbox" id="header"> Header row</label>
<label><input type="checkbox" id="dynamicTyping"> Dynamic typing</label>
<label><input type="checkbox" id="fastmode"> Fast mode</label>
<label><input type="checkbox" id="skipEmptyLines"> Skip empty lines</label>
<label><input type="checkbox" id="step-pause"> Pause on step</label>
<label><input type="checkbox" id="print-steps"> Log each step/chunk</label>
<label>Delimiter: <input type="text" size="5" placeholder="auto" id="delimiter"> <a href="javascript:" id="insert-tab">tab</a></label>
Line Endings:
<label style="display: inline;"><input type="radio" name="newline" id="newline-auto" checked>Auto</label>
<label style="display: inline;"><input type="radio" name="newline" id="newline-n">\n</label>
<label style="display: inline;"><input type="radio" name="newline" id="newline-r">\r</label>
<label style="display: inline;"><input type="radio" name="newline" id="newline-rn">\r\n</label>
<label>Preview: <input type="number" min="0" max="1000" placeholder="default" id="preview"></label>
<label>Encoding: <input type="text" id="encoding" placeholder="default" size="10"></label>
<label>Comment char: <input type="text" size="5" maxlength="1" placeholder="default" id="comments"></label>
<label>Papa.LocalChunkSize: <input type="number" min="0" placeholder="default" id="localChunkSize"></label>
<label>Papa.RemoteChunkSize: <input type="number" min="0" placeholder="default" id="remoteChunkSize"></label>
</div>
<div class="grid-75 text-center">
<textarea id="input" placeholder="Input">Column 1,Column 2,Column 3,Column 4
1-1,1-2,1-3,1-4
2-1,2-2,2-3,2-4
3-1,3-2,3-3,3-4
40,41,42,43
"Quoted field",No quotes,"Foo","bar",extra
"Field quoted with
line break"</textarea>
<br>
<b>or</b>
<br>
<input type="file" id="files" multiple>
<br><br>
<button id="submit-parse">Parse</button>
&nbsp;
<button id="submit-unparse">Unparse</button>
<br><br>
<i>Open the Console in your browser's inspector tools to see results.</i>
</div>
</div>
</body>
</html>

178
player/player.js

@ -1,178 +0,0 @@ @@ -1,178 +0,0 @@
var stepped = 0, chunks = 0, rows = 0;
var start, end;
var parser;
var pauseChecked = false;
var printStepChecked = false;
$(function()
{
$('#submit-parse').click(function()
{
stepped = 0;
chunks = 0;
rows = 0;
var txt = $('#input').val();
var localChunkSize = $('#localChunkSize').val();
var remoteChunkSize = $('#remoteChunkSize').val();
var files = $('#files')[0].files;
var config = buildConfig();
// NOTE: Chunk size does not get reset if changed and then set back to empty/default value
if (localChunkSize)
Papa.LocalChunkSize = localChunkSize;
if (remoteChunkSize)
Papa.RemoteChunkSize = remoteChunkSize;
pauseChecked = $('#step-pause').prop('checked');
printStepChecked = $('#print-steps').prop('checked');
if (files.length > 0)
{
if (!$('#stream').prop('checked') && !$('#chunk').prop('checked'))
{
for (var i = 0; i < files.length; i++)
{
if (files[i].size > 1024 * 1024 * 10)
{
alert("A file you've selected is larger than 10 MB; please choose to stream or chunk the input to prevent the browser from crashing.");
return;
}
}
}
start = performance.now();
$('#files').parse({
config: config,
before: function(file, inputElem)
{
console.log("Parsing file:", file);
},
complete: function()
{
console.log("Done with all files.");
}
});
}
else
{
start = performance.now();
var results = Papa.parse(txt, config);
console.log("Synchronous parse results:", results);
}
});
$('#submit-unparse').click(function()
{
var input = $('#input').val();
var delim = $('#delimiter').val();
var results = Papa.unparse(input, {
delimiter: delim
});
console.log("Unparse complete!");
console.log("--------------------------------------");
console.log(results);
console.log("--------------------------------------");
});
$('#insert-tab').click(function()
{
$('#delimiter').val('\t');
});
});
function buildConfig()
{
return {
delimiter: $('#delimiter').val(),
newline: getLineEnding(),
header: $('#header').prop('checked'),
dynamicTyping: $('#dynamicTyping').prop('checked'),
preview: parseInt($('#preview').val() || 0),
step: $('#stream').prop('checked') ? stepFn : undefined,
encoding: $('#encoding').val(),
worker: $('#worker').prop('checked'),
comments: $('#comments').val(),
complete: completeFn,
error: errorFn,
download: $('#download').prop('checked'),
fastMode: $('#fastmode').prop('checked'),
skipEmptyLines: $('#skipEmptyLines').prop('checked'),
chunk: $('#chunk').prop('checked') ? chunkFn : undefined,
beforeFirstChunk: undefined,
};
function getLineEnding()
{
if ($('#newline-n').is(':checked'))
return "\n";
else if ($('#newline-r').is(':checked'))
return "\r";
else if ($('#newline-rn').is(':checked'))
return "\r\n";
else
return "";
}
}
function stepFn(results, parserHandle)
{
stepped++;
rows += results.data.length;
parser = parserHandle;
if (pauseChecked)
{
console.log(results, results.data[0]);
parserHandle.pause();
return;
}
if (printStepChecked)
console.log(results, results.data[0]);
}
function chunkFn(results, streamer, file)
{
if (!results)
return;
chunks++;
rows += results.data.length;
parser = streamer;
if (printStepChecked)
console.log("Chunk data:", results.data.length, results);
if (pauseChecked)
{
console.log("Pausing; " + results.data.length + " rows in chunk; file:", file);
streamer.pause();
return;
}
}
function errorFn(error, file)
{
console.log("ERROR:", error, file);
}
function completeFn()
{
end = performance.now();
if (!$('#stream').prop('checked')
&& !$('#chunk').prop('checked')
&& arguments[0]
&& arguments[0].data)
rows = arguments[0].data.length;
console.log("Finished input (async). Time:", end-start, arguments);
console.log("Rows:", rows, "Stepped:", stepped, "Chunks:", chunks);
}

8
tests/long-sample.csv

@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
Grant,Dyer,Donec.elementum@orciluctuset.example,2013-11-23T02:30:31-08:00,2014-05-31T01:06:56-07:00,Magna Ut Associates,ljenkins
Cherokee,Shields,Nulla.Semper.Tellus@duinec.example,2014-11-22T16:43:51-08:00,2013-09-26T11:47:15-07:00,Pede Corporation,Donec.elementum@orciluctuset.example
Catherine,Parrish,lorem@feugiatnon.example,2015-02-11T12:01:10-08:00,2015-02-26T00:29:40-08:00,Phasellus Fermentum Convallis PC,Donec.elementum@orciluctuset.example
Destiny,Shannon,libero@Aenean.example,2015-07-14T09:38:11-07:00,2014-01-11T14:53:04-08:00,Pretium Et Inc.,Donec.elementum@orciluctuset.example
Callum,Underwood,Phasellus@Quisquetincidunt.example,2013-09-13T18:49:35-07:00,2014-12-04T23:04:19-08:00,Sed Turpis Nec LLP,ljenkins
Elliott,Wright,cursus@nibh.example,2015-04-20T14:35:19-07:00,2015-03-05T12:56:46-08:00,Dolor Associate,Phasellus@Quisquetincidunt.example
Galvin,Foley,nisi.Aenean.eget@atauctorullamcorper.example,2014-03-20T23:20:15-07:00,2014-06-11T15:00:23-07:00,Adipiscing Industrie,Phasellus@Quisquetincidunt.example
Talon,Salinas,posuere.vulputate.lacus@Donecsollicitudin.example,2015-01-31T09:19:02-08:00,2014-12-17T04:59:18-08:00,Aliquam Iaculis Incorporate,Phasellus@Quisquetincidunt.example
1 Grant Dyer Donec.elementum@orciluctuset.example 2013-11-23T02:30:31-08:00 2014-05-31T01:06:56-07:00 Magna Ut Associates ljenkins
2 Cherokee Shields Nulla.Semper.Tellus@duinec.example 2014-11-22T16:43:51-08:00 2013-09-26T11:47:15-07:00 Pede Corporation Donec.elementum@orciluctuset.example
3 Catherine Parrish lorem@feugiatnon.example 2015-02-11T12:01:10-08:00 2015-02-26T00:29:40-08:00 Phasellus Fermentum Convallis PC Donec.elementum@orciluctuset.example
4 Destiny Shannon libero@Aenean.example 2015-07-14T09:38:11-07:00 2014-01-11T14:53:04-08:00 Pretium Et Inc. Donec.elementum@orciluctuset.example
5 Callum Underwood Phasellus@Quisquetincidunt.example 2013-09-13T18:49:35-07:00 2014-12-04T23:04:19-08:00 Sed Turpis Nec LLP ljenkins
6 Elliott Wright cursus@nibh.example 2015-04-20T14:35:19-07:00 2015-03-05T12:56:46-08:00 Dolor Associate Phasellus@Quisquetincidunt.example
7 Galvin Foley nisi.Aenean.eget@atauctorullamcorper.example 2014-03-20T23:20:15-07:00 2014-06-11T15:00:23-07:00 Adipiscing Industrie Phasellus@Quisquetincidunt.example
8 Talon Salinas posuere.vulputate.lacus@Donecsollicitudin.example 2015-01-31T09:19:02-08:00 2014-12-17T04:59:18-08:00 Aliquam Iaculis Incorporate Phasellus@Quisquetincidunt.example

64
tests/node-tests.js

@ -1,64 +0,0 @@ @@ -1,64 +0,0 @@
(function() {
"use strict";
var Papa = require("../papaparse.js");
var fs = require('fs');
var assert = require('assert');
var longSampleRawCsv = fs.readFileSync(__dirname + '/long-sample.csv', 'utf8');
function assertLongSampleParsedCorrectly(parsedCsv) {
assert.equal(8, parsedCsv.data.length)
assert.deepEqual(parsedCsv.data[0], [
'Grant',
'Dyer',
'Donec.elementum@orciluctuset.example',
'2013-11-23T02:30:31-08:00',
'2014-05-31T01:06:56-07:00',
'Magna Ut Associates',
'ljenkins'
])
assert.deepEqual(parsedCsv.data[7], [
'Talon',
'Salinas',
'posuere.vulputate.lacus@Donecsollicitudin.example',
'2015-01-31T09:19:02-08:00',
'2014-12-17T04:59:18-08:00',
'Aliquam Iaculis Incorporate',
'Phasellus@Quisquetincidunt.example'
]);
assert.deepEqual(parsedCsv.meta, {
"delimiter":",",
"linebreak":"\n",
"aborted":false,
"truncated":false,
"cursor":1209
});
assert.equal(parsedCsv.errors.length, 0)
}
describe('PapaParse', function() {
it('synchronously parsed CSV should be correctly parsed', function() {
assertLongSampleParsedCorrectly(Papa.parse(longSampleRawCsv));
});
it('asynchronously parsed CSV should be correctly parsed', function(done) {
Papa.parse(longSampleRawCsv, {
complete: function(parsedCsv) {
assertLongSampleParsedCorrectly(parsedCsv);
done();
},
});
});
it('asynchronously parsed streaming CSV should be correctly parsed', function(done) {
Papa.parse(fs.createReadStream(__dirname + '/long-sample.csv', 'utf8'), {
complete: function(parsedCsv) {
assertLongSampleParsedCorrectly(parsedCsv);
done();
},
});
});
});
})();

2
tests/sample.csv

@ -1,2 +0,0 @@ @@ -1,2 +0,0 @@
A,B,C
X,Y,Z
1 A B C
2 X Y Z

1735
tests/test-cases.js

File diff suppressed because it is too large Load Diff

19
tests/test.js

@ -1,19 +0,0 @@ @@ -1,19 +0,0 @@
var connect = require('connect');
var serveStatic = require('serve-static');
var open = require('open');
var path = require('path');
var child_process = require('child_process');
var server = connect().use(serveStatic(path.join(__dirname, '/..'))).listen(8071, function() {
if (process.argv.indexOf('--phantomjs') !== -1) {
child_process.spawn('node_modules/.bin/mocha-phantomjs', ['http://localhost:8071/tests/tests.html'], {
stdio: 'inherit'
}).on('exit', function () {
server.close();
});
} else {
open('http://localhost:8071/tests/tests.html');
console.log('Serving tests...');
}
});

29
tests/tests.html

@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
<html>
<head>
<title>Papa Parse Tests</title>
<meta charset="utf-8">
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="../papaparse.js"></script>
<script src="http://chaijs.com/chai.js"></script>
<script src="../node_modules/mocha/mocha.js"></script>
<script>mocha.setup('bdd')</script>
<script src="test-cases.js"></script>
</head>
<body>
<div id="mocha"></div>
<script>
if (window.mochaPhantomJS) {
mochaPhantomJS.run();
} else {
mocha.checkLeaks();
mocha.globals(['jQuery']);
mocha.run();
}
</script>
</body>
</html>
Loading…
Cancel
Save