diff --git a/papaparse.js b/papaparse.js index 83a297b..59eff7c 100644 --- a/papaparse.js +++ b/papaparse.js @@ -35,8 +35,8 @@ if (typeof window !== 'undefined') { return window; } if (typeof global !== 'undefined') { return global; } - // When running tests none of the above have been defined - return {}; + // When running tests none of the above have been defined + return {}; })(); @@ -193,13 +193,13 @@ function CsvToJson(_input, _config) { _config = _config || {}; - var dynamicTyping = _config.dynamicTyping || false; - if (isFunction(dynamicTyping)) { - _config.dynamicTypingFunction = dynamicTyping; - // Will be filled on first row call - dynamicTyping = {}; - } - _config.dynamicTyping = dynamicTyping; + var dynamicTyping = _config.dynamicTyping || false; + if (isFunction(dynamicTyping)) { + _config.dynamicTypingFunction = dynamicTyping; + // Will be filled on first row call + dynamicTyping = {}; + } + _config.dynamicTyping = dynamicTyping; if (_config.worker && Papa.WORKERS_SUPPORTED) { @@ -643,8 +643,8 @@ { var contentRange = xhr.getResponseHeader('Content-Range'); if (contentRange === null) { // no content range, then finish! - return -1; - } + return -1; + } return parseInt(contentRange.substr(contentRange.lastIndexOf('/') + 1)); } } @@ -829,7 +829,7 @@ var _input; // The input being parsed var _parser; // The core parser being used 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 _fields = []; // Fields are from the header row of the input, if there is one var _results = { // The last results returned from the parser @@ -973,13 +973,13 @@ _results.data.splice(0, 1); } - function shouldApplyDynamicTyping(field) { - // Cache function values to avoid calling it for each row - if (_config.dynamicTypingFunction && _config.dynamicTyping[field] === undefined) { - _config.dynamicTyping[field] = _config.dynamicTypingFunction(field); - } - return (_config.dynamicTyping[field] || _config.dynamicTyping) === true - } + function shouldApplyDynamicTyping(field) { + // Cache function values to avoid calling it for each row + if (_config.dynamicTypingFunction && _config.dynamicTyping[field] === undefined) { + _config.dynamicTyping[field] = _config.dynamicTypingFunction(field); + } + return (_config.dynamicTyping[field] || _config.dynamicTyping) === true + } function parseDynamic(field, value) { diff --git a/player/player.js b/player/player.js index 9560c24..2484b63 100644 --- a/player/player.js +++ b/player/player.js @@ -43,7 +43,7 @@ $(function() } start = performance.now(); - + $('#files').parse({ config: config, before: function(file, inputElem) @@ -127,14 +127,14 @@ function stepFn(results, parserHandle) 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]); } @@ -172,7 +172,7 @@ function completeFn() && 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); -} \ No newline at end of file +} diff --git a/tests/test-cases.js b/tests/test-cases.js index f9e93ea..5ae3afb 100644 --- a/tests/test-cases.js +++ b/tests/test-cases.js @@ -47,10 +47,10 @@ var CORE_PARSER_TESTS = [ }, { description: "Whitespace at edges of unquoted field", - input: 'a, b ,c', + input: 'a, b ,c', notes: "Extra whitespace should graciously be preserved", expected: { - data: [['a', ' b ', 'c']], + data: [['a', ' b ', 'c']], errors: [] } }, @@ -220,12 +220,12 @@ var CORE_PARSER_TESTS = [ } }, { - description: "Empty quoted field at EOF is empty", - input: 'a,b,""\na,b,""', - expected: { - data: [['a', 'b', ''], ['a', 'b', '']], - errors: [] - } + description: "Empty quoted field at EOF is empty", + input: 'a,b,""\na,b,""', + expected: { + data: [['a', 'b', ''], ['a', 'b', '']], + errors: [] + } }, { description: "Multiple consecutive empty fields", @@ -933,9 +933,9 @@ var PARSE_TESTS = [ description: "Header row with preceding comment", notes: "Must parse correctly headers if they are preceded by comments", input: '#Comment\na,b\nc,d\n', - config: { header: true, comments: '#', skipEmptyLines: true, delimiter: ','}, + config: { header: true, comments: '#', skipEmptyLines: true, delimiter: ','}, expected: { - data: [{'a': 'c', 'b': 'd'}], + data: [{'a': 'c', 'b': 'd'}], errors: [] } } diff --git a/tests/test.js b/tests/test.js index 4c07bb8..60bc88f 100644 --- a/tests/test.js +++ b/tests/test.js @@ -6,14 +6,14 @@ 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(); - }); + 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...'); + open('http://localhost:8071/tests/tests.html'); + console.log('Serving tests...'); } });