A fast, type-safe, language-agnostic compliant JavaScript / Node.js library for parsing, formatting, and generating Fixed Width Files (FWF).
Support for CharColumn, RightCharColumn, PositiveIntegerColumn, PositiveDecimalColumn, DateColumn, TimeColumn, and DateTimeColumn.
Compose header, details, and footer rows using HeaderRowDescriptor, DetailRowDescriptor, and FooterRowDescriptor.
Fully compatible with Python pyfwf and Java java-fwf JSON hydration formats and compliant with fwf-compliance-tests v1.0.0.
import {
CharColumn,
PositiveIntegerColumn,
DetailRowDescriptor,
FileDescriptor,
Reader
} from '@fixed-width-file/javascript-fwf';
// 1. Define Columns
const nameCol = new CharColumn('name', 20, 'User Name');
const ageCol = new PositiveIntegerColumn('age', 3, 'Age in years');
// 2. Define Descriptors
const detail = new DetailRowDescriptor([nameCol, ageCol]);
const fileDescriptor = new FileDescriptor([detail]);
// 3. Read Content
const content = "KELSON MEDEIROS 045\nMARIA SILVA 030\n";
const reader = new Reader(content, fileDescriptor, "\n");
for (const row of reader) {
console.log(`Name: ${row.name} | Age: ${row.age}`);
}