From 440ab5ba23e801b89b039f050b2acc03a5a261f4 Mon Sep 17 00:00:00 2001 From: Kiryl Koniukh <49252228+Kasmadei@users.noreply.github.com> Date: Sun, 23 Jun 2024 15:00:03 +0200 Subject: [PATCH] [#415] Changed implementation of asArray function --- src/utils/utils.tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/utils/utils.tsx b/src/utils/utils.tsx index 365ef355..ba2c55e9 100644 --- a/src/utils/utils.tsx +++ b/src/utils/utils.tsx @@ -51,15 +51,16 @@ const transformReferences = (b: Type, transformer: < return bCopy; }; -export const asArray = (objectOrArray) => { - if (!objectOrArray) { - return []; - } - if (Array.isArray(objectOrArray)) { - return objectOrArray; - } - return [objectOrArray]; -}; +/** + * Ensures that the specified argument is returned as an array at all conditions. + * + * If the argument is a single element, it is returned as a single-element array. + * @param arr Input to sanitize + */ + +export function asArray(arr: T[] | T | undefined | null): T[] { + return arr ? (Array.isArray(arr) ? arr : [arr]) : []; +} /** * Return reordered list of entities so that selected entity will become first,