@andranik-arakelyan/js-utilities
Version:
Javascript utilities
35 lines (34 loc) • 784 B
TypeScript
/**
* Flattens a nested object into a flat object with dot notation keys.
*
* @param obj - The object to flatten
* @param prefix - Internal parameter for recursion (do not use)
* @returns A flattened object with dot notation keys
*
* @example
* ```ts
* const nested = {
* user: {
* profile: {
* name: 'John',
* age: 30
* },
* settings: {
* theme: 'dark'
* }
* },
* app: {
* version: '1.0.0'
* }
* };
*
* const flattened = flattenObject(nested);
* // {
* // 'user.profile.name': 'John',
* // 'user.profile.age': 30,
* // 'user.settings.theme': 'dark',
* // 'app.version': '1.0.0'
* // }
* ```
*/
export declare function flattenObject(obj: Record<string, any>, prefix?: string): Record<string, any>;