All files / src/decoders regexp.ts

100% Statements 9/9
100% Branches 2/2
100% Functions 2/2
100% Lines 8/8

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    21x     1x 1x 1x 4x 1x 1x 1x    
import { DecodeContext } from '../decode';
 
const FLAGS = ['g', 'i', 'm', 'y'];
 
export function decodeRegExp(context: DecodeContext): RegExp {
	const { reader, links } = context;
	const pattern = reader.readString();
	const flags = reader.readFlags(4);
	const flagsString = flags.map((flag, i) => (flag ? FLAGS[i] : '')).join('');
	const regexp = new RegExp(pattern, flagsString);
	links.push(regexp);
	return regexp;
}