All files / src/detectors link.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        1467x 1467x 1467x 1467x 8x 8x 2x   6x   1459x    
import { EncodeContext } from '../encode';
import { ValueType } from '../types';
 
export function detectLinkIndex(value: any, context: EncodeContext): ValueType {
	const { links } = context;
	const index = links.indexOf(value);
	const lastIndex = links.lastIndexOf(value);
	if (index !== -1) {
		const endIndex = links.length - lastIndex;
		if (endIndex < index) {
			return ValueType.LINK_INDEX_LAST;
		}
		return ValueType.LINK_INDEX;
	}
	return ValueType.UNKNOWN;
}