number primitive
Restricted number coercion. Returns number presentation for every value that follows below constraints
- is implicitly coercible to number
- is neither
null
norundefined
- is not
NaN
and doesn't coerce toNaN
For all other values null
is returned
const coerceToNumber = require("type/number/coerce");
coerceToNumber("12"); // 12
coerceToNumber({}); // null
coerceToNumber(null); // null
If given argument is a number coercible value (via number/coerce
) returns result number.
Otherwise TypeError
is thrown.
const ensureNumber = require("type/number/ensure");
ensureNumber(12); // "12"
ensureNumber(null); // Thrown TypeError: null is not a number