validateNonRepeatedConsecutiveCharsInString

It resolves the str parameter if the characters don't repeat consecutively.
  • In the 'aa' string, the character 'a' is repeating once consecutively.
  • In the string 'aba', although the character 'a' appears twice, it's not consecutive.
  • This function will then validate the string 'aba', but not the string 'aa'.
  • If you want to allow a character to repeat to a certain number of times, you can assign a value to tolerance. The tolerance is concerned with the least amount of times it must repeat (times -1), and not least amount of times it appears.
  • For example, if the tolerance is 5, then the character can repeat 5 times consecutively.
  • The string 'aaaaaa' has 6 a's (1 a repeating 5 times, totalizing 6 a's).
  • In other words, if you call this function passing 'aabbbbba' and tolerance of 2, this function will reject RepeatedConsecutiveCharsInStringValidationError, since b is allowed to repeat only twice, however it's repeating 3 times.
    The usage of this permission is when you want to avoid the input to have repeated characters, for example, when you are validating a password.
    Parameter ListReturnsRejection Errors
    • str: string
    • tolerance: number
    • tuple: Array (optional)
    Promise<string || Array>
    Related FunctionsFunction Signature
    function validateNonRepeatedConsecutiveCharsInString(str, tolerance[, tuple]): Promise<string || Array>
    1 2 3 4 5 import { validateNonRepeatedConsecutiveCharsInString } from "puddy-m/lib/validators/complexValidators"; validateNonRepeatedConsecutiveCharsInString("nonrepeat").then( (nonRepeatChars) => console.log(nonRepeatChars) // prints 'nonrepeat' );
    1 2 3 4 5 6 7 import { validateNonRepeatedConsecutiveCharsInString } from "puddy-m/lib/validators/complexValidators"; import { validateString } from "puddy-m/lib/validators"; // 1 is allowed to repeat only once, so "11" is valid. validateNonRepeatedConsecutiveCharsInString("11", 1).then( (repeatedWithTolerance) => console.log(repeatedWithTolerance) );
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import { validateNonRepeatedConsecutiveCharsInString } from "puddy-m/lib/validators/complexValidators"; validateNonRepeatedConsecutiveCharsInString("ab", 0, []) .then((tuple) => validateString("Foo", tuple)) .then((tuple) => console.log(tuple)); // prints ['aab', 'foo'] const run = async () => { try { const validatedNonRepeatChars = await validateNonRepeatedConsecutiveCharsInString("foo", 1); // 'o' is allowed to repeat only once, which is correct. console.log(validatedNonRepeatChars); } catch (e) { // Throws an IntegerValidationErrorToValue console.log(e); } }; run();
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import { validateNonRepeatedConsecutiveCharsInString } from "puddy-m/lib/validators/complexValidators"; const run = async () => { try { const validatedNonRepeatChars = await validateNonRepeatedConsecutiveCharsInString("fooo", 1); // 'o' is allowed to repeat only once, so, it will throw console.log(validatedNonRepeatChars); } catch (e) { // Throws an NonRepeatedConsecutiveCharsInStringValidationError console.log(e); } }; run();