export type TinyCloner = import('../libs/utils/TinyCloner.mjs').default; export type ExtendObjTypeFunc = (val: Value) => Result; export type ExtendObjTypeCloner = (val: Value, isDeep: boolean, cloner: TinyCloner) => Value; export type ExtendObjType = Object>; export type ExtendObjTypeValue = [string, ExtendObjTypeFunc, ExtendObjTypeCloner] | [string, ExtendObjTypeFunc]; export type ObjTypeRegistry = { /** * - The function used to validate the type. */ validator: ExtendObjTypeFunc; /** * - The function used to create a clone of the value. */ cloner: ExtendObjTypeCloner; }; /** * @typedef {import('../libs/utils/TinyCloner.mjs').default} TinyCloner */ /** * A function type used to validate a value and return a specific result. * * @template {any} Value - The type of the value being validated. * @template {any} Result - The type of the result returned by the function. * @typedef {(val: Value) => Result} ExtendObjTypeFunc */ /** * A function type used to clone a value, supporting deep cloning operations. * * @template {any} Value - The type of the value to be cloned. * @typedef {(val: Value, isDeep: boolean, cloner: TinyCloner) => Value} ExtendObjTypeCloner */ /** * A mapping of type names to their corresponding validation functions. * * @template {any} Value - The type of the value being mapped. * @typedef {Object.>} ExtendObjType */ /** * A tuple representing a type definition, containing a key, a validator, and an optional cloner. * * @template {any} Value - The type of the value. * @template {any} Result - The type of the result returned by the validator. * @typedef {[string, ExtendObjTypeFunc, ExtendObjTypeCloner]|[string, ExtendObjTypeFunc]} ExtendObjTypeValue */ /** * A registry object containing the validator and cloner for a specific type. * * @template {any} Value - The type of the value being registered. * @template {any} Result - The type of the result returned by the validator. * @typedef {Object} ObjTypeRegistry * @property {ExtendObjTypeFunc} validator - The function used to validate the type. * @property {ExtendObjTypeCloner} cloner - The function used to create a clone of the value. */ /** * Adds new type checkers to the `typeValidator` registry. * * Accepts an object of functions, an array of [key, validator] tuples, or an array of [key, validator, cloner] tuples. * If an `index` is provided, the new type is inserted at that position. * If no index is provided, it is inserted before the 'object' type or at the end of the registry. * * @template {any} Value * @template {any} Result * @param {ExtendObjType | ExtendObjTypeValue[] | ExtendObjTypeValue} ni * - New type validators to be added. * @param {number} [index] - Optional. Position at which to insert each new type. Ignored if the type already exists. * @returns {string[]} - A list of successfully added type names. * @throws {TypeError} If `ni` is not an object/array, if `index` is not a number, if a key is not a string, or if a validator is not a function. * * @example * extendObjType({ * htmlElement2: val => typeof HTMLElement !== 'undefined' && val instanceof HTMLElement * }); * * @example * extendObjType([ * ['alpha', val => typeof val === 'string'], * ['beta', val => Array.isArray(val)] * ]); * * @example * extendObjType(['gamma', val => typeof val === 'number']); */ export declare function extendObjType(ni: ExtendObjType | ExtendObjTypeValue[] | ExtendObjTypeValue, index?: number): string[]; /** * Reorders the typeValidator.order array according to a custom new order. * All values in the new order must already exist in the current order. * The function does not mutate the original array structure directly. * * @param {string[]} newOrder - The new order of type names. * @returns {boolean} - Returns true if the reorder was successful, false if invalid keys were found. * * @example * reorderObjTypeOrder([ * 'string', 'number', 'array', 'object' * ]); */ export declare function reorderObjTypeOrder(newOrder: string[]): boolean; /** * Returns a cloned version of the `typeValidator.order` array. * The cloned array will not be affected by future changes to the original `order`. * * @returns {string[]} - A new array with the same values as `typeValidator.order`. */ export declare function cloneObjTypeOrder(): string[]; /** * Returns the detected type name of a given value based on predefined type validators. * * If `val` is `null`, it immediately returns `'null'`. * If no match is found, it returns `'unknown'`. * * @param {any} val - The value whose type should be determined. * @returns {string} - The type name of the value (e.g., "array", "date", "map"), or "unknown" if no match is found. * * @example * objTypeName([]); // "array" * objTypeName(null); // "null" * objTypeName(new Set()); // "set" */ export declare const objTypeName: (val: any) => string; /** * Checks the type of a given object. * * @param {*} obj - The object to check. * @param {string} [type] - Checks whether the object matches this type (e.g., "object", "array", "string"). * @returns {boolean} - Returns `true` if the type matches. * @throws {TypeError} If `type` is not a string. */ export declare function isObjType(obj: any, type?: string): boolean; /** * Checks the type of a given object or returns its type as a string. * * @deprecated Use {@link isObjType} or {@link objTypeName} instead. * @param {*} obj - The object to check or identify. * @param {string} [type] - Optional. If provided, checks whether the object matches this type (e.g., "object", "array", "string"). * @returns {boolean|string|null} - Returns `true` if the type matches, `false` if not, * the type string if no type is provided, or `null` if the object is `undefined`. * @throws {TypeError} If `type` is provided but is not a string. * * @example * objType([], 'array'); // true * objType({}, 'object'); // true * objType('hello'); // "string" * objType(undefined); // null */ export declare function objType(obj: any, type?: string): boolean | string | null; export type CheckResult = { /** * - The result of the validator function (often the value itself if truthy). */ valid: any; /** * - The name of the detected type. */ type: string | null; }; /** * @typedef {Object} CheckResult * @property {*} valid - The result of the validator function (often the value itself if truthy). * @property {string | null} type - The name of the detected type. */ /** * Evaluates an object against the registered validators and returns the first match. * * @param {unknown} obj - The object to check. * @returns {CheckResult} An object containing the validation result and the type name. */ export declare function checkObj(obj: unknown): CheckResult; /** * Returns a shallow clone of the `typeValidator.items` registry. * * @returns {Record>} A new object containing the registry data. */ export declare function getObjTypeRegistry(): Record>; /** * Returns a copy of the current order of type validators. * @returns {string[]} A new array containing the type order. */ export declare const getObjTypeOrder: () => string[]; //# sourceMappingURL=objFilter.d.mts.map