This library allows you to read (parse) and write (generate) CSV like text data in manner similar to reading and writing from/to databases. It does this by associating a schema (called Meta) with the text data.
The schema supports a wide variety of text data where lines consist of field values (not just CSV). This includes data with lines that contain different fields depending on the value of key fields - where effectively the data is a database with multiple tables (each having records with different fields).
Fielded Text is ideal for reading and writing database like text data with complex schemas containing multiple tables.
Note that this library is designed for applications running in a "browser". For "node" applications use @pbkware/fielded-text-node.
The structure of this meta/schema is specified by the proposed Fielded Text standard. A schema can be created for text data using a Fielded Text editor and then used by the library to read and write data in a similar fashion to reading and writing to/from database tables.
Below is a very simple parsing example:
import { FtReader, FtXmlMetaSerialization } from "@pbkware/fielded-text-web";
// CSV data to be read
const csvData = `Name,Age
John Doe,30
Jane Smith,25`;
// Meta describing the schema of the CSV data
const xmlMeta = `<?xml version="1.0" encoding="utf-8"?>
<FieldedText HeadingLineCount="1">
<Field Name="Name"/>
<Field Name="Age" DataType="Integer"/>
</FieldedText>`;
// Load meta data from XML
const metaReader = new FtXmlMetaSerialization();
const meta = metaReader.deserialize(xmlMeta);
const reader = new FtReader(meta, csvData);
// Read and log the data
while (reader.read()) {
console.log(
reader.fieldList.get(0).asString,
reader.fieldList.get(1).asBigInt,
);
}
npm install @pbkware/fielded-text-web
See Change Log for changes - including any breaking changes.