isArrayLikeObject
lang
This method is like isArrayLike except that it also checks if value is an object.
Installation
Import
import { isArrayLikeObject } from '@tulx/utils';Source Code
Implementation
/**
* This method is like isArrayLike except that it also checks if value is an object.
*
* @param value - The value to check.
* @returns Returns true if value is an array-like object, else false.
*
* @example
* ```ts
* isArrayLikeObject([1, 2, 3]); // true
* isArrayLikeObject(document.body.children); // true
* isArrayLikeObject('abc'); // false
* isArrayLikeObject(() => {}); // false
* ```
*/
export function isArrayLikeObject(
value: unknown
): value is ArrayLike<unknown> & object {
return (
typeof value === 'object' &&
value !== null &&
!Array.isArray(value) &&
typeof (value as { length?: unknown }).length === 'number' &&
(value as { length: number }).length >= 0 &&
(value as { length: number }).length % 1 === 0 &&
(value as { length: number }).length <= Number.MAX_SAFE_INTEGER
);
}
Example
import { isArrayLikeObject } from '@tulx/utils';
isArrayLikeObject([1, 2, 3]); // true
isArrayLikeObject(document.body.children); // true
isArrayLikeObject('abc'); // false
isArrayLikeObject(() => {}); // falseRelated Functions
castArray
Casts value as an array if it's not one.
clone
Creates a shallow clone of value.
cloneDeep
This method is like clone except that it recursively clones value.
cloneDeepWith
This method is like cloneDeep except that it accepts customizer which is invoked to produce the cloned value.
cloneWith
This method is like clone except that it accepts customizer which is invoked to produce the cloned value.
conformsTo
Checks if object conforms to source by invoking the predicate properties of source with the corresponding property values of object.