hedgedoc/src/components/markdown-renderer/replace-components/csv/csv-parser.ts
Philip Molares d482065d72
Feature/csv table (#500)
- added csv-replacer
- changed highlghted-code plugin:
     each replacer extracts what he need from the data-extra attribute now
- changed CHANGELOG.md

Co-authored-by: Erik Michelson <github@erik.michelson.eu>
2020-08-29 15:55:42 +02:00

8 lines
336 B
TypeScript

export const parseCsv = (csvText: string, csvColumnDelimiter: string): string[][] => {
const rows = csvText.split('\n')
if (!rows || rows.length === 0) {
return []
}
const splitRegex = new RegExp(`${csvColumnDelimiter}(?=(?:[^"]*"[^"]*")*[^"]*$)`)
return rows.filter(row => row !== '').map(row => row.split(splitRegex))
}