validateListOfInstance
Description
it validates if the list contains only elements that are instance of InstanceReference. Suppose you have a class in your code called User, then InstanceReference would be assigned User (capital U, the same way the class name has been declared). It Resolves the list if all elements of the list is of instance of InstanceReference.
Parameter List | Returns | Rejection Errors |
---|---|---|
| Promise<Array<*> || Array<Array<*>>> | |
Related Functions | Function Signature | |
function validateListOfInstance(InstanceReference, list[, tuple]): Promise<Array<*> || Array<Array<*>>> |
Examples
1
2
3
4
5
6
7
8
9
10
import { validateListOfInstance } from "puddy-m/lib/validators/listValidators";
class User {}
const user = new User();
const user2 = new User();
validateListOfInstance(User, [user, user2]).then((userList) =>
console.log(userList)
); // print [ User {}, User {} ]
1
2
3
4
5
6
7
8
9
10
11
import { validateListOfInstance } from "puddy-m/lib/validators/listValidators";
import { validateString } from "puddy-m/lib/validators";
class User {}
const user = new User();
const user2 = new User();
validateListOfInstance(User, [user, user2], [])
.then((tuple) => validateString("string", tuple))
.then((tuple) => console.log(tuple)); // print [ [User {}, User {}], 'string' ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { validateListOfInstance } from "puddy-m/lib/validators/listValidators";
const run = async () => {
try {
class User {}
const user = new User();
const user2 = new User();
const validatedUserList = await validateListOfInstance(User, [user, user2]);
console.log(validatedUserList);
} catch (e) {
// Throws IntegerValidationErrorToValue
console.log(e);
}
};
run();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { validateListOfInstance } from "puddy-m/lib/validators/listValidators";
const run = async () => {
try {
class User {}
const validatedUserList = await validateListOfInstance(User, [1, 2]);
console.log(validatedUserList);
} catch (e) {
// Throws InstanceValidationError
console.log(e);
}
};
run();