Finite number primitive
Follows number/coerce
additionally rejecting Infinity
and -Infinity
values (null
is returned if given values coerces to them)
const coerceToFinite = require("type/finite/coerce");
coerceToFinite("12"); // 12
coerceToFinite(Infinity); // null
coerceToFinite(null); // null
If given argument is a finite number coercible value (via finite/coerce
) returns result number.
Otherwise TypeError
is thrown.
const ensureFinite = require("type/finite/ensure");
ensureFinite(12); // "12"
ensureFinite(null); // Thrown TypeError: null is not a finite number