UNPKG

tiny-ai-api

Version:

A customizable and extensible client api for managing conversations and AI interactions, currently supporting the **Google Gemini** API — with flexibility to support any similar AI APIs.

29 lines (28 loc) 1.26 kB
/** * 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>;