0.3.1 • Published 2 years ago

@k4a_l/dirtreeist v0.3.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

DirTreeist

Create a directory Structure Diagram from a markdown lists.

Installation

tarn

yarn add @k4a_l/dirtreeist

npm

npm install @k4a_l/dirtreeist

Demo

https://www.k4a.me/tools/dirtreeist

Example

Basic

Input

- /components
   - App.tsx
   - App.css
- config.json
- /utils
   - converter.ts
   - parser.ts

Output

├─/components
│ ├─App.tsx
│ └─App.css
├─config.json
└─/utils
  └─converter.ts
  └─parser.ts

Only one top

Input

- /root
  - /components
     - App.tsx
     - App.css
  - config.json
  - /utils
     - converter.ts
     - parser.ts

Output

/root
├─/components
│ ├─App.tsx
│ └─App.css
├─config.json
└─/utils
  ├─converter.ts
  └─parser.ts

Sequential listings

Consecutive lists are connected.

Input

- a
  - b
  - c
- d

- 1
  - 2
    - 3
      - 4

Output

├─ a
│   ├─ b
│   └─ c
├─ d
└─ 1
   └─ 2
     └─ 3
       └─ 4

Another element comes in between

If another element is sandwiched in between, a "only" split lists is output.

Input

- a
  - b
  - c
- d

sometext

- 1
  - 2
    - 3
      - 4

Output

├─ a
│ ├─ b
│ └─ c
└─ d
└─ 1
  └─ 2
    └─ 3
      └─ 4

How to use

TypeScript

const markdown = `
- /components
  - App.tsx
  - App.css
- config.json
- /utils
  - converter.ts
  - parser.ts
`
import dirtreeist, { Options } from '@k4a_l/dirtreeist'

const options: Options = {}
const outputs = dirtreeist(markdown, options) // DirTree[] => output[]

console.log(outputs)

or

import { parse, convert, Options } from '@k4a_l/dirtreeist'

const dirTrees = parse(markdown) // markdown => DirTree[]

const options: Options = {}
const outputs = dirTrees.map((dirTree) => convert(dirTree, options)) // DirTree[] => output[]

console.log(outputs)

Type

Structure

type DirNode = {
  name: string
  children: DirNode[]
}

type DirTree = DirNode[]

Options

type Options = {
  treeType?: 'normal' | 'bold' | 'ascii'
  emptyBeforeUpperHierarche?: boolean
  spaceBeforeName?: boolean
  spaceSize?: number
}

Description of options

treeType

default:normal

normal
│
├─
│
└─
bold
┃
┣━
┃
┗━
ascii
|
+
|
+-

emptyLineBeforeUpperHierarchy : boolean

default:false

true
(true)
├─/components
│ ├─App.tsx
│ └─App.css
│
├─config.json
└─/utils
  └─converter.ts
  └─parser.ts

spaceBeforeName : boolean

default: false

true
├─ /components
│ ├─ App.tsx
│ └─ App.css
├─ config.json
└─ /utils
  └─ converter.ts
  └─ parser.ts

spaceSize : number

default:2

4
├──/components
│  ├──App.tsx
│  └──App.css
├──config.json
└──/utils
   └──converter.ts
   └──parser.ts
0.2.12

2 years ago

0.2.11

2 years ago

0.2.10

2 years ago

0.3.0

2 years ago

0.3.1

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago