isLength
lang
Checks if value is a valid array-like length.
Installation
Import
import { isLength } from '@tulx/utils';Source Code
Implementation
/**
* Checks if value is a valid array-like length.
*
* @param value - The value to check.
* @returns Returns true if value is a valid length, else false.
*
* @example
* ```ts
* isLength(3); // true
* isLength(Number.MIN_VALUE); // false
* isLength(Infinity); // false
* isLength('3'); // false
* ```
*/
export function isLength(value: unknown): value is number {
return (
typeof value === 'number' &&
value > -1 &&
value % 1 === 0 &&
value <= Number.MAX_SAFE_INTEGER
);
}
Example
import { isLength } from '@tulx/utils';
isLength(3); // true
isLength(Number.MIN_VALUE); // false
isLength(Infinity); // false
isLength('3'); // 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.