mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-10-17 03:04:08 +00:00
16 lines
444 B
TypeScript
16 lines
444 B
TypeScript
import { Parser } from '@json2csv/plainjs';
|
|
import csv from 'csvtojson';
|
|
|
|
export const csvToJson = <T>(csvContent: string) =>
|
|
new Promise<T[]>((resolve) => {
|
|
csv().fromString(csvContent).then(resolve);
|
|
});
|
|
|
|
export type CsvToJson = typeof csvToJson;
|
|
|
|
const jsonParser = new Parser(); // This accepts options if needed
|
|
|
|
export const jsonToCsv = <T>(data: T[]): string => jsonParser.parse(data);
|
|
|
|
export type JsonToCsv = typeof jsonToCsv;
|