All files / utils getFigure.ts

100% Statements 11/11
100% Branches 6/6
100% Functions 1/1
100% Lines 11/11

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 171x   1x 10x   9x   9x 22x 22x   22x 9x   10x 10x  
import { trimSpaces } from "./trimSpaces";
 
export const getFigure = <T>(map: Record<string, T>, name?: string) => {
	if (!name) return map.default;
 
	const deviceKeys = Object.keys(map);
 
	const figure = deviceKeys.find((key) => {
		const parsedName = trimSpaces(name).toLowerCase();
		const parsedKey = key.toLowerCase();
 
		return parsedName.toLowerCase().includes(parsedKey);
	});
 
	return figure ? map[figure as keyof typeof map] : map.default;
};