Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

894 B
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.

import type { ColumnDef } from "@tanstack/react-table";

export function getAccessorKey<T>(columnDef: ColumnDef<T, unknown>) {
  return "accessorKey" in columnDef
    ? columnDef?.accessorKey.toString()
    : undefined;
}

export function updateNestedProperty(
  obj: object,
  path: string | string[],
  value: unknown
): unknown {
  if (typeof path == "string")
    return updateNestedProperty(obj, path.split("_"), value);
  else if (path.length == 1 && value !== undefined)
    // @ts-expect-error
    return (obj[path[0]] = value);
  else if (path.length == 0) return obj;
  // @ts-expect-error
  else return updateNestedProperty(obj[path[0]], path.slice(1), value);
}