javascript-fwf is a fast, type-safe JavaScript / ES Module library for parsing, validating, and exporting Fixed Width Files (FWF).
It is part of the Fixed Width File Ecosystem and fully implements the fwf-compliance-tests v1.0.0 specification.
- Type-Safe Columns:
CharColumn,RightCharColumn,PositiveIntegerColumn,PositiveDecimalColumn,DateColumn,TimeColumn, andDateTimeColumn. - Flexible Descriptors: Structured records with
HeaderRowDescriptor,DetailRowDescriptor, andFooterRowDescriptor. - Multiple Output Renders: Export layout specifications to Markdown, ReStructuredText (RST), or HTML tables via
RenderUtils. - Full Test Suite & Compliance: 100% compliant with
fwf-compliance-testsv1.0.0. - Git Hooks Ready: Pre-configured
pre-commitandpre-pushhooks.
Install via npm:
npm install @fixed-width-file/javascript-fwfimport {
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 row and file descriptors
const detail = new DetailRowDescriptor([nameCol, ageCol]);
const fileDescriptor = new FileDescriptor([detail]);
// 3. Read fixed-width file 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}`);
}Run unit tests using Vitest:
npm testRun test coverage:
npm run test:coverageSet up pre-commit and pre-push hooks:
pre-commit install
pre-commit install --hook-type pre-pushRun checks manually:
pre-commit run --all-filesThis project is licensed under the MIT License - see the LICENSE file for details.