@stryke/helpers
Version:
A package containing miscellaneous helper functions that are used across many different Storm Software projects.
34 lines (33 loc) • 818 B
TypeScript
import type { DeepKey, DeepValue } from "@stryke/types/object";
/**
* 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 flattenObject<TObject extends Record<string, any> = Record<string, any>, TDeepKeyObject extends {
[TKey in DeepKey<TObject>]: DeepValue<TObject, TKey>;
} = {
[TKey in DeepKey<TObject>]: DeepValue<TObject, TKey>;
}>(object: TObject): TDeepKeyObject;