From 3ff0bf1f282f38b4e4ec42cd5134eec8d6fca9e5 Mon Sep 17 00:00:00 2001 From: Rufus Pollock Date: Tue, 20 Mar 2012 10:34:20 +0000 Subject: [PATCH] [refactor][s]: remove costco-csv-worker (we are not using it). --- recline.js | 57 ---------------------------------------- src/costco-csv-worker.js | 57 ---------------------------------------- 2 files changed, 114 deletions(-) delete mode 100644 src/costco-csv-worker.js diff --git a/recline.js b/recline.js index ee6f6fa3..64e0bc33 100644 --- a/recline.js +++ b/recline.js @@ -1,60 +1,3 @@ -// importScripts('lib/underscore.js'); - -onmessage = function(message) { - - function parseCSV(rawCSV) { - var patterns = new RegExp(( - // Delimiters. - "(\\,|\\r?\\n|\\r|^)" + - // Quoted fields. - "(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" + - // Standard fields. - "([^\"\\,\\r\\n]*))" - ), "gi"); - - var rows = [[]], matches = null; - - while (matches = patterns.exec(rawCSV)) { - var delimiter = matches[1]; - - if (delimiter.length && (delimiter !== ",")) rows.push([]); - - if (matches[2]) { - var value = matches[2].replace(new RegExp("\"\"", "g"), "\""); - } else { - var value = matches[3]; - } - rows[rows.length - 1].push(value); - } - - if(_.isEqual(rows[rows.length -1], [""])) rows.pop(); - - var docs = []; - var headers = _.first(rows); - _.each(_.rest(rows), function(row, rowIDX) { - var doc = {}; - _.each(row, function(cell, idx) { - doc[headers[idx]] = cell; - }) - docs.push(doc); - }) - - return docs; - } - - var docs = parseCSV(message.data.data); - - var req = new XMLHttpRequest(); - - req.onprogress = req.upload.onprogress = function(e) { - if(e.lengthComputable) postMessage({ percent: (e.loaded / e.total) * 100 }); - }; - - req.onreadystatechange = function() { if (req.readyState == 4) postMessage({done: true, response: req.responseText}) }; - req.open('POST', message.data.url); - req.setRequestHeader('Content-Type', 'application/json'); - req.send(JSON.stringify({docs: docs})); -}; // adapted from https://github.com/harthur/costco. heather rules var costco = function() { diff --git a/src/costco-csv-worker.js b/src/costco-csv-worker.js deleted file mode 100644 index 720d2fda..00000000 --- a/src/costco-csv-worker.js +++ /dev/null @@ -1,57 +0,0 @@ -// importScripts('lib/underscore.js'); - -onmessage = function(message) { - - function parseCSV(rawCSV) { - var patterns = new RegExp(( - // Delimiters. - "(\\,|\\r?\\n|\\r|^)" + - // Quoted fields. - "(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" + - // Standard fields. - "([^\"\\,\\r\\n]*))" - ), "gi"); - - var rows = [[]], matches = null; - - while (matches = patterns.exec(rawCSV)) { - var delimiter = matches[1]; - - if (delimiter.length && (delimiter !== ",")) rows.push([]); - - if (matches[2]) { - var value = matches[2].replace(new RegExp("\"\"", "g"), "\""); - } else { - var value = matches[3]; - } - rows[rows.length - 1].push(value); - } - - if(_.isEqual(rows[rows.length -1], [""])) rows.pop(); - - var docs = []; - var headers = _.first(rows); - _.each(_.rest(rows), function(row, rowIDX) { - var doc = {}; - _.each(row, function(cell, idx) { - doc[headers[idx]] = cell; - }) - docs.push(doc); - }) - - return docs; - } - - var docs = parseCSV(message.data.data); - - var req = new XMLHttpRequest(); - - req.onprogress = req.upload.onprogress = function(e) { - if(e.lengthComputable) postMessage({ percent: (e.loaded / e.total) * 100 }); - }; - - req.onreadystatechange = function() { if (req.readyState == 4) postMessage({done: true, response: req.responseText}) }; - req.open('POST', message.data.url); - req.setRequestHeader('Content-Type', 'application/json'); - req.send(JSON.stringify({docs: docs})); -};