All files / src/detectors value.ts

100% Statements 9/9
100% Branches 4/4
100% Functions 1/1
100% Lines 9/9

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        1561x 1561x 1561x 1561x 94x 94x 23x   71x   1467x    
import { EncodeContext } from '../encode';
import { ValueType } from '../types';
 
export function detectValueIndex(value: any, context: EncodeContext): ValueType {
	const { values } = context;
	const index = values.indexOf(value);
	const lastIndex = values.lastIndexOf(value);
	if (index !== -1) {
		const endIndex = values.length - lastIndex;
		if (endIndex < index) {
			return ValueType.VALUE_INDEX_LAST;
		}
		return ValueType.VALUE_INDEX;
	}
	return ValueType.UNKNOWN;
}