summaryrefslogtreecommitdiff
path: root/packages/taler-util/src/helpers.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-util/src/helpers.ts')
-rw-r--r--packages/taler-util/src/helpers.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/packages/taler-util/src/helpers.ts b/packages/taler-util/src/helpers.ts
index 53a9a43d4..089602c9d 100644
--- a/packages/taler-util/src/helpers.ts
+++ b/packages/taler-util/src/helpers.ts
@@ -110,3 +110,18 @@ export function strcmp(s1: string, s2: string): number {
export function j2s(x: any): string {
return JSON.stringify(x, undefined, 2);
}
+
+/**
+ * Use this to filter null or undefined from an array in a type-safe fashion
+ *
+ * example:
+ * const array: Array<T | undefined> = [undefined, null]
+ * const filtered: Array<T> = array.filter(notEmpty)
+ *
+ * @param value
+ * @returns
+ */
+export function notEmpty<T>(value: T | null | undefined): value is T {
+ return value !== null && value !== undefined;
+}
+