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.
86 lines • 3.45 kB
text/typescript
/** @typedef {Object.<string, (val: any) => *>} ExtendObjType */
/** @typedef {Array<[string, (val: any) => *]>} ExtendObjTypeArray */
/**
* Adds new type checkers to the typeValidator without overwriting existing ones.
*
* Accepts either an object with named functions or an array of [key, fn] arrays.
* If no index is provided, the type is inserted just before 'object' (if it exists), or at the end.
*
* @param {ExtendObjType|ExtendObjTypeArray} newItems
* - 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.
*
* @example
* extendObjType({
* htmlElement2: val => typeof HTMLElement !== 'undefined' && val instanceof HTMLElement
* });
*
* @example
* extendObjType([
* ['alpha', val => typeof val === 'string'],
* ['beta', val => Array.isArray(val)]
* ]);
*/
export function extendObjType(newItems: ExtendObjType | ExtendObjTypeArray, 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 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 function cloneObjTypeOrder(): string[];
/**
* Checks the type of a given object or returns its type as a string.
*
* @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`.
*
* @example
* objType([], 'array'); // true
* objType({}, 'object'); // true
* objType('hello'); // "string"
* objType(undefined); // null
*/
export function objType(obj: any, type?: string): boolean | string | null;
/**
* Checks the type of a given object and returns the validation value if a known type is detected.
*
* @param {*} obj - The object to check or identify.
* @returns {{ valid:*; type: string | null }} - Returns the type result.
*/
export function checkObj(obj: any): {
valid: any;
type: string | null;
};
/**
* Creates a clone of the functions from the `typeValidator` object.
* It returns a new object where the keys are the same and the values are the cloned functions.
*/
export function getCheckObj(): {
[k: string]: any;
};
export type ExtendObjType = {
[x: string]: (val: any) => any;
};
export type ExtendObjTypeArray = Array<[string, (val: any) => any]>;
import { countObj } from './objChecker.mjs';
import { isJsonObject } from './objChecker.mjs';
export { countObj, isJsonObject };
//# sourceMappingURL=objFilter.d.mts.map