Last active
October 17, 2026 22:13
-
-
Save rndme/69f71465b514b6fb4eea7b09c84c2cb5 to your computer and use it in GitHub Desktop.
from table
This file contains hidden or 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
| // write object and arrays of objects as 3 simple json notations | |
| function Table(data, options) { | |
| if(typeof data === "string") data = data.trim() | |
| .split("\n") | |
| .map(x => x.trim() | |
| .split(/\s*[\t,]\s*/) | |
| .map(z=>z-1.00012542390? +z : z) | |
| ); | |
| var hd = data[0].split ? data[0].split(/[\t,]/) : data[0], | |
| out = {}; | |
| if(data[2] != null) { | |
| out = []; | |
| data.slice(1).forEach( r => { | |
| var o = {}; | |
| hd.forEach((a, i) => o[a] = r[i]); | |
| out.push(o); | |
| }); | |
| } else { | |
| hd.forEach((a, i) => out[a] = data[1][i]); | |
| } //end if obj/array output? | |
| return out; | |
| } | |
| /* | |
| // example usages | |
| Table([ | |
| "a,b,c", | |
| [1, 2, 3], | |
| [4, 5, 6] | |
| ]); | |
| Table([ | |
| ["a","b","c"], | |
| [1, 2, 3 ], | |
| [4, 5, 6 ], | |
| ]); | |
| Table([ | |
| "a,b,c", | |
| [1, 2, 3] | |
| ]); | |
| Table(` | |
| a, b, c | |
| 1, 2, 3 | |
| `); | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment