Socket
Socket
Sign inDemoInstall

obj2indent

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    obj2indent

Convert a JavaScript object to a string used the indentation.


Version published
Weekly downloads
51
increased by10.87%
Maintainers
1
Install size
6.65 kB
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 21 Aug 2015

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc