@feugene/mu
Version:
Helpful TS utilities without dependencies
26 lines (24 loc) • 641 B
text/typescript
import isFunction from '~/is/isFunction'
import isLength from '~/is/isLength'
/**
* Checks if `value` is array-like. A value is considered array-like if it's
* not a function and has a `value.length` that's an integer greater than or
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
*
* @example
*
* isArrayLike([1, 2, 3]);
* // => true
*
* isArrayLike(document.body.children);
* // => true
*
* isArrayLike('abc');
* // => true
*
* isArrayLike(()=>{}));
* // => false
*/
export default function isArrayLike(value: any): boolean {
return value != null && isLength(value.length) && !isFunction(value)
}