nhb-toolbox
Version:
A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.
51 lines (50 loc) • 3.07 kB
TypeScript
import type { Any, PartialOrRequired } from '../types/index';
import type { DotNotationKey, GenericObject, SanitizedData, SanitizeOptions } from './types';
/**
* * Trims all the words in a string.
*
* @param input String to sanitize.
* @returns Sanitized string .
*/
export declare function sanitizeData(input: string): string;
/**
* * Trims all the words in an array of strings.
*
* @param input Array of strings to sanitize.
* @returns Sanitized array of strings.
*/
export declare function sanitizeData(input: string[]): string[];
/**
* * Sanitizes a deeply nested array that may contain arrays, objects or other (mixed) data types.
* * Preserves structure while removing empty values and trimming strings and other operations.
*
* @param array - An array of objects that may contain arrays, objects or other data types.
* @param options - Options that define which keys to ignore, whether to trim string values, and whether to exclude nullish, falsy or empty values.
* @param _return - By default return type is as it is, passing this parameter `partial` makes the return type `$DeepPartial<T>`.
* @returns A new sanitized array with the specified modifications.
*/
export declare function sanitizeData<Data extends GenericObject, Ignored extends DotNotationKey<Data> = never, PoR extends PartialOrRequired = 'required'>(array: Data[], options?: SanitizeOptions<Data, Ignored>, _return?: PoR): Array<SanitizedData<Data, Ignored, PoR>>;
/**
* * Sanitizes an object by ignoring specified keys and trimming string values based on options provided.
* * Also excludes nullish values (`null`, `undefined`), falsy (`nullish` + `0` & `""`) or empty values (`object`, `array`) if specified.
*
* @param object - The object to sanitize.
* @param options - Options that define which keys to ignore, whether to trim string values, and whether to exclude nullish, falsy or empty values.
* @param _return - By default return type is as it is, passing this parameter `true` makes the return type `Partial<T>`.
* @returns A new object with the specified modifications.
*/
export declare function sanitizeData<Data extends GenericObject, Ignored extends DotNotationKey<Data> = never, PoR extends PartialOrRequired = 'required'>(object: Data, options?: SanitizeOptions<Data, Ignored>, _return?: PoR): SanitizedData<Data, Ignored, PoR>;
/**
* * Parse an object of stringified values into their appropriate primitive types.
*
* @description
* - Attempts to convert string values into `boolean`, `number`, or JSON-parsed objects/arrays.
* - Non-string values except arrays/objects are left unchanged. Nested arrays/objects are parsed recursively.
*
* @param object - The object with potentially stringified primitive values.
* @param parseNested - Whether to convert stringified primitives in nested arrays/objects. (default: `true`).
* @returns A new object with parsed values converted to their original types.
*/
export declare function parseObjectValues<T extends GenericObject>(object: T, parseNested?: boolean): {
[K in keyof T]: Any;
};