UNPKG

passcode-validator

Version:

Validate passwords and numeric codes

20 lines (16 loc) 516 B
import Rule from './base/Rule'; /** * Rule to forbid some strings. For instance, the username. */ class ForbiddenText extends Rule { private readonly texts: string[]; constructor(texts: string[], message?: string) { super(message); this.texts = texts; } validate(subject: string) { const subjectLowerCased = subject.toLowerCase(); this.completed = this.texts.every(value => !subjectLowerCased.includes(value.toLowerCase())); } } export default ForbiddenText;