Local modifications to ClusterLabs/Anvil by Alteeve
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

29 lines
739 B

type MapToValueIsEmptyFunction = {
[TypeName in keyof MapToType]: (
value: MapToType[TypeName] | undefined,
) => boolean;
};
const MAP_TO_VALUE_IS_EMPTY_FUNCTION: MapToValueIsEmptyFunction = {
number: (value = 0) => value === 0,
string: (value = '') => value.trim().length === 0,
undefined: () => true,
};
const isEmpty = <TypeName extends keyof MapToType>(
values: Array<MapToType[TypeName] | undefined>,
{ not, fn = 'every' }: { not?: boolean; fn?: 'every' | 'some' } = {},
): boolean =>
values[fn]((value) => {
const type = typeof value as TypeName;
let result = MAP_TO_VALUE_IS_EMPTY_FUNCTION[type](value);
if (not) {
result = !result;
}
return result;
});
export default isEmpty;