Parses buffer data using CsvParseOptions to create an array of type T.
{TypeError} When data is missing.
{Error} When invalid CsvParseOptions are passed in.
{Error} When the csv file cannot be parsed with the default or provided options.
In this example, data is pulled from a csv file and parsed into array of Data Rows.
// Ensure you have imported the CsvPowers // import { CsvPowers, CsvParseOptions, DataPowers } from "@andi/powers"; type DataRow = { column1: string, column2: string }; const rawData = await DataPowers.get("example.csv", { type: DataType.File, parseOptions: "buffer" }); const exampleData = await CsvPowers.parse<DataRow>(rawData); // Recommended: if manual parsing is not needed, you can combine load and parse const orgData: DataRow[] = await DataPowers.get<DataRow>("example.csv", { type: DataType.File, parseOptions: "csv" }); // Alternative: with custom csv options const orgData: DataRow[] = await DataPowers.get<DataRow>("example.csv", { type: DataType.File, parseOptions: { cast: true, skip_lines_with_error: true} as CsvParseOptions });
Buffer with CSV data.
Various options to control how your CSV is parsed. By default, CSV rows will be parsed into objects.
Generated using TypeDoc
Parses buffer data using CsvParseOptions to create an array of type T.
{TypeError} When data is missing.
{Error} When invalid CsvParseOptions are passed in.
{Error} When the csv file cannot be parsed with the default or provided options.
In this example, data is pulled from a csv file and parsed into array of Data Rows.
// Ensure you have imported the CsvPowers // import { CsvPowers, CsvParseOptions, DataPowers } from "@andi/powers"; type DataRow = { column1: string, column2: string }; const rawData = await DataPowers.get("example.csv", { type: DataType.File, parseOptions: "buffer" }); const exampleData = await CsvPowers.parse<DataRow>(rawData); // Recommended: if manual parsing is not needed, you can combine load and parse const orgData: DataRow[] = await DataPowers.get<DataRow>("example.csv", { type: DataType.File, parseOptions: "csv" }); // Alternative: with custom csv options const orgData: DataRow[] = await DataPowers.get<DataRow>("example.csv", { type: DataType.File, parseOptions: { cast: true, skip_lines_with_error: true} as CsvParseOptions });