isInteger

isInteger

Verifies if provided Verificable represents a number that is an integer. Integer values are values with the part after decimal point being 0.

The check internally is done by calling the JS function Number.isInteger().

Possible errors:

If provided Verificable is not a number:

{
    type: "isNumber",
    path: [/* ... */]
}

If provided Verificable is not a integer:

{
    type: "isInteger",
    path: [/* ... */]
}

Examples:

Each of examples uses this import statement:

const { asVerificable, isValid, isInteger } = require("verifica");

Null or undefined is not considered a number:

const verificable = asVerificable(null);
isValid(verificable, isInteger); // false

String value is not considered a number as well:

const verificable = asVerificable("123");
isValid(verificable, isInteger); // false

Infinity, -Infinity, or NaN are not considered integers:

const verificable = asVerificable(Infinity);
isValid(verificable, isInteger); // false

Numbers with non-zero decimal part are not considered integers:

const verificable = asVerificable(12345.67);
isValid(verificable, isInteger); // false

Numbers with decimal part equal to zero are considered integers:

const verificable = asVerificable(12345);
isValid(verificable, isInteger); // true

Last updated