Class: Reader

Reader(iterable, fileDescriptor, newlineopt)

Sequential reader and iterator for Fixed Width Files. Parses raw file content line-by-line according to a FileDescriptor specification.

Constructor

new Reader(iterable, fileDescriptor, newlineopt)

Creates an instance of Reader.
Parameters:
Name Type Attributes Default Description
iterable string | Array.<string> | Iterable.<string> Content as a string, line array, or string iterable.
fileDescriptor FileDescriptor Layout specification for the file.
newline string <optional>
"\n" Line separator sequence.
Source:
Throws:
If fileDescriptor is not a FileDescriptor instance or iterable is invalid.
Type
TypeError
Example
const reader = new Reader(fwfContent, fileDescriptor);
for (const row of reader) {
  console.log(row);
}

Classes

Reader

Members

fileDescriptor :FileDescriptor

Layout descriptor for the file.
Type:
Source:

lineNum :number

Current line number index during iteration (1-based).
Type:
  • number
Source:

lines :Array.<string>

Array of extracted and normalized raw line strings.
Type:
  • Array.<string>
Source:

linesCount :number

Total number of lines in the file.
Type:
  • number
Source:

newline :string

Line separator character.
Type:
  • string
Source:

Methods

extractLines(iterable) → {Array.<string>}

Normalizes and splits various input types into an array of string lines.
Parameters:
Name Type Description
iterable string | Array.<string> | Iterable.<string> Input content.
Source:
Throws:
If input type is not supported.
Type
TypeError
Returns:
Array of lines.
Type
Array.<string>

validateAndNormalizeLines()

Validates line lengths against expected file line size and pads trailing spaces if needed.
Source:
Throws:
If line length exceeds expected file line size.
Type
Error