Browse Source

Use tabs instead of spaces for formatting.

Closes #386
pull/390/head
Sergi Almacellas Abellana 8 years ago
parent
commit
06aad9e130
  1. 38
      papaparse.js
  2. 20
      tests/test-cases.js
  3. 14
      tests/test.js

38
papaparse.js

@ -35,8 +35,8 @@
if (typeof window !== 'undefined') { return window; } if (typeof window !== 'undefined') { return window; }
if (typeof global !== 'undefined') { return global; } if (typeof global !== 'undefined') { return global; }
// When running tests none of the above have been defined // When running tests none of the above have been defined
return {}; return {};
})(); })();
@ -193,13 +193,13 @@
function CsvToJson(_input, _config) function CsvToJson(_input, _config)
{ {
_config = _config || {}; _config = _config || {};
var dynamicTyping = _config.dynamicTyping || false; var dynamicTyping = _config.dynamicTyping || false;
if (isFunction(dynamicTyping)) { if (isFunction(dynamicTyping)) {
_config.dynamicTypingFunction = dynamicTyping; _config.dynamicTypingFunction = dynamicTyping;
// Will be filled on first row call // Will be filled on first row call
dynamicTyping = {}; dynamicTyping = {};
} }
_config.dynamicTyping = dynamicTyping; _config.dynamicTyping = dynamicTyping;
if (_config.worker && Papa.WORKERS_SUPPORTED) if (_config.worker && Papa.WORKERS_SUPPORTED)
{ {
@ -643,8 +643,8 @@
{ {
var contentRange = xhr.getResponseHeader('Content-Range'); var contentRange = xhr.getResponseHeader('Content-Range');
if (contentRange === null) { // no content range, then finish! if (contentRange === null) { // no content range, then finish!
return -1; return -1;
} }
return parseInt(contentRange.substr(contentRange.lastIndexOf('/') + 1)); return parseInt(contentRange.substr(contentRange.lastIndexOf('/') + 1));
} }
} }
@ -829,7 +829,7 @@
var _input; // The input being parsed var _input; // The input being parsed
var _parser; // The core parser being used var _parser; // The core parser being used
var _paused = false; // Whether we are paused or not var _paused = false; // Whether we are paused or not
var _aborted = false; // Whether the parser has aborted or not var _aborted = false; // Whether the parser has aborted or not
var _delimiterError; // Temporary state between delimiter detection and processing results var _delimiterError; // Temporary state between delimiter detection and processing results
var _fields = []; // Fields are from the header row of the input, if there is one var _fields = []; // Fields are from the header row of the input, if there is one
var _results = { // The last results returned from the parser var _results = { // The last results returned from the parser
@ -973,13 +973,13 @@
_results.data.splice(0, 1); _results.data.splice(0, 1);
} }
function shouldApplyDynamicTyping(field) { function shouldApplyDynamicTyping(field) {
// Cache function values to avoid calling it for each row // Cache function values to avoid calling it for each row
if (_config.dynamicTypingFunction && _config.dynamicTyping[field] === undefined) { if (_config.dynamicTypingFunction && _config.dynamicTyping[field] === undefined) {
_config.dynamicTyping[field] = _config.dynamicTypingFunction(field); _config.dynamicTyping[field] = _config.dynamicTypingFunction(field);
} }
return (_config.dynamicTyping[field] || _config.dynamicTyping) === true return (_config.dynamicTyping[field] || _config.dynamicTyping) === true
} }
function parseDynamic(field, value) function parseDynamic(field, value)
{ {

20
tests/test-cases.js

@ -47,10 +47,10 @@ var CORE_PARSER_TESTS = [
}, },
{ {
description: "Whitespace at edges of unquoted field", description: "Whitespace at edges of unquoted field",
input: 'a, b ,c', input: 'a, b ,c',
notes: "Extra whitespace should graciously be preserved", notes: "Extra whitespace should graciously be preserved",
expected: { expected: {
data: [['a', ' b ', 'c']], data: [['a', ' b ', 'c']],
errors: [] errors: []
} }
}, },
@ -220,12 +220,12 @@ var CORE_PARSER_TESTS = [
} }
}, },
{ {
description: "Empty quoted field at EOF is empty", description: "Empty quoted field at EOF is empty",
input: 'a,b,""\na,b,""', input: 'a,b,""\na,b,""',
expected: { expected: {
data: [['a', 'b', ''], ['a', 'b', '']], data: [['a', 'b', ''], ['a', 'b', '']],
errors: [] errors: []
} }
}, },
{ {
description: "Multiple consecutive empty fields", description: "Multiple consecutive empty fields",
@ -933,9 +933,9 @@ var PARSE_TESTS = [
description: "Header row with preceding comment", description: "Header row with preceding comment",
notes: "Must parse correctly headers if they are preceded by comments", notes: "Must parse correctly headers if they are preceded by comments",
input: '#Comment\na,b\nc,d\n', input: '#Comment\na,b\nc,d\n',
config: { header: true, comments: '#', skipEmptyLines: true, delimiter: ','}, config: { header: true, comments: '#', skipEmptyLines: true, delimiter: ','},
expected: { expected: {
data: [{'a': 'c', 'b': 'd'}], data: [{'a': 'c', 'b': 'd'}],
errors: [] errors: []
} }
} }

14
tests/test.js

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

Loading…
Cancel
Save