sfcode An Online Competing and Development Environment

Natural Number

Natural number primitive

# <tt>natural-number/coerce</tt>

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

# <tt>natural-number/ensure</tt>

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