rc-js-util
Version:
A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.
21 lines (20 loc) • 477 B
text/typescript
/**
* @public
* Replaces length 0 `ArrayLike` with `undefined`.
* @returns `array` if it's an `ArrayLike` of length greater than 0, otherwise `undefined`.
*
* @remarks
* See {@link arrayNormalizeEmptyToUndefined}.
*/
export function arrayNormalizeEmptyToUndefined<TArray extends ArrayLike<unknown>>
(
array: TArray | null | undefined
)
: TArray | undefined
{
if (array == null || array.length === 0)
{
return undefined;
}
return array;
}