validateRepeatedConsecutiveCharsInString
Description
It resolves the str parameter if it has consecutively repeating chars in it.
Parameter List | Returns | Rejection Errors |
---|---|---|
| Promise<string || Array> | |
Related Functions | Function Signature | |
function validateRepeatedConsecutiveCharsInString(str, tolerance[, tuple]): Promise<string || number> |
Examples
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();