Convert Array, Object to Unix Tree

hosheima

HoSheiMa

Posted on November 1, 2022

Convert Array, Object to Unix Tree

javascript-unix-tree

Github: https://github.com/HoSheiMa/javascript-unix-tree
Pure Javascript Unix Tree Script

// our array example
let array = [
  1,
  2,
  [3, 4, 5],
  {
    name: "Qandil",
    links: [
      "https://www.freelancer.com/u/wadielnatrontv",
      "https://www.facebook.com/qandilabdel.fadilawyan/",
    ],
    ex: [1, 2, 3, { say: "hello" }],
  },
];
Enter fullscreen mode Exit fullscreen mode

Simple result


new output(
  new unix(array).output
);
/**
Output:
├── 1
├── 2
├── Array
│   ├── 3
│   ├── 4
│   └── 5
├── Object
│   ├── Qandil
│   ├── Array
│   │   ├── https://www.freelancer.com/u/wadielnatrontv
│   │   └── https://www.facebook.com/qandilabdel.fadilawyan/
│   ├── Array
│   │   ├── 1
│   │   ├── 2
│   │   ├── 3
│   │   ├── Object
│   │   │   └── hello
*/
Enter fullscreen mode Exit fullscreen mode

Simple result and full Array() details


new output(
   new unix(array, {
    show_array_index: true,
    show_object_keys: false,
  }).output
);
/**
Output:
├── Array: 0
│   └── 1
├── Array: 1
│   └── 2
├── Array
│   ├── Array: 0
│   │   └── 3
│   ├── Array: 1
│   │   └── 4
│   ├── Array: 2
│   │   └── 5
├── Object
│   ├── Qandil
│   ├── Array
│   │   ├── Array: 0
│   │   │   └── https://www.freelancer.com/u/wadielnatrontv
│   │   ├── Array: 1
│   │   │   └── https://www.facebook.com/qandilabdel.fadilawyan/
│   ├── Array
│   │   ├── Array: 0
│   │   │   └── 1
│   │   ├── Array: 1
│   │   │   └── 2
│   │   ├── Array: 2
│   │   │   └── 3
│   │   ├── Object
│   │   │   └── hello
*/
Enter fullscreen mode Exit fullscreen mode

Simple result and full Object details

new output(
  new unix(array, {
    show_array_index: false,
    show_object_keys: true,
  }).output
);
/**
Output:
├── 1
├── 2
├── Array
│   ├── 3
│   ├── 4
│   └── 5
├── Object
│   ├── Object: name
│   │   └── Qandil
│   ├── Array
│   │   ├── https://www.freelancer.com/u/wadielnatrontv
│   │   └── https://www.facebook.com/qandilabdel.fadilawyan/
│   ├── Array
│   │   ├── 1
│   │   ├── 2
│   │   ├── 3
│   │   ├── Object
│   │   │   ├── Object: say
│   │   │   │   └── hello
*/
Enter fullscreen mode Exit fullscreen mode

Simple result, full Array() and Object details

new output(
  new unix(array, {
    show_array_index: true,
    show_object_keys: true,
  }).output
);
/**
Output:
├── Array: 0
│   └── 1
├── Array: 1
│   └── 2
├── Array
│   ├── Array: 0
│   │   └── 3
│   ├── Array: 1
│   │   └── 4
│   ├── Array: 2
│   │   └── 5
├── Object
│   ├── Object: name
│   │   └── Qandil
│   ├── Array
│   │   ├── Array: 0
│   │   │   └── https://www.freelancer.com/u/wadielnatrontv
│   │   ├── Array: 1
│   │   │   └── https://www.facebook.com/qandilabdel.fadilawyan/
│   ├── Array
│   │   ├── Array: 0
│   │   │   └── 1
│   │   ├── Array: 1
│   │   │   └── 2
│   │   ├── Array: 2
│   │   │   └── 3
│   │   ├── Object
│   │   │   ├── Object: say
│   │   │   │   └── hello
*/
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
hosheima
HoSheiMa

Posted on November 1, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

JavaScript Math Object Cheatsheet
javascript JavaScript Math Object Cheatsheet

November 25, 2024

Human-Readable JavaScript
javascript Human-Readable JavaScript

November 20, 2024

CyroScript Weekly Digest: Nov 15, 2024
javascript CyroScript Weekly Digest: Nov 15, 2024

November 16, 2024