Skip to main content

Function: loadData()

loadData(url, type): Promise<Data[]> | Promise<WideData[]>

Loads and parses data from a URL.

Supports JSON, CSV, TSV, and XML formats. The data type is auto-detected from the file extension when type is set to 'auto' (default), falling back to JSON if detection fails.

Parameters

url: string

The URL of the data file to load.

type: "auto" | "json" | "csv" | "tsv" | "xml" = 'auto'

The data format. One of 'json', 'csv', 'tsv', 'xml', or 'auto'. Defaults to 'auto', which infers the type from the URL's file extension.

Returns

Promise<Data[]> | Promise<WideData[]>

A Promise resolving to an array of Data or WideData objects.

Throws

If the data fails to load or the type is unsupported.

Example

import { loadData, race } from 'racing-bars';
const data = await loadData('/data/population.csv', 'csv');
const racer = await race(data, '#race');

See

https://racing-bars.hatemhosny.dev/documentation/api

Defined in

lib/load-data.ts:25