Integer number primitive
Follows finite/coerce
additionally stripping decimal part from the number
const coerceToInteger = require("type/integer/coerce");
coerceToInteger("12.95"); // 12
coerceToInteger(Infinity); // null
coerceToInteger(null); // null
If given argument is an integer coercible value (via integer/coerce
) returns result number.
Otherwise TypeError
is thrown.
const ensureInteger = require("type/integer/ensure");
ensureInteger(12.93); // "12"
ensureInteger(null); // Thrown TypeError: null is not an integer