{"version":3,"file":"unflatten-object.mjs","names":[],"sources":["../src/unflatten-object.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n                       🗲 Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website:                  https://stormsoftware.com\n Repository:               https://github.com/storm-software/stryke\n Documentation:            https://docs.stormsoftware.com/projects/stryke\n Contact:                  https://stormsoftware.com/contact\n\n SPDX-License-Identifier:  Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { DeepKey, DeepValue } from \"@stryke/types\";\nimport { setField } from \"./set-field\";\n\n/**\n * Flattens a nested object into a single level object with dot-separated keys.\n *\n * @example\n * ```typescript\n * const nestedObject = {\n *   a: {\n *     b: {\n *       c: 1\n *     }\n *   },\n *   d: [2, 3]\n * };\n *\n * const flattened = flattenObject(nestedObject);\n * console.log(flattened);\n * // Output:\n * // {\n * //   'a.b.c': 1,\n * //   'd.0': 2,\n * //   'd.1': 3\n * // }\n * ```\n *\n * @param deepKeyObject - The object to flatten.\n * @returns - The flattened object.\n */\nexport function unflattenObject<\n  TObject extends Record<string, any> = Record<string, any>,\n  TDeepKeyObject extends {\n    [TKey in DeepKey<TObject>]: DeepValue<TObject, TKey>;\n  } = { [TKey in DeepKey<TObject>]: DeepValue<TObject, TKey> }\n>(deepKeyObject: TDeepKeyObject): TObject {\n  return Object.entries(deepKeyObject).reduce(\n    (ret: TObject, [key, value]: [string, any]) => {\n      return setField<TObject>(ret, key as DeepKey<TObject>, value);\n    },\n    {} as TObject\n  );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,gBAKd,eAAwC;AACxC,QAAO,OAAO,QAAQ,cAAc,CAAC,QAClC,KAAc,CAAC,KAAK,WAA0B;AAC7C,SAAO,SAAkB,KAAK,KAAyB,MAAM;IAE/D,EAAE,CACH"}