Introduce the LineOptions interface and optional ctor param for Line.
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 21 Mar 2021 19:05:01 +0000 (15:05 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 21 Mar 2021 19:05:01 +0000 (15:05 -0400)
Currently this is used to specify a new FormatType, which can be used by
ustaxviewer to format the value appropriately.

src/core/Line.ts
src/core/index.ts
src/fed2019/Form1116.ts
src/fed2019/Form8606.ts

index bdd55711e1f41caf7ba4486c6a430ceb0bd02b1c..3b709c90ad634e6947dfce9b80c7cbdcd5c4b14e 100644 (file)
@@ -7,14 +7,27 @@ import TaxReturn from './TaxReturn';
 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 {
@@ -25,6 +38,10 @@ export abstract class Line<T> {
     return this._description;
   }
 
+  get options(): LineOptions {
+    return this._options || {};
+  }
+
   abstract value(tr: TaxReturn): T;
 };
 
@@ -33,8 +50,8 @@ type ComputeFunc<T> = (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;
   }
 
@@ -57,8 +74,8 @@ export class ReferenceLine<F extends Form,
   // 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;
@@ -85,8 +102,8 @@ export class SymbolicLine<F extends Form & { [key in K]: ComputeFunc<ReturnType<
   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;
   }
@@ -106,8 +123,8 @@ export class InputLine<U = unknown, T extends keyof U = any> extends Line<U[T]>
 
   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;
   }
@@ -130,8 +147,8 @@ export class AccumulatorLine<F extends Form,
   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;
   }
index c0d89796b20d3b277f2e0e0c566bd920dd980f44..20e758b5377b8d39dc6835a71e63abe4d15af178 100644 (file)
@@ -3,7 +3,7 @@
 // version 3.0. The full text of the license can be found in LICENSE.txt.
 // SPDX-License-Identifier: GPL-3.0-only
 
-export { Line } from './Line';
+export { Line, FormatType } from './Line';
 export { default as Form } from './Form';
 export { default as Person } from './Person';
 export { default as TaxReturn } from './TaxReturn';
index 1514b51cbf65def05807bef7bdcd9587a55068e8..4baf98d529c359e84a9edaa65955cf87c6ceeace 100644 (file)
@@ -4,7 +4,7 @@
 // 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';
 
@@ -71,7 +71,7 @@ export default class Form1116 extends Form<Form1116Input> {
     }),
     '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');
     }),
index 4938de3411401990669c8a2859c8ce5f52cae4e9..2ab8132c6f74fe206b019137fa7aca5ed64a4b9e 100644 (file)
@@ -4,7 +4,7 @@
 // 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 {
@@ -44,7 +44,7 @@ export default class Form8606 extends Form<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'),