Skip to content

Latest commit

 

History

History
33 lines (23 loc) · 971 Bytes

array-like.md

File metadata and controls

33 lines (23 loc) · 971 Bytes

Array Like

Array-like value (any value with length property)

array-like/is

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

array-like/ensure

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