Number
March 5, 2020 ยท View on GitHub
number primitive
number/coerce
Restricted number coercion. Returns number presentation for every value that follows below constraints
- is implicitly coercible to number
- is neither
nullnorundefined - is not
NaNand 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
number/ensure
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