Skip to content

Latest commit

 

History

History
33 lines (22 loc) · 792 Bytes

number.md

File metadata and controls

33 lines (22 loc) · 792 Bytes

Number

number primitive

number/coerce

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

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