All files / validators alphabetValidator.js

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

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 167x 3x 3x 1x         2x 2x 1x          
const alphabetValidator = (alphabet) => {
	const illegal = alphabet.match(new RegExp("[\\W_]"));
	if (illegal) {
		throw new Error(
			`Illegal character found in alphabet: ${alphabet.charAt(illegal.index)}`
		);
	}
 
	const duplicate = alphabet.match(new RegExp("(.+)(?=.*?\\1)", "g"));
	if (duplicate) {
		throw new Error(`Duplicate character found in alphabet: ${duplicate[0]}`);
	}
};
 
export { alphabetValidator };