import * as Trace from './Trace';
import Form, { FormClass } from './Form';
+export enum FormatType {
+ Dollar = '$',
+ Decimal = '.',
+ Percent = '%',
+ String = 's',
+}
+
+interface LineOptions {
+ formatType?: FormatType;
+}
+
export abstract class Line<T> {
private _description?: string;
+ private _options?: LineOptions;
_id: string; // _id is set by Form.init().
form: Form; // Set by Form.init();
- constructor(description?: string) {
+ constructor(description?: string, options?: LineOptions) {
this._description = description;
+ this._options = options;
}
get id(): string {
return this._description;
}
+ get options(): LineOptions {
+ return this._options || {};
+ }
+
abstract value(tr: TaxReturn): T;
};
export class ComputedLine<T> extends Line<T> {
private _compute: ComputeFunc<T>;
- constructor(compute: ComputeFunc<T>, description?: string) {
- super(description);
+ constructor(compute: ComputeFunc<T>, description?: string, options?: LineOptions) {
+ super(description, options);
this._compute = compute;
}
// If creating a ReferenceLine and F is the same class as the
// the one the Line is in, erase |form|'s type with |as any| to
// keep TypeScript happy.
- constructor(form: FormClass<F>, line: L, description?: string, fallback?: T) {
- super(description || `Reference ${form.name}@${line}`);
+ constructor(form: FormClass<F>, line: L, description?: string, fallback?: T, options?: LineOptions) {
+ super(description || `Reference ${form.name}@${line}`, options);
this._form = form;
this._line = line;
this._fallback = fallback;
private _form: FormClass<F>;
private _key: K;
- constructor(form: FormClass<F>, key: K, description?: string) {
- super(description || `Reference ${form.name}/${key}`);
+ constructor(form: FormClass<F>, key: K, description?: string, options?: LineOptions) {
+ super(description || `Reference ${form.name}/${key}`, options);
this._form = form;
this._key = key;
}
form: Form<U>;
- constructor(input: T, description?: string, fallback?: U[T]) {
- super(description || `Input from ${input}`);
+ constructor(input: T, description?: string, fallback?: U[T], options?: LineOptions) {
+ super(description || `Input from ${input}`, options);
this._input = input;
this._fallback = fallback;
}
private _form: FormClass<F>;
private _line: L;
- constructor(form: FormClass<F>, line: L, description?: string) {
- super(description || `Accumulator ${form.name}@${line}`);
+ constructor(form: FormClass<F>, line: L, description?: string, options?: LineOptions) {
+ super(description || `Accumulator ${form.name}@${line}`, options);
this._form = form;
this._line = line;
}
// SPDX-License-Identifier: GPL-3.0-only
import { Form, Person, TaxReturn } from '../core';
-import { Line, ComputedLine, InputLine, ReferenceLine, SymbolicLine, UnsupportedLine, sumFormLines } from '../core/Line';
+import { Line, ComputedLine, InputLine, ReferenceLine, SymbolicLine, UnsupportedLine, sumFormLines, FormatType } from '../core/Line';
import { UnsupportedFeatureError } from '../core/Errors';
import { reduceBySum } from '../core/Math';
}),
'3f': new ComputedLine((tr): number => {
return Number.parseFloat((this.getValue(tr, '3d') / this.getValue(tr, '3e')).toFixed(4));
- }),
+ }, undefined, { formatType: FormatType.Decimal }),
'3g': new ComputedLine((tr): number => {
return this.getValue(tr, '3c') * this.getValue(tr, '3f');
}),
// SPDX-License-Identifier: GPL-3.0-only
import { Form, Person, TaxReturn } from '../core';
-import { Line, AccumulatorLine, ComputedLine, InputLine, ReferenceLine, UnsupportedLine } from '../core/Line';
+import { Line, AccumulatorLine, ComputedLine, InputLine, ReferenceLine, UnsupportedLine, FormatType } from '../core/Line';
import { clampToZero, undefinedToZero } from '../core/Math';
export interface Form8606Input {
undefinedToZero(this.getValue(tr, '7')) +
undefinedToZero(this.getValue(tr, '8'));
}),
- '10': new ComputedLine((tr): number => this.getValue(tr, '5') / this.getValue(tr, '9')),
+ '10': new ComputedLine((tr): number => this.getValue(tr, '5') / this.getValue(tr, '9'), undefined, { formatType: FormatType.Decimal }),
'11': new ComputedLine((tr): number => this.getValue(tr, '8') * this.getValue(tr, '10'), 'Nontaxable portion converted to Roth'),
'12': new ComputedLine((tr): number => this.getValue(tr, '7') * this.getValue(tr, '10'), 'Nontaxable portion of distributions not converted to Roth'),
'13': new ComputedLine((tr): number => this.getValue(tr, '11') + this.getValue(tr, '12'), 'Nontaxable portion of all distributions'),