indent2obj

Hierarchy expressed by the indent is converted into the JavaScript object.
Install
npm
$ npm install indent2obj
bower
$ bower install indent2obj
Basic
<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);
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