obj2indent
v0.0.1
Published
Convert a JavaScript object to a string used the indentation.
Downloads
226
Maintainers
Readme
obj2indent
Convert a JavaScript object to a string used the indentation.
indent2obj.js and interconvertible.
Install
npm
$ npm install obj2indent
bower
$ bower install obj2indent
Basic
- Download the obj2indent.min.js.
- 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