From 0f27b62d0d8651b824734ca87bda3c6337fc116d Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sun, 31 Oct 2021 12:31:15 -0400 Subject: [PATCH] Adds array helper --- src/system/array.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/system/array.ts b/src/system/array.ts index c20ffda..0e3e947 100644 --- a/src/system/array.ts +++ b/src/system/array.ts @@ -30,6 +30,10 @@ export function countUniques(source: T[], accessor: (item: T) => string): Rec return uniqueCounts; } +export function ensure(source: T | T[] | undefined): T[] | undefined { + return source == null ? undefined : Array.isArray(source) ? source : [source]; +} + export function filterMap( source: T[], predicateMapper: (item: T, index: number) => TMapped | null | undefined,