sfcode An Online Competing and Development Environment

Number

number primitive

# <tt>number/coerce</tt>

Restricted number coercion. Returns number presentation for every value that follows below constraints

- is implicitly coercible to number
- is neither `null` nor `undefined`
- is not `NaN` and doesn't coerce to `NaN`

For all other values `null` is returned

const coerceToNumber = require("type/number/coerce");
coerceToNumber("12"); // 12
coerceToNumber({}); // null
coerceToNumber(null); // null

# <tt>number/ensure</tt>

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