sfcode An Online Competing and Development Environment

Array Like

Array-like value (any value with `length` property)

# <tt>array-like/is</tt>

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 meets `array-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

# <tt>array-like/ensure</tt>

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