array-to-archy

Convert an array to object structure representation which can be used to archy.

Usage no npm install needed!

<script type="module">
  import arrayToArchy from 'https://cdn.skypack.dev/array-to-archy';
</script>

README

Array To Archy

Convert an array to object structure representation which can be used to archy.

Build Status version downloads

Table of Contents

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's devDependencies:

npm install --save-dev array-to-archy

Usage

const arrayToArchy = require("array-to-archy")

const _array = [
  1,
  2,
  [3, 4, ["city", "country", ["abc", "xyz"]]],
  5,
  ["foo", "bar"],
  "baz",
  6
]

arrayToArchy(_array, 'X')

Output

{
  "label": "X",
  "nodes": [
    "1",
    "2",
    {
      "label": "X",
      "nodes": [
        "3",
        "4",
        {
          "label": "X",
          "nodes": [
            "city",
            "country",
            {
              "label": "X",
              "nodes": [
                "abc",
                "xyz"
              ]
            }
          ]
        }
      ]
    },
    "5",
    {
      "label": "X",
      "nodes": [
        "foo",
        "bar"
      ]
    },
    " baz",
    "6"
  ]
}

API

arrayToArchy(data [, label])

Returns a object.

label

Type: string
Default: --


Joydip Roy (rjoydip)

💻 📖 🚇 ⚠️

Contributions of any kind welcome!

LICENSE

MIT