Class: PositiveIntegerColumn

PositiveIntegerColumn()

Positive integer column formatted with leading zeros. Parses strings of digits into integer numbers, and serializes positive integers padded with leading zeros.

Constructor

new PositiveIntegerColumn()

Source:
Example
const col = new PositiveIntegerColumn('age', 3, 'Age in years');
col.toValue('045'); // 45
col.toStr(45); // '045'

Extends

Members

description :string

Description of the column.
Type:
  • string
Inherited From:
Source:

end :number

1-indexed end position of the column within a row line.
Type:
  • number
Inherited From:
Source:

name :string

Name of the column.
Type:
  • string
Inherited From:
Source:

size :number

Character width of the column.
Type:
  • number
Inherited From:
Source:

start :number|null

1-indexed start position of the column within a row line.
Type:
  • number | null
Inherited From:
Source:

Methods

toStr(value) → {string}

Serializes a non-negative integer into a zero-padded fixed-width string.
Parameters:
Name Type Description
value number | null Positive integer value to serialize. Null/undefined serializes to zeros.
Overrides:
Source:
Throws:
If value is not a non-negative integer or exceeds size formatted length.
Type
Error
Returns:
Zero-padded fixed-width string.
Type
string

toValue(slice) → {number}

Converts raw string slice from file into a positive integer.
Parameters:
Name Type Description
slice string Raw fixed-width slice consisting of digits.
Overrides:
Source:
Throws:
If slice contains non-digit characters or parses to negative integer.
Type
Error
Returns:
Parsed integer value.
Type
number

validateToStrSize(value) → {string}

Validates that a formatted string representation matches the required column size.
Parameters:
Name Type Description
value string The formatted string to validate.
Inherited From:
Source:
Throws:
If formatted string length does not equal column size.
Type
Error
Returns:
The validated string.
Type
string