validateRepeatedConsecutiveCharsInString

It resolves the str parameter if it has consecutively repeating chars in it.
  • If the repeating number of times is less than the tolerance, then it will reject.
  • Repeating must be at least equal the tolerance.
  • Repeating is different from times it appears in a row.
  • If the string "aaaaaa" has the letter 'a' appearing 6 times in a row, then it means that it repeated only 5, as the first time isn't a repeatition.
  • Repeatition = times it appears - 1.
  • Parameter ListReturnsRejection Errors
    • str: string
    • tolerance: number
    • tuple: Array (optional)
    Promise<string || Array>
    Related FunctionsFunction Signature
    function validateRepeatedConsecutiveCharsInString(str, tolerance[, tuple]): Promise<string || number>
    1 2 3 import { validateRepeatedConsecutiveCharsInString } from "puddy-m/lib/validators/complexValidators"; validateRepeatedConsecutiveCharsInString("aaaaf").then(console.log); // prints 'aaaaf'
    1 2 3 4 5 6 7 import { validateRepeatedConsecutiveCharsInString } from "puddy-m/lib/validators/complexValidators"; import { validateString } from "puddy-m/lib/validators"; // '1' one must be repeated at least once, so '11' is invalid. validateRepeatedConsecutiveCharsInString("11", 1).then( (repeatedWithTolerance) => console.log(repeatedWithTolerance) );
    1 2 3 4 5 import { validateRepeatedConsecutiveCharsInString } from "puddy-m/lib/validators/complexValidators"; validateRepeatedConsecutiveCharsInString("aab", 1, []) .then((tuple) => validateString("Foo", tuple)) .then((tuple) => console.log(tuple)); // prints ['aab', 'Foo']
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import { validateRepeatedConsecutiveCharsInString } from "puddy-m/lib/validators/complexValidators"; const run = async () => { try { const repeatedChars = await validateRepeatedConsecutiveCharsInString( "foo", 1 ); // 'o' is expected to repeat only once, which is correct. console.log(repeatedChars); } catch (e) { console.log(e); } }; run();
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import { validateRepeatedConsecutiveCharsInString } from "puddy-m/lib/validators/complexValidators"; const run = async () => { try { const repeatingChars = await validateRepeatedConsecutiveCharsInString( "fooo", 5 ); // Because no characters repeated at least 5 times, it will throw console.log(repeatingChars); } catch (e) { // Throws an RepeatedConsecutiveCharsInStringValidationError console.log(e); } }; run();