Array-like value (any value with length
property)
Restricted array-like confirmation. Returns true for every value that meets following contraints
- is an object (or with
allowString
option, a string) - is not a function
- Exposes
length
that meetsarray-length
constraints
const isArrayLike = require("type/array-like/is");
isArrayLike([]); // true
isArrayLike({}); // false
isArrayLike({ length: 0 }); // true
isArrayLike("foo"); // false
isArrayLike("foo", { allowString: true }); // true
If given argument is an array-like, it is returned back. Otherwise TypeError
is thrown.
const ensureArrayLike = require("type/array-like/ensure");
ensureArrayLike({ length: 0 }); // { length: 0 }
ensureArrayLike("foo", { allowString: true }); // "foo"
ensureArrayLike({}); // Thrown TypeError: null is not an iterable