🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

indent2obj

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

indent2obj

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

0.0.3
latest
Source
npm
Version published
Maintainers
1
Created
Source

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

  • Download the indent2obj.min.js.
  • 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

Keywords

string

FAQs

Package last updated on 21 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts