object-as-tree
Version:
Visualise a Javascript/Typescript object in a tree structure
73 lines (52 loc) • 1.37 kB
Markdown
A lightweight utility for visualizing JavaScript/TypeScript objects in a tree structure in the console.
- [Installation](
- [Features](
- [Usage](
- [Contributing](
- [License](
Install the package as a dev dependency using npm:
```
npm install --save-dev object-as-tree
```
- Supports objects, arrays, maps, sets, and other common data structures.
- Displays info for RegExp, Date, and other special objects.
- Provides a clear tree representation for easy debugging.
- Detects circular references.
- Zero dependencies.
```js
import { asTree } from 'object-as-tree';
const myObject= {
a: 1,
b: "Hello World!",
c: {
d: true,
e: null
},
f:new Date('2021-01-01'),
g:[1,2,3],
};
console.log(asTree(myObject));
```
This will output a tree representation of the object:
```
Object{}
├─• a: 1
├─• b: 'Hello World!'
├─• c: Object{}
│ ├─• d: true
│ └─• e: null
├─• f: Date(2021-01-01T00:00:00.000Z)
└─• g: Array(3)
├─• 0: 1
├─• 1: 2
└─• 2: 3
```
Contributions are welcome. Open an issue or submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.