aboutsummaryrefslogtreecommitdiff
path: root/src/server/DataVizUtils.ts
blob: 15f03b319e284930f08a724ef419c2f8ded424f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { readFileSync } from 'fs';

export function csvParser(csv: string) {
    const lines = csv.split('\n');
    const headers = lines[0].split(',').map(header => header.trim());
    const data = lines.slice(1).map(line =>
        line.split(',').reduce((last, value, i) => {
            last[headers[i]] = value.trim();
            return last;
        }, {} as any)
    );
    return data;
}

export function csvToString(path: string) {
    return readFileSync(path, 'utf8');
}