From b728cbd90aa3b8d6619588fd5d78f140a39b27ec Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Fri, 3 Feb 2023 03:55:33 +0100 Subject: [PATCH] Improve utils: add documentation and test of NoEmpty, return empty list if undefined --- Utils.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Utils.ts b/Utils.ts index 6ed49a2fa..1b97d00a2 100644 --- a/Utils.ts +++ b/Utils.ts @@ -268,8 +268,19 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be return hist } + /** + * Removes all empty strings from this list + * If undefined or null is given, an empty list is returned + * + * Utils.NoEmpty(undefined) // => [] + * Utils.NoEmpty(["abc","","def", null]) // => ["abc","def", null] + * + */ public static NoEmpty(array: string[]): string[] { const ls: string[] = [] + if(!array){ + return ls + } for (const t of array) { if (t === "") { continue