{"version":3,"file":"set.mjs","names":[],"sources":["../../src/object/set.ts"],"sourcesContent":["/**\n * Sets the value at path of object. If a portion of path doesn't exist, it's created.\n * @param obj - The object to modify\n * @param path - The path of the property to set (can be string or array)\n * @param value - The value to set\n * @returns Returns the object\n * @example\n * const obj = { a: { b: { c: 3 } } };\n * set(obj, 'a.b.c', 4);\n * set(obj, ['x', 'y', 'z'], 5);\n * set(obj, 'a.b.d[0]', 6);\n */\nexport function set<T extends object>(obj: T, path: string | readonly (string | number)[], value: unknown): T {\n  if (obj == null) {\n    return obj;\n  }\n\n  // Convert string path to array\n  const pathArray: (string | number)[] =\n    typeof path === 'string'\n      ? path\n          .replace(/\\[(\\d+)\\]/g, '.$1')\n          .split('.')\n          .filter(Boolean)\n      : [...path];\n\n  let current: Record<PropertyKey, unknown> = obj as Record<PropertyKey, unknown>;\n\n  for (let i = 0; i < pathArray.length - 1; i++) {\n    const key = pathArray[i];\n    const nextKey = pathArray[i + 1];\n\n    // Determine if next key is array index\n    const isNextKeyIndex = /^\\d+$/.test(String(nextKey));\n\n    // Create nested structure if it doesn't exist\n    if (current[key] == null) {\n      current[key] = isNextKeyIndex ? [] : {};\n    }\n\n    current = current[key] as Record<PropertyKey, unknown>;\n  }\n\n  // Set the final value\n  const lastKey = pathArray[pathArray.length - 1];\n  current[lastKey] = value;\n\n  return obj;\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,SAAgB,IAAsB,KAAQ,MAA6C,OAAmB;CAC5G,IAAI,OAAO,MACT,OAAO;CAIT,MAAM,YACJ,OAAO,SAAS,WACZ,KACG,QAAQ,cAAc,KAAK,CAAC,CAC5B,MAAM,GAAG,CAAC,CACV,OAAO,OAAO,IACjB,CAAC,GAAG,IAAI;CAEd,IAAI,UAAwC;CAE5C,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,SAAS,GAAG,KAAK;EAC7C,MAAM,MAAM,UAAU;EACtB,MAAM,UAAU,UAAU,IAAI;EAG9B,MAAM,iBAAiB,QAAQ,KAAK,OAAO,OAAO,CAAC;EAGnD,IAAI,QAAQ,QAAQ,MAClB,QAAQ,OAAO,iBAAiB,CAAC,IAAI,CAAC;EAGxC,UAAU,QAAQ;CACpB;CAGA,MAAM,UAAU,UAAU,UAAU,SAAS;CAC7C,QAAQ,WAAW;CAEnB,OAAO;AACT"}