fix(striker-ui): allow undefined in isEmpty element(s)

main
Tsu-ba-me 2 years ago
parent 558ec9ef67
commit 89ad9d34e9
  1. 10
      striker-ui/lib/isEmpty.ts

@ -1,14 +1,16 @@
type MapToValueIsEmptyFunction = {
[TypeName in keyof MapToType]: (value: MapToType[TypeName]) => boolean;
[TypeName in keyof MapToType]: (
value: MapToType[TypeName] | undefined,
) => boolean;
};
const MAP_TO_VALUE_IS_EMPTY_FUNCTION: MapToValueIsEmptyFunction = {
number: (value: number) => value === 0,
string: (value: string) => value.trim().length === 0,
number: (value = 0) => value === 0,
string: (value = '') => value.trim().length === 0,
};
const isEmpty = <TypeName extends keyof MapToType>(
values: Array<MapToType[TypeName]>,
values: Array<MapToType[TypeName] | undefined>,
{ not, fn = 'every' }: { not?: boolean; fn?: 'every' | 'some' } = {},
): boolean =>
values[fn]((value) => {

Loading…
Cancel
Save