validatePositiveIntegersIncludingZero

It validates the integer number if it's positive or 0. Promise will resolve the integer if valid, else, it will reject PositiveIncludingZeroValidationError.
Parameter ListReturnsRejection Errors
  • supposedPositiveIncludingZeroInteger: number
  • tuple: Array (optional)
Promise<number || Array>
Related FunctionsFunction Signature
function validatePositiveIntegersIncludingZero(number[, tuple]): Promise<number || Array>
1 2 3 4 5 import { validatePositiveIntegersIncludingZero } from "puddy-m/lib/validators/complexValidators"; validatePositiveIntegersIncludingZero(100).then((validatedInteger) => console.log(validatedInteger) ); // prints 100
1 2 3 4 5 6 import { validateString } from "puddy-m/lib/validators"; import { validatePositiveIntegersIncludingZero } from "puddy-m/lib/validators/complexValidators"; validatePositiveIntegersIncludingZero(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 14 import { validatePositiveIntegersIncludingZero } from "puddy-m/lib/validators/complexValidators"; const run = async () => { try { const positiveIncludingZeroNumber = await validatePositiveIntegersIncludingZero(100); console.log(positiveIncludingZeroNumber); // prints 0 } catch (e) { console.log(e); } }; run();
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import { validatePositiveIntegersIncludingZero } from "puddy-m/lib/validators/complexValidators"; const run = async () => { try { const positiveIncludingZeroNumber = await validatePositiveIntegersIncludingZero(-1); console.log(positiveIncludingZeroNumber); // Because number is negative, it will throw } catch (e) { // Throws an PositiveIntegersIncludingZeroError console.log(e); } }; run();