number primitive that conforms as valid array length
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
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