obj2indent

0.0.1 • Public • Published

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

  1. Download the obj2indent.min.js.
  2. Load it in the script tag.
<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

Package Sidebar

Install

npm i obj2indent

Weekly Downloads

79

Version

0.0.1

License

MIT

Last publish

Collaborators

  • wadackel