array-string-to-nested-structure

Convert array of string to nested structure

Usage no npm install needed!

<script type="module">
  import arrayStringToNestedStructure from 'https://cdn.skypack.dev/array-string-to-nested-structure';
</script>

README

Convert array of strings to nested structure

const input = [
  "payments",
  "effects",
  "items.product.unit",
  "items.effects",
  "items.tax",
];

const output = [
  { name: "payments" },
  { name: "effects" },
  {
    name: "items",
    children: [
      { name: "product", children: [{ name: "unit" }] },
      { name: "effects" },
      { name: "tax" },
    ],
  },
];