javascript-fwf

A fast, type-safe, language-agnostic compliant JavaScript / Node.js library for parsing, formatting, and generating Fixed Width Files (FWF).

Node.js 18+ Vitest 100% Coverage FWF Spec v1.0.0

⚡ Type-Safe Column Definitions

Support for CharColumn, RightCharColumn, PositiveIntegerColumn, PositiveDecimalColumn, DateColumn, TimeColumn, and DateTimeColumn.

📜 Structure Descriptors

Compose header, details, and footer rows using HeaderRowDescriptor, DetailRowDescriptor, and FooterRowDescriptor.

🔍 Cross-Language Hydration

Fully compatible with Python pyfwf and Java java-fwf JSON hydration formats and compliant with fwf-compliance-tests v1.0.0.

Quick Usage Example

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}`);
}