Skip to content
Formats a tree structure into a string that can be printed
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs/img
lib
test
.editorconfig
.gitignore
.npmignore
LICENSE
README.md
Takefile
package.json
tsconfig.json
tslint.json
yarn.lock

README.md

Format Tree

This library allows complete formatting of trees with guides and configurability that look similar to how npm and yarn dispay trees. The functions expect the predefined structure as defined in mod.ts, and the full documentation for that format is also described there. However, some examples are shown here (which are taken from the test file)

This library is compatible with deno via the following direct import:

https://raw.githubusercontent.com/luvies/format-tree/{tag}/lib/mod.ts

or by using the slightly nicer:

https://denopkg.com/luvies/format-tree@{tag}/lib/mod.ts

In both cases, the {tag} identifier is the release version you are targeting. I would recommend against using master directly (as, in general, the master branch is not guaranteed to be stable).

With first item

Source:

formatTreeString(
  {
    text: 'first',
    extra: 'extra',
    children: [
      {
        text: 'second',
        extra: 'another'
      },
      {
        text: 'third',
        children: [
          {
            text: 'fourth',
            extra: 'yet'
          },
          {
            text: 'fifth'
          },
          {
            text: 'sixth',
            extra: 'another',
            children: [
              {
                text: 'seventh',
                extra: 'one'
              },
              {
                text: 'eighth',
                extra: 'look',
                children: [
                  {
                    text: 'ninth',
                    extra: 'another'
                  },
                  {
                    text: 'tenth',
                    extra: 'one'
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        text: 'eleventh',
        extra: 'yay'
      }
    ]
  },
  {
    guideFormat: chalk.dim
  }
);

Output:

node-stype output

Without first item

Source:

formatTreeString(
  [
    {
      text: 'first',
      extra: 'extra'
    },
    {
      text: 'second',
      extra: 'another'
    },
    {
      text: 'third',
      children: [
        {
          text: 'fourth',
          extra: 'yet'
        },
        {
          text: 'fifth'
        },
        {
          text: 'sixth',
          extra: 'another',
          children: [
            {
              text: 'seventh',
              extra: 'one'
            },
            {
              text: 'eighth',
              extra: 'look',
              children: [
                {
                  text: 'ninth',
                  extra: 'another'
                },
                {
                  text: 'tenth',
                  extra: 'one'
                }
              ]
            }
          ]
        }
      ]
    },
    {
      text: 'eleventh',
      extra: 'yay'
    }
  ],
  {
    guideFormat: chalk.dim
  }
)

Output:

list-style output

You can’t perform that action at this time.