UNPKG

@tmlmobilidade/utils

Version:

A collection of utility functions and helpers for the TML Mobilidade Go monorepo, providing common functionality for batching operations, caching, HTTP requests, object manipulation, permissions, and more.

22 lines (21 loc) 867 B
type DotPrefix<T extends string, U extends string> = '' extends T ? U : `${T}.${U}`; type NestedKeys<T, Prefix extends string = ''> = { [K in keyof T & string]: T[K] extends Record<string, any> ? DotPrefix<Prefix, K> | NestedKeys<T[K], DotPrefix<Prefix, K>> : DotPrefix<Prefix, K>; }[keyof T & string]; export type FlattenObjectType<T> = Record<NestedKeys<T>, any>; /** * Flattens an object using dot notation for nested fields. * Arrays are treated as leaf nodes and are not traversed. * Includes both nested objects and their individual properties as separate keys. * * Example: * flattenObject({ a: { b: 1, c: { d: 2 } } }) * -> { * 'a': { b: 1, c: { d: 2 } }, * 'a.b': 1, * 'a.c': { d: 2 }, * 'a.c.d': 2 * } */ export declare function flattenObject<T extends object>(input: T): FlattenObjectType<T>; export {};