From 029cf06c791ea89e9ebb27f9e3b424250d397a7c Mon Sep 17 00:00:00 2001 From: Samuel Rowe Date: Sun, 31 Jul 2022 23:53:37 +0530 Subject: [PATCH] feat(frontend): created `pruneNumber` utility function --- services/frontend/src/utils/forms.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/services/frontend/src/utils/forms.ts b/services/frontend/src/utils/forms.ts index 560ea3b..26cd41d 100644 --- a/services/frontend/src/utils/forms.ts +++ b/services/frontend/src/utils/forms.ts @@ -1,4 +1,5 @@ import lodash from "lodash"; +import { number } from "yup"; export const checkArray = (array: any, name: string): T => { if (!Array.isArray(array)) { @@ -32,6 +33,19 @@ export const pruneString = (value?: string): string | undefined => { return value; }; +export const pruneNumber = (value?: number): number | undefined => { + if ( + value === undefined || + value === null || + isNaN(value) || + (value as unknown as string) === "" + ) { + return undefined; + } + + return value; +}; + export const splitKVPairs = ( text: string, seperator: string,