validateNegativeIntegersIncludingZero
Description
It resolves the parameter if it's an integer lower or equal 0. Rejects if the parameter isn't an integer or if integer is greater than 0.
Parameter List | Returns | Rejection Errors |
---|---|---|
| Promise<number || Array> | |
Related Functions | Function Signature | |
function validateNegativeIntegersIncludingZero(supposedPositiveIncludingZeroInteger[, tuple]): Promise<number || Array> |
Examples
1
2
3
4
5
import { validateNegativeIntegersIncludingZero } from "puddy-m/lib/validators/complexValidators";
validateNegativeIntegersIncludingZero(0).then((validatedInteger) =>
console.log(validatedInteger)
); // prints 0
1
2
3
4
5
6
import { validateString } from "puddy-m/lib/validators";
import { validateNegativeIntegersIncludingZero } from "puddy-m/lib/validators/complexValidators";
validateNegativeIntegersIncludingZero(0, [])
.then((tuple) => validateString("string", tuple))
.then((tuple) => console.log(tuple)); // prints [0, 'string']
1
2
3
4
5
6
7
8
9
10
11
12
13
import { validateNegativeIntegersIncludingZero } from "puddy-m/lib/validators/complexValidators";
const run = async () => {
try {
const validatedNegativeInteger = await validateNegativeIntegersIncludingZero(0);
console.log(validatedNegativeInteger); // prints 0
} catch (e) {
console.log(e);
}
};
run();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { validateNegativeIntegersIncludingZero } from "puddy-m/lib/validators/complexValidators";
const run = async () => {
try {
const validatedNegativeInteger = await validateNegativeIntegersIncludingZero(1);
console.log(validatedNegativeInteger);
} catch (e) {
// Throws an IntegerValidationErrorToValue
console.log(e);
}
};
run();