Skip to content

Commit

Permalink
Add isDefined and removeUndefineds
Browse files Browse the repository at this point in the history
  • Loading branch information
therealjmj committed Jun 8, 2023
1 parent 1828677 commit a499957
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export * from './format';
export * from './gas';
export * from './network';
export * from './promises';
export * from './util';
export * from './versions';
13 changes: 13 additions & 0 deletions src/utils/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const isDefined = <T>(a: T | undefined | null): a is T => {
return typeof a !== 'undefined' && a !== null;
};

export const removeUndefineds = <T>(a: Optional<T>[]): T[] => {
const newArray: T[] = [];
for (const item of a) {
if (isDefined(item)) {
newArray.push(item);
}
}
return newArray;
};

0 comments on commit a499957

Please sign in to comment.