All files / lib enum-validation.ts

100% Statements 7/7
100% Branches 6/6
100% Functions 3/3
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18        45x 44x             10x 8x 11x      
export function isValidEnum<T extends readonly string[]>(
	value: string | undefined,
	allowedValues: T,
): value is T[number] {
	if (!value) return false;
	return allowedValues.includes(value as T[number]);
}
 
export function isValidEnumArray<T extends readonly string[]>(
	values: unknown,
	allowedValues: T,
): values is T[number][] {
	if (!Array.isArray(values)) return false;
	return values.every(
		(v) => typeof v === "string" && allowedValues.includes(v as T[number]),
	);
}