From d0daefe926b00f9a0167bff9dc64febcc9269223 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Fri, 21 Feb 2020 10:51:12 -0500 Subject: [PATCH] Add TaxReturn.maybeGetForm() --- src/TaxReturn.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/TaxReturn.ts b/src/TaxReturn.ts index c7f1003..a8e64fb 100644 --- a/src/TaxReturn.ts +++ b/src/TaxReturn.ts @@ -47,10 +47,10 @@ export default class TaxReturn { this._forms.push(form); } - getForm(name: string): T { + maybeGetForm(name: string): T | null { const forms = this.getForms(name); if (forms.length == 0) { - throw new NotFoundError(`No form named ${name}`); + return null; } if (forms.length > 1) { throw new InconsistencyError(`More than 1 form named ${name}`); @@ -58,6 +58,13 @@ export default class TaxReturn { return forms[0]; } + getForm(name: string): T { + const form = this.maybeGetForm(name); + if (!form) + throw new NotFoundError(`No form named ${name}`); + return form; + } + getForms(name: string): T[] { return this._forms.filter(f => f.name == name) as T[]; } -- 2.43.5