From 65871e32c7cb9a39c87a90945deb4f42f30daec0 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Thu, 8 Sep 2022 16:49:59 -0400 Subject: [PATCH] fix(striker-ui): enable isEmpty to check objects --- striker-ui/lib/isEmpty.ts | 6 +++++- striker-ui/types/MapToType.d.ts | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/striker-ui/lib/isEmpty.ts b/striker-ui/lib/isEmpty.ts index d2fd1970..23be50ce 100644 --- a/striker-ui/lib/isEmpty.ts +++ b/striker-ui/lib/isEmpty.ts @@ -1,4 +1,7 @@ -type IsEmptyTypeMap = Pick; +type IsEmptyTypeMap = Pick< + MapToType, + 'number' | 'object' | 'string' | 'undefined' +>; type MapToValueIsEmptyFunction = { [TypeName in keyof IsEmptyTypeMap]: ( @@ -8,6 +11,7 @@ type MapToValueIsEmptyFunction = { const MAP_TO_VALUE_IS_EMPTY_FUNCTION: MapToValueIsEmptyFunction = { number: (value = 0) => value === 0, + object: (value) => Object.keys(value).length === 0, string: (value = '') => value.trim().length === 0, undefined: () => true, }; diff --git a/striker-ui/types/MapToType.d.ts b/striker-ui/types/MapToType.d.ts index e400ab34..2cf693ff 100644 --- a/striker-ui/types/MapToType.d.ts +++ b/striker-ui/types/MapToType.d.ts @@ -1,6 +1,7 @@ declare type MapToType = { boolean: boolean; number: number; + object: Record; string: string; undefined: undefined; };