Skip to content

Latest commit

 

History

History
27 lines (18 loc) · 838 Bytes

array-length.md

File metadata and controls

27 lines (18 loc) · 838 Bytes

Array length

number primitive that conforms as valid array length

array-length/coerce

Follows safe-integer/coerce but returns null in place of values which are below 0

const coerceToArrayLength = require("type/safe-integer/coerce");

coerceToArrayLength("12.95"); // 12
coerceToArrayLength(9007199254740992); // null
coerceToArrayLength(null); // null

array-length/ensure

If given argument is an array length coercible value (via array-length/coerce) returns result number. Otherwise TypeError is thrown.

const ensureArrayLength = require("type/array-length/ensure");

ensureArrayLength(12.93); // "12"
ensureArrayLength(9007199254740992); // Thrown TypeError: 9007199254740992 is not a valid array length