UNPKG

@kuma-ui/core

Version:

🐻 Kuma UI is a utility-first, zero-runtime CSS-in-JS library that offers an outstanding developer experience and optimized performance.

38 lines (35 loc) 989 B
import { UnionToIntersection } from './types.js'; type ObjectKey = string | number; type Pretty<T> = { [P in keyof T]: T[P]; } & {}; type NestedObject<T = unknown> = { [_: ObjectKey]: T | NestedObject<T>; }; /** * Flattening an object * input * const a = { * b: { c: 'd' } * } * * output * const a = { * b.c: 'd' * } */ declare function flattenObject<const T, T2 extends NestedObject<T>>(object: T2): FlattenObject<T2>; /** * Flattening an object * input * const a = { * b: { c: 'd' } * } * * output * const a = { * b.c: 'd' * } */ type FlattenObject<T extends NestedObject, RestKey extends string = ""> = UnionToIntersection<T extends Record<infer Key, unknown> ? Key extends ObjectKey ? T[Key] extends NestedObject ? FlattenObject<T[Key], RestKey extends "" ? Key : `${RestKey}.${Key}`> : Record<RestKey extends "" ? Key : `${RestKey}.${Key}`, T[Key]> : Record<Key, T[Key]> : never>; export { FlattenObject, NestedObject, Pretty, flattenObject };