This library allows you to read (parse) and write (generate) files with 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 files with complex schemas containing multiple tables.
Note that this library is built on top of the @pbkware/fielded-text-web library. It supports all the capabilities of @pbkware/fielded-text-web and adds the node run time - allowing reading and writing files. Do NOT import @pbkware/fielded-text-web if @pbkware/fielded-text-node is imported! This is not necessary as @pbkware/fielded-text-node re-exports all types from @pbkware/fielded-text-web.
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:
Name,Age
John Doe,30
Jane Smith,25
<?xml version="1.0" encoding="utf-8"?>
<FieldedText HeadingLineCount="1">
<Field Name="Name"/>
<Field Name="Age" DataType="Integer"/>
</FieldedText>
import { FtNodeFileReader, FtNodeXmlMetaSerialization } from "@pbkware/fielded-text-node";
// Load meta data from XML
const meta = FtNodeXmlMetaSerialization.deserializeFromFile(xmlMeta);
using reader = new FtNodeFileReader(csvFilePath, meta);
// 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-node
See Change Log for changes - including any breaking changes.