From a49995723e391ef2ea10e6462c9859b7aa372b1d Mon Sep 17 00:00:00 2001 From: jrmeurer Date: Thu, 8 Jun 2023 12:47:53 -0600 Subject: [PATCH] Add isDefined and removeUndefineds --- src/utils/index.ts | 1 + src/utils/util.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 src/utils/util.ts diff --git a/src/utils/index.ts b/src/utils/index.ts index 831031f..8a9c0c5 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -7,4 +7,5 @@ export * from './format'; export * from './gas'; export * from './network'; export * from './promises'; +export * from './util'; export * from './versions'; diff --git a/src/utils/util.ts b/src/utils/util.ts new file mode 100644 index 0000000..db478f0 --- /dev/null +++ b/src/utils/util.ts @@ -0,0 +1,13 @@ +export const isDefined = (a: T | undefined | null): a is T => { + return typeof a !== 'undefined' && a !== null; +}; + +export const removeUndefineds = (a: Optional[]): T[] => { + const newArray: T[] = []; + for (const item of a) { + if (isDefined(item)) { + newArray.push(item); + } + } + return newArray; +};