UNPKG

nhb-toolbox

Version:

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

51 lines 2.87 kB
import type { Any, FlattenPartial, PartialOrRequired } from '../types/index'; import type { GenericObject, 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 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<T extends GenericObject, B extends PartialOrRequired = 'required'>(object: T, options?: SanitizeOptions<T>, _return?: B): B extends 'partial' ? FlattenPartial<T> : T; /** * * 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 - A mixed array that may contain arrays, objects or other data types. * @param options - Options to trim and filter values. * @param _return - By default return type is as it is, passing this parameter `partial` makes the return type `Partial<T>`. * @returns A new sanitized array with the specified modifications. */ export declare function sanitizeData<T extends GenericObject, B extends PartialOrRequired = 'required'>(array: T[], options?: SanitizeOptions<T>, _return?: B): B extends 'partial' ? FlattenPartial<T>[] : T[]; /** * * 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; }; //# sourceMappingURL=sanitize.d.ts.map