Skip to content

Latest commit

 

History

History
27 lines (18 loc) · 762 Bytes

natural-number.md

File metadata and controls

27 lines (18 loc) · 762 Bytes

Natural Number

Natural number primitive

natural-number/coerce

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

natural-number/ensure

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