tiny-essentials
Version:
Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.
29 lines • 1.3 kB
text/typescript
/**
* Counts the number of elements in an array or the number of properties in an object.
*
* @param {Array<*>|Record<string | number | symbol, any>} obj - The array or object to count.
* @returns {number} - The count of items (array elements or object keys), or `0` if the input is neither an array nor an object.
*
* @example
* countObj([1, 2, 3]); // 3
* countObj({ a: 1, b: 2 }); // 2
* countObj('not an object'); // 0
*/
export function countObj(obj: Array<any> | Record<string | number | symbol, any>): number;
/**
* Determines whether a given value is a pure JSON object (plain object).
*
* A pure object satisfies the following:
* - It is not null.
* - Its type is "object".
* - Its internal [[Class]] is "[object Object]".
* - It is not an instance of built-in types like Array, Date, Map, Set, etc.
*
* This function is useful for strict data validation when you want to ensure
* a value is a clean JSON-compatible object, free of class instances or special types.
*
* @param {unknown} value - The value to test.
* @returns {value is Record<string | number | symbol, unknown>} Returns true if the value is a pure object.
*/
export function isJsonObject(value: unknown): value is Record<string | number | symbol, unknown>;
//# sourceMappingURL=objChecker.d.mts.map