es-next-tools
Version:
A comprehensive utility library for JavaScript and TypeScript that provides a wide range of functions for common programming tasks, including mathematical operations, date manipulations, array and object handling, string utilities, and more.
17 lines (16 loc) • 616 B
TypeScript
export type FlattenedObject<T> = {
[K in keyof T]?: T[K] extends object ? FlattenedObject<T[K]> : T[K];
} & {
[key: string]: any;
};
/**
* Flattens a nested object structure.
* @param {T} obj - The object to flatten.
* @param {string} [prefix=''] - The prefix to use for flattened keys.
* @returns A flattened version of the input object.
* @example
* const nestedObj = { a: 1, b: { c: 2, d: { e: 3 } } };
* const flattenedObj = flatten(nestedObj);
* // { 'a': 1, 'b.c': 2, 'b.d.e': 3 }
*/
export declare function flatten<T extends Record<string, any>>(obj: T, prefix?: string): FlattenedObject<T>;