Added the capability to upload CSV files
This commit is contained in:
parent
90b02eef79
commit
d1e736d7a7
19 changed files with 678 additions and 99 deletions
47
static/csv.js
Normal file
47
static/csv.js
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
function parse(text) {
|
||||
let state = 0;
|
||||
let idx = 0;
|
||||
let current = '';
|
||||
let curr_row = [];
|
||||
let rows = [];
|
||||
|
||||
while(idx < text.length) {
|
||||
switch (text[idx]) {
|
||||
case '\\':
|
||||
current += text[idx++];
|
||||
break;
|
||||
|
||||
case '"':
|
||||
if(current.length == 0) {
|
||||
while(text.length > idx && text[++idx] != '"')
|
||||
current += text[idx];
|
||||
}
|
||||
break;
|
||||
|
||||
case ',':
|
||||
if (/^\d+(\.\d+)?$/.test(current)) {
|
||||
let asnum = parseFloat(current);
|
||||
curr_row.push(asnum);
|
||||
} else {
|
||||
curr_row.push(current);
|
||||
}
|
||||
current = '';
|
||||
break;
|
||||
|
||||
case '\n':
|
||||
curr_row.push(current);
|
||||
current = '';
|
||||
rows.push(curr_row);
|
||||
curr_row = [];
|
||||
break;
|
||||
|
||||
default:
|
||||
current += text[idx];
|
||||
break;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
export default parse;
|
||||
Loading…
Add table
Add a link
Reference in a new issue