validateNotInstance
Description
This function takes an Instance Reference which is a class/function name and the supposedNotInstance paramter which is the instance that will be validated against the Reference. It will only resolve if the supposedNotInstance is NOT an instance of the Reference.
For example, say you have a class User. If you pass an instance of User, this function will reject NotInstanceValidationError.
Parameter List | Returns | Rejection Errors |
---|---|---|
| Promise<* || Array> | |
Related Functions | Function Signature | |
function validateNotInstance(InstanceRef, supposedNotInstance[, tuple]): Promise<* || Array> |
Examples
1
2
3
4
5
6
import { validateNotInstance } from "puddy-m/lib/validators";
class User {}
const user = new User();
// Will resolve since user is not instance of an Array
validateNotInstance(Array, user).then(console.log); // Prints user{}
1
2
3
4
5
6
7
import { validateNotInstance, validateString } from "puddy-m/lib/validators";
class User {}
const user = new User();
validateNotInstance(Array, user, [])
.then((tuple) => validateString("user is not an array", tuple))
.then(console.log); // prints [user{}, 'user is not an array']
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { validateNotInstance } from "puddy-m/lib/validators";
const run = async () => {
try {
class User {}
const user = new User();
const notArray = await validateNotInstance(Array, user);
console.log(notArray);
} catch (e) {
console.log(e);
}
};
run();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { validateNotInstance } from "puddy-m/lib/validators";
const run = async () => {
try {
class User {}
const user = new User();
const notArray = await validateNotInstance(User, user); // As user is instance of User, this function will throw
console.log(notArray);
} catch (e) {
// Throws NotInstanceValidationError
console.log(e);
}
};
run();