indent2obj

0.0.3 • Public • Published

indent2obj

Build Status npm version Bower

Hierarchy expressed by the indent is converted into the JavaScript object.

Install

npm

$ npm install indent2obj

bower

$ bower install indent2obj

Basic

  1. Download the indent2obj.min.js.
  2. Load it in the script tag.
<script type="text/javascript" src="indent2obj.js"></script>

Usage

input looks like this.

depth1
  depth2
  depth2
    depth3
depth1
depth1
  dpeth2

The result is as follows.

var results = indent2obj(input);
 
console.log(results);
/*
[
  {
    name: "depth1",
    children: [
      {
        name: "depth2",
        children: []
      },
      {
        name: "depth2",
        children: [
          {
            name: "depth3",
            children: []
          }
        ]
      }
    ]
  },
  {
    name: "depth1",
    children: []
  },
  {
    name: "depth1",
    children: [
      {
        name: "depth2",
        children: []
      }
    ]
  }
]
*/

Change indent types

The default is to use 2 spaces.
If you want to the tab, Do the following.

indent2obj(input, "\t");

In the case of the 4 spaces.

indent2obj(input, "    ");

Settings

indent2obj.defaultIndent = "  ";
 
indent2obj.keys = {
  name: "name",
  children: "children"
};

Browser Support

  • IE6 +
  • Chrome
  • Firefox
  • Safari
  • iOS
  • Android

License

Released under the MIT Licence

Author

tsuyoshi wada

Package Sidebar

Install

npm i indent2obj

Weekly Downloads

2

Version

0.0.3

License

MIT

Last publish

Collaborators

  • wadackel