UNPKG

es-toolkit

Version:

A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.

44 lines 1.3 kB
//#region src/compat/array/size.d.ts /** * Returns the length of an array, string, or object. * * This function takes an array, string, or object and returns its length. * For arrays and strings, it returns the number of elements or characters, respectively. * For objects, it returns the number of enumerable properties. * * @template T - The type of the input value. * @param target - The value whose size is to be determined. It can be an array, string, or object. * @returns The size of the input value. * * @example * const arr = [1, 2, 3]; * const arrSize = size(arr); * // arrSize will be 3 * * const str = 'hello'; * const strSize = size(str); * // strSize will be 5 * * const obj = { a: 1, b: 2, c: 3 }; * const objSize = size(obj); * // objSize will be 3 * * const emptyArr = []; * const emptyArrSize = size(emptyArr); * // emptyArrSize will be 0 * * const emptyStr = ''; * const emptyStrSize = size(emptyStr); * // emptyStrSize will be 0 * * const emptyObj = {}; * const emptyObjSize = size(emptyObj); * // emptyObjSize will be 0 * * const arrayLike = { length: 3 }; * const arrayLikeSize = size(arrayLike); * // arrayLikeSize will be 3 */ declare function size(collection: object | string | null | undefined): number; //#endregion export { size };