@storm-stack/utilities
Version:
This package includes various base utility class and various functions to assist in the development process.
34 lines (33 loc) • 820 B
TypeScript
import { DeepKey, DeepValue } from "@storm-stack/types";
/**
* Flattens a nested object into a single level object with dot-separated keys.
*
* @example
* ```typescript
* const nestedObject = {
* a: {
* b: {
* c: 1
* }
* },
* d: [2, 3]
* };
*
* const flattened = flattenObject(nestedObject);
* console.log(flattened);
* // Output:
* // {
* // 'a.b.c': 1,
* // 'd.0': 2,
* // 'd.1': 3
* // }
* ```
*
* @param object - The object to flatten.
* @returns - The flattened object.
*/
export declare function unflattenObject<TObject extends Record<string, any> = Record<string, any>, TDeepKeyObject extends {
[TKey in DeepKey<TObject>]: DeepValue<TObject, TKey>;
} = {
[TKey in DeepKey<TObject>]: DeepValue<TObject, TKey>;
}>(deepKeyObject: TDeepKeyObject): TObject;