Last active
March 16, 2022 04:31
-
-
Save esctabcapslock/0f318f7fe62c1f60d2cf2e9b7480a69f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function csv2arr(data){ | |
data = data.replace(/\n\r/g,'\n'); | |
var f=0; | |
var arr=[] | |
var ar=[''] | |
for(var i=0; i<data.length; i++){ | |
if(data[i]=='"' ) f+=1; | |
//if(data[i]=='"' && !(f%2)) continue; | |
if(data[i]=='"' && data[i+1]=='"' && f%2) continue; | |
if(data[i]=='"' && data[i-1]!='"' && f%2) continue | |
if(data[i]=='"' && data[i+1]!='"' && !(f%2)) continue | |
if(data[i]=='\n' && !(f%2)) {arr.push(ar.slice()); ar=['']} | |
else if(data[i]==',' && !(f%2)) ar.push(''); | |
else ar[ar.length-1]+=data[i] | |
} | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment