validateInteger
Description
It resolves the the parameter supposedInteger if it's a number type and if it's an integer. It uses the Number.isInteger method to determine if the number is integer.
| Parameter List | Returns | Rejection Errors | 
|---|---|---|
  | Promise<number || Array> | |
| Related Functions | Function Signature | |
function validateInteger(supposedInteger[, tuple]): Promise<number || Array> | ||
Examples
1
2
3
import { validateInteger } from "puddy-m/lib/validators/complexValidators";
validateInteger(100).then((validatedInteger) => console.log(validatedInteger)); // prints 1001
2
3
4
5
6
import { validateString } from "puddy-m/lib/validators";
import { validateInteger } from "puddy-m/lib/validators/complexValidators";
validateInteger(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 { validateInteger } from "puddy-m/lib/validators/complexValidators";
const run = async () => {
  try {
    const validatedInteger = await validateInteger(100);
    console.log(validatedInteger); // prints 100
  } catch (e) {
    console.log(e);
  }
};
run();1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { validateInteger } from "puddy-m/lib/validators/complexValidators";
const run = async () => {
  try {
    const validatedInteger = await validateInteger(1.5);
    console.log(validatedInteger);
  } catch (e) {
    // Throws an IntegerValidationError
    console.log(e);
  }
};
run();