UNPKG

nhb-toolbox

Version:

A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.

43 lines (42 loc) 1.99 kB
import type { GenericObject } from '../object/types'; import type { Maybe } from '../types/index'; import type { Flattened } from './types'; /** * * Flattens a nested array recursively or wraps any non-array data type in an array. * * @param input - The input value, which can be a nested array or a non-array value. * @returns A fully flattened array of type `Flatten<T>`. If the input is not an array, it wraps it in a single-element array. */ export declare const flattenArray: <T>(input: T | T[]) => Flattened<T>[]; /** * @deprecated _Please, use `findAll` instance method from `Finder` class for **more advanced filtering and searching.**_ * * * Filters an array of objects based on multiple conditions for specified keys. * @param array - The array of objects to filter. * @param conditions - An object where keys represent the property names and values represent filter conditions. * The conditions can be a function `(value: T[K]) => boolean`. * @returns The filtered array of objects. * @throws `Error` If the input is not a valid array. */ export declare const filterArrayOfObjects: <T extends GenericObject>(array: T[], conditions: { [K in keyof T]?: (value: Maybe<T[K]>) => boolean; }) => T[]; /** * * Checks if a value is an empty array or an array with only empty values. * * @param value - The value to check. * @returns `true` if the value is not an array, an empty array, or an array containing only `null`, `undefined`, empty objects, or empty arrays. */ export declare const isInvalidOrEmptyArray: <T>(value: T) => boolean; /** * * Shuffle the elements of an array. * * @param array Array to shuffle. * @returns Shuffled array. */ export declare const shuffleArray: <T>(array: T[]) => T[]; /** * * Get the last element of an array. * * @param array Array to get the last element from. * @returns The last element or `undefined` if the array is empty. */ export declare const getLastArrayElement: <T>(array: T[]) => Maybe<T>;