validateTrim
Description
Gets an string and removes the empty spaces around it. It uses the String.prototype.trim() to resolve the trimmed version of the string.
Parameter List | Returns | Rejection Errors |
---|---|---|
| Promise<string || Array> | |
Related Functions | Function Signature | |
function validateTrim(supposedString[, tuple]): Promise<string || Array> |
Examples
1
2
3
import { validateTrim } from "puddy-m/lib/validators/complexValidators";
validateTrim(" aaa ").then(console.log); // prints 'aaa' without the spaces around
1
2
3
4
5
import { validateTrim } from "puddy-m/lib/validators/complexValidators";
validateTrim(" ____|_____ ", [])
.then((tuple) => validateTrim(" ", tuple))
.then(console.log); // prints ['____|_____', '']
1
2
3
4
5
6
7
8
9
10
11
12
13
import { validateTrim } from "puddy-m/lib/validators/complexValidators";
const run = async () => {
try {
const trimmedStr = await validateTrim("string ");
console.log(trimmedStr); // prints 'string'
} catch (e) {
console.log(e);
}
};
run();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { validateTrim } from "puddy-m/lib/validators/complexValidators";
const run = async () => {
try {
const trimmedStr = await validateTrim(55);
console.log(trimmedStr); // Because it's not a string, it will throw
} catch (e) {
// Throw StringValidationError
console.log(e);
}
};
run();