validateBoolean
Description
It resolves if the parameter passed is of a boolean type, else, it will reject.
Parameter List | Returns | Rejection Errors |
---|---|---|
| Promise<boolean || Array> | |
Related Functions | Function Signature | |
function validateBoolean(supposedBoolean[, tuple]): Promise<boolean> |
Examples
1
2
3
import { validateBoolean } from "puddy-m/lib/validators";
validateBoolean(true).then((arr) => console.log(arr)); // true
1
2
3
4
5
import { validateBoolean } from "puddy-m/lib/validators";
validateBoolean(true, [])
.then((tuple) => validateString("string", tuple))
.then((tuple) => console.log(tuple)); // [true, 'string']
1
2
3
4
5
6
7
8
9
10
11
12
13
import { validateBoolean } from "puddy-m/lib/validators";
const run = async () => {
try {
const validatedBoolean = await validateBoolean(false);
console.log(validatedBoolean); // prints false
} catch (e) {
console.log(e);
}
};
run();
1
2
3
4
5
6
7
8
9
10
11
12
import { validateBoolean } from "puddy-m/lib/validators";
const run = async () => {
try {
const validatedBoolean = await validateBoolean("This is not a boolean");
} catch (e) {
//Throws BooleanValidationError
console.log(e);
}
};
run();