Natural number primitive
Follows integer/coerce
but returns null
for values below 0
const coerceToNaturalNumber = require("type/natural-number/coerce");
coerceToNaturalNumber("12.95"); // 12
coerceToNaturalNumber(-120); // null
coerceToNaturalNumber(null); // null
If given argument is a natural number coercible value (via natural-number/coerce
) returns result number.
Otherwise TypeError
is thrown.
const ensureNaturalNumber = require("type/natural-number/ensure");
ensureNaturalNumber(12.93); // "12"
ensureNaturalNumber(-230); // Thrown TypeError: null is not a natural number