array-to-archy

1.1.0 • Public • Published

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

Package Sidebar

Install

npm i array-to-archy

Weekly Downloads

4

Version

1.1.0

License

MIT

Unpacked Size

6.26 kB

Total Files

5

Last publish

Collaborators

  • rjoydip