UNPKG

sussy-util

Version:
26 lines (25 loc) 1.19 kB
import { JSONObject } from '../Types'; export default class DataConverter { /** * It takes a CSV string and returns an array of objects. * The first line of the CSV is assumed to be the header row. * The header row is used to create the keys for the objects in the array. * The values for the keys are taken from the subsequent rows. * @param {string} csv - string - The CSV string you want to convert to JSON * @param {string} [del=,] - The delimiter in use in the CSV file. * @returns An array of objects. */ static csvToJson(csv: string, del?: string): JSONObject[]; /** * It takes an array of objects and returns a CSV string. * The first object in the array is taken as for the properties of the csv string. * * The function takes two parameters: * json: an array of objects * del: the delimiter to use in the CSV string (defaults to a comma) * @param {object[]} json - object[] - The JSON object you want to convert to CSV. * @param {string} [del=,] - The delimiter to use in the CSV file. * @returns A string */ static jsonToCsv(json: JSONObject[], del?: string): string; }