UNPKG

es-toolkit

Version:

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

15 lines (14 loc) 622 B
import { isNil } from "../../predicate/isNil.mjs"; import { isArrayLike } from "../predicate/isArrayLike.mjs"; import { regexMultiByte } from "../_internal/regexMultiByte.mjs"; import { unicodeSize } from "../_internal/unicodeSize.mjs"; //#region src/compat/array/size.ts function size(target) { if (isNil(target)) return 0; if (typeof target === "string") return regexMultiByte.test(target) ? unicodeSize(target) : target.length; if (isArrayLike(target)) return target.length; if (target instanceof Map || target instanceof Set) return target.size; return Object.keys(target).length; } //#endregion export { size };