What is @loaders.gl/core?
@loaders.gl/core is a framework-agnostic library for loading and processing data in various formats. It provides a unified API for handling different types of data sources, making it easier to work with complex data pipelines.
What are @loaders.gl/core's main functionalities?
Loading Data
This feature allows you to load data from various sources using different loaders. In this example, the CSVLoader is used to load a CSV file from a URL.
const { load } = require('@loaders.gl/core');
const { CSVLoader } = require('@loaders.gl/csv');
async function loadData(url) {
const data = await load(url, CSVLoader);
console.log(data);
}
loadData('https://example.com/data.csv');
Parsing Data
This feature allows you to parse data from a string or buffer using different parsers. In this example, the JSONLoader is used to parse a JSON string.
const { parse } = require('@loaders.gl/core');
const { JSONLoader } = require('@loaders.gl/json');
async function parseData(jsonString) {
const data = await parse(jsonString, JSONLoader);
console.log(data);
}
parseData('{"key": "value"}');
Creating Custom Loaders
This feature allows you to create and register custom loaders for handling specific data formats. In this example, a CustomLoader is created and registered to load data from a custom format.
const { registerLoaders, Loader } = require('@loaders.gl/core');
class CustomLoader extends Loader {
parse(arrayBuffer) {
// Custom parsing logic
return { data: new Uint8Array(arrayBuffer) };
}
}
registerLoaders([new CustomLoader()]);
async function loadCustomData(url) {
const data = await load(url, CustomLoader);
console.log(data);
}
loadCustomData('https://example.com/data.custom');
Other packages similar to @loaders.gl/core
papaparse
PapaParse is a powerful CSV parser that can handle large files and various edge cases. It is specifically designed for parsing CSV data, whereas @loaders.gl/core provides a more general framework for loading and parsing multiple data formats.
axios
Axios is a popular HTTP client for making requests to fetch data from URLs. While it focuses on making HTTP requests, @loaders.gl/core provides a higher-level abstraction for loading and parsing data from various sources.
d3-dsv
d3-dsv is a module from the D3.js library that provides functions for parsing and formatting delimiter-separated values (DSV) files. It is specialized for DSV formats, whereas @loaders.gl/core supports a wider range of data formats and provides a unified API.