validatePositiveIntegers
Description
It validates the integer number if it's positive, not including 0. It rejects a PositiveIntegersError if integer is lower or equal 0.
If you want to include 0, you need to use the validateNegativeIntegersIncludingZero instead.
Parameter List | Returns | Rejection Errors |
---|---|---|
| Promise<number || Array> | |
Related Functions | Function Signature | |
function validatePositiveIntegers(supposedPositiveInteger[, tuple]): Promise<number || Array> |
Examples
1
2
3
4
5
import { validatePositiveIntegers } from "puddy-m/lib/validators/complexValidators";
validatePositiveIntegers(100).then((validatedInteger) =>
console.log(validatedInteger)
); // prints 100
1
2
3
4
5
6
import { validateString } from "puddy-m/lib/validators";
import { validatePositiveIntegers } from "puddy-m/lib/validators/complexValidators";
validatePositiveIntegers(100, [])
.then((tuple) => validateString("string", tuple))
.then((tuple) => console.log(tuple)); // prints [100, 'string']
1
2
3
4
5
6
7
8
9
10
11
12
13
import { validatePositiveIntegers } from "puddy-m/lib/validators/complexValidators";
const run = async () => {
try {
const positiveNumber = await validatePositiveIntegers(100);
console.log(positiveNumber); // prints 100
} catch (e) {
console.log(e);
}
};
run();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { validatePositiveIntegers } from "puddy-m/lib/validators/complexValidators";
const run = async () => {
try {
const positiveNumber = await validatePositiveIntegers(0);
console.log(positiveNumber); // Because zero is not included, it will throw
} catch (e) {
// Throws an PositiveIntegersError
console.log(e);
}
};
run();