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

Install Socket

Detect and block malicious and high-risk dependencies

Install

obj2indent

Convert a JavaScript object to a string used the indentation.

0.0.1
latest
Version published
Weekly downloads
346
7.45%
Maintainers
1
Weekly downloads
 
Created

obj2indent

Build Status npm version Bower License

Convert a JavaScript object to a string used the indentation.
indent2obj.js and interconvertible.

Install

npm

$ npm install obj2indent

bower

$ bower install obj2indent

Basic

<script type="text/javascript" src="obj2indent.min.js"></script>

Usage

var results = obj2indent([
  {
    name: "depth1",
    children: [
      {
        name: "depth2",
        children: []
      },
      {
        name: "depth2",
        children: [
          {
            name: "depth3"
          }
        ]
      }
    ]
  },
  {
    name: "depth1"
  },
  {
    name: "depth1",
    children: [
      {
        name: "depth2"
      }
    ]
  }
]);

console.log(results);
/*
depth1
  depth2
  depth2
    depth3
depth1
depth1
  dpeth2
*/

Change indent types

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

obj2indent(input, "\t");

In the case of the 4 spaces.

obj2indent(input, "    ");

Settings

obj2indent.defaultIndent = "  ";

obj2indent.keys = {
  name: "name",
  children: "children"
};

Browser Support

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

License

Released under the MIT Licence

Author

tsuyoshi wada

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