indent2obj
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.
Usage
input
looks like this.
depth1
depth2
depth2
depth3
depth1
depth1
dpeth2
The result is as follows.
var results = ; console;/*[ { 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.
;
In the case of the 4 spaces.
;
Settings
indent2objdefaultIndent = " "; indent2objkeys = name: "name" children: "children";
Browser Support
- IE6 +
- Chrome
- Firefox
- Safari
- iOS
- Android
License
Released under the MIT Licence