validateObject
Description
It resolves the supposedObject parameter is an object and not an array.
Parameter List | Returns | Rejection Errors |
---|---|---|
| Promise<object> | |
Related Functions | Function Signature | |
function validateObject(supposedObject[, tuple]): Promise<object> |
Examples
1
2
3
import { validateObject } from "puddy-m/lib/validators/complexValidators";
validateObject({ foo: "bar" }).then(console.log); // prints {foo: "bar"}
1
2
3
4
5
6
import { validateString } from "puddy-m/lib/validators";
import { validateObject } from "puddy-m/lib/validators/complexValidators";
validateObject({}, [])
.then((tuple) => validateString("foo", tuple))
.then(console.log); // prints [{}, 'foo']
1
2
3
4
5
6
7
8
9
10
11
12
13
import { validateObject } from "puddy-m/lib/validators/complexValidators";
const run = async () => {
try {
const obj = await validateObject({});
console.log(obj); // prints {}
} catch (e) {
console.log(e);
}
};
run();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { validateObject } from "puddy-m/lib/validators/complexValidators";
const run = async () => {
try {
const obj = await validateObject("Not an object");
console.log(obj); // Will throw since arg is not a object
} catch (e) {
// Throws ObjectValidationError
console.log(e);
}
};
run();