@k4a_l/dirtreeist 0.3.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +152 -38
- package/dist/index.d.ts +127 -7
- package/dist/index.js +606 -6
- package/dist/index.js.map +1 -1
- package/package.json +44 -47
- package/.eslint.js +0 -16
- package/.github/workflows/release.yml +0 -24
- package/.prettierrc +0 -7
- package/babel.config.js +0 -13
- package/dist/constants/constant.d.ts +0 -8
- package/dist/constants/constant.d.ts.map +0 -1
- package/dist/constants/constant.js +0 -32
- package/dist/constants/constant.js.map +0 -1
- package/dist/index.cjs +0 -9997
- package/dist/index.d.ts.map +0 -1
- package/dist/modules/convert.d.ts +0 -4
- package/dist/modules/convert.d.ts.map +0 -1
- package/dist/modules/convert.js +0 -75
- package/dist/modules/convert.js.map +0 -1
- package/dist/modules/options.d.ts +0 -4
- package/dist/modules/options.d.ts.map +0 -1
- package/dist/modules/options.js +0 -44
- package/dist/modules/options.js.map +0 -1
- package/dist/modules/parse.d.ts +0 -4
- package/dist/modules/parse.d.ts.map +0 -1
- package/dist/modules/parse.js +0 -48
- package/dist/modules/parse.js.map +0 -1
- package/dist/types/index.d.ts +0 -22
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -2
- package/dist/types/index.js.map +0 -1
- package/rollup.config.js +0 -21
- package/tsconfig.build.json +0 -4
- package/vitest.config.ts +0 -11
- package/yarn-error.log +0 -1861
package/README.md
CHANGED
|
@@ -4,15 +4,8 @@ Create a directory Structure Diagram from a markdown lists.
|
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
#### yarn
|
|
8
|
-
|
|
9
7
|
```shell
|
|
10
8
|
yarn add @k4a_l/dirtreeist
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
### npm
|
|
14
|
-
|
|
15
|
-
```shell
|
|
16
9
|
npm install @k4a_l/dirtreeist
|
|
17
10
|
```
|
|
18
11
|
|
|
@@ -147,6 +140,38 @@ sometext
|
|
|
147
140
|
└─ 4
|
|
148
141
|
```
|
|
149
142
|
|
|
143
|
+
### Memo and note
|
|
144
|
+
|
|
145
|
+
Set `delimiter` and the text after it becomes a **memo**, lined up in a column.
|
|
146
|
+
|
|
147
|
+
An item with **no name, only a memo** is not a directory. It is a **note** belonging to its parent, so longer remarks can be written as an outline without adding fake entries to the tree. Children of a note are notes too, even if they have a name.
|
|
148
|
+
|
|
149
|
+
#### Input
|
|
150
|
+
|
|
151
|
+
```markdown
|
|
152
|
+
- /components -- UI
|
|
153
|
+
- -- has buttons and modals
|
|
154
|
+
- -- Storybook ready
|
|
155
|
+
- App.tsx -- entry point
|
|
156
|
+
- App.css -- style
|
|
157
|
+
- tsconfig.json -- settings
|
|
158
|
+
- README.md -- docs
|
|
159
|
+
- /utils
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### Output (`{ delimiter: '--' }`)
|
|
163
|
+
|
|
164
|
+
```text
|
|
165
|
+
├─/components UI
|
|
166
|
+
│ │ ・has buttons and modals
|
|
167
|
+
│ │ ・Storybook ready
|
|
168
|
+
│ ├─App.tsx entry point
|
|
169
|
+
│ └─App.css style
|
|
170
|
+
├─tsconfig.json settings
|
|
171
|
+
├─README.md docs
|
|
172
|
+
└─/utils
|
|
173
|
+
```
|
|
174
|
+
|
|
150
175
|
## How to use
|
|
151
176
|
|
|
152
177
|
### TypeScript
|
|
@@ -168,8 +193,6 @@ import dirtreeist, { Options } from '@k4a_l/dirtreeist'
|
|
|
168
193
|
|
|
169
194
|
const options: Options = {}
|
|
170
195
|
const outputs = dirtreeist(markdown, options) // DirTree[] => output[]
|
|
171
|
-
|
|
172
|
-
console.log(outputs)
|
|
173
196
|
```
|
|
174
197
|
|
|
175
198
|
or
|
|
@@ -181,35 +204,42 @@ const dirTrees = parse(markdown) // markdown => DirTree[]
|
|
|
181
204
|
|
|
182
205
|
const options: Options = {}
|
|
183
206
|
const outputs = dirTrees.map((dirTree) => convert(dirTree, options)) // DirTree[] => output[]
|
|
184
|
-
|
|
185
|
-
console.log(outputs)
|
|
186
207
|
```
|
|
187
208
|
|
|
188
|
-
###
|
|
209
|
+
### Custom rendering
|
|
189
210
|
|
|
190
|
-
|
|
211
|
+
To style parts of the output yourself, use `layout` instead of `convert`. It returns the same result as flat, already-aligned line data — `'node'`, `'note'` or `'empty'`, each split into branch / name / padding / memo, plus the source `DirNode`.
|
|
191
212
|
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
213
|
+
```tsx
|
|
214
|
+
import { layout } from '@k4a_l/dirtreeist'
|
|
215
|
+
|
|
216
|
+
layout(dirTree, options).map((line, i) =>
|
|
217
|
+
line.type === 'node' ? (
|
|
218
|
+
<div key={i}>
|
|
219
|
+
<span className="branch">{line.branch}</span>
|
|
220
|
+
<span onClick={() => select(line.node)}>{line.name}</span>
|
|
221
|
+
{line.gap}
|
|
222
|
+
<span className="memo">{line.memo}</span>
|
|
223
|
+
</div>
|
|
224
|
+
) : (
|
|
225
|
+
...
|
|
226
|
+
)
|
|
227
|
+
)
|
|
199
228
|
```
|
|
200
229
|
|
|
201
|
-
|
|
230
|
+
Padding comes as ready-made strings rather than widths, so you never count characters yourself. Joining every field of a line gives back exactly what `convert` outputs:
|
|
202
231
|
|
|
203
232
|
```ts
|
|
204
|
-
|
|
205
|
-
treeType?: 'normal' | 'bold' | 'ascii'
|
|
206
|
-
emptyBeforeUpperHierarche?: boolean
|
|
207
|
-
spaceBeforeName?: boolean
|
|
208
|
-
spaceSize?: number
|
|
209
|
-
}
|
|
233
|
+
convert(dirTree, options) === layout(dirTree, options).map(lineToString).join('\n')
|
|
210
234
|
```
|
|
211
235
|
|
|
212
|
-
|
|
236
|
+
That padding only holds in monospace. If names and memos get different fonts or sizes, ignore `gap` and lay the fields out with CSS instead.
|
|
237
|
+
|
|
238
|
+
### Type
|
|
239
|
+
|
|
240
|
+
See [src/types/index.ts](src/types/index.ts)
|
|
241
|
+
|
|
242
|
+
### Options
|
|
213
243
|
|
|
214
244
|
#### treeType
|
|
215
245
|
|
|
@@ -220,7 +250,6 @@ default:`normal`
|
|
|
220
250
|
```
|
|
221
251
|
│
|
|
222
252
|
├─
|
|
223
|
-
│
|
|
224
253
|
└─
|
|
225
254
|
```
|
|
226
255
|
|
|
@@ -229,7 +258,6 @@ default:`normal`
|
|
|
229
258
|
```
|
|
230
259
|
┃
|
|
231
260
|
┣━
|
|
232
|
-
┃
|
|
233
261
|
┗━
|
|
234
262
|
```
|
|
235
263
|
|
|
@@ -237,8 +265,6 @@ default:`normal`
|
|
|
237
265
|
|
|
238
266
|
```
|
|
239
267
|
|
|
|
240
|
-
+
|
|
241
|
-
|
|
|
242
268
|
+-
|
|
243
269
|
```
|
|
244
270
|
|
|
@@ -252,11 +278,9 @@ default:`false`
|
|
|
252
278
|
(true)
|
|
253
279
|
├─/components
|
|
254
280
|
│ ├─App.tsx
|
|
255
|
-
│ └─App.css
|
|
256
281
|
│
|
|
257
282
|
├─config.json
|
|
258
283
|
└─/utils
|
|
259
|
-
└─converter.ts
|
|
260
284
|
└─parser.ts
|
|
261
285
|
```
|
|
262
286
|
|
|
@@ -269,10 +293,8 @@ default: `false`
|
|
|
269
293
|
```text
|
|
270
294
|
├─ /components
|
|
271
295
|
│ ├─ App.tsx
|
|
272
|
-
│ └─ App.css
|
|
273
296
|
├─ config.json
|
|
274
297
|
└─ /utils
|
|
275
|
-
└─ converter.ts
|
|
276
298
|
└─ parser.ts
|
|
277
299
|
```
|
|
278
300
|
|
|
@@ -285,9 +307,101 @@ default:`2`
|
|
|
285
307
|
```text
|
|
286
308
|
├──/components
|
|
287
309
|
│ ├──App.tsx
|
|
288
|
-
│ └──App.css
|
|
289
310
|
├──config.json
|
|
290
311
|
└──/utils
|
|
291
|
-
└──converter.ts
|
|
292
312
|
└──parser.ts
|
|
293
313
|
```
|
|
314
|
+
|
|
315
|
+
#### keepMarkdown : boolean
|
|
316
|
+
|
|
317
|
+
default:`false`
|
|
318
|
+
|
|
319
|
+
Whether to keep markdown notation in lists.
|
|
320
|
+
|
|
321
|
+
##### true
|
|
322
|
+
|
|
323
|
+
```text
|
|
324
|
+
Input:
|
|
325
|
+
- **bold**
|
|
326
|
+
- [google](https://google.com)
|
|
327
|
+
|
|
328
|
+
Output:
|
|
329
|
+
├─**bold**
|
|
330
|
+
└─[google](https://google.com)
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
#### delimiter : string | false
|
|
334
|
+
|
|
335
|
+
default: `false`
|
|
336
|
+
|
|
337
|
+
Separates a name from its memo; `false` disables memos.
|
|
338
|
+
|
|
339
|
+
Splits at the first occurrence; later ones stay in the memo. Occurrences inside link URLs, code spans and escapes (`\`) are skipped, so names can contain the delimiter.
|
|
340
|
+
|
|
341
|
+
#### memoAlign : 'all' | 'siblings' | 'none'
|
|
342
|
+
|
|
343
|
+
default: `all`
|
|
344
|
+
|
|
345
|
+
```text
|
|
346
|
+
all siblings
|
|
347
|
+
├─/components UI ├─/components UI
|
|
348
|
+
│ ├─A.tsx entry │ ├─A.tsx entry
|
|
349
|
+
│ └─A.css style │ └─A.css style
|
|
350
|
+
├─tsconfig.json settings ├─tsconfig.json settings
|
|
351
|
+
├─README.md docs ├─README.md docs
|
|
352
|
+
└─/utils └─/utils
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
#### memoGap : number
|
|
356
|
+
|
|
357
|
+
default: `2`
|
|
358
|
+
|
|
359
|
+
Minimum number of half-width spaces between a name and its memo.
|
|
360
|
+
|
|
361
|
+
#### memoMaxColumn : number | false
|
|
362
|
+
|
|
363
|
+
default: `false`
|
|
364
|
+
|
|
365
|
+
Lines wider than this stop deciding the memo column, so one long name cannot drag every memo right. A ceiling on who *decides* the column, not a width it is padded out to.
|
|
366
|
+
|
|
367
|
+
```text
|
|
368
|
+
false 20
|
|
369
|
+
├─a short ├─a short
|
|
370
|
+
├─b short ├─b short
|
|
371
|
+
├─/very/deeply/nested/dir long ├─/very/deeply/nested/dir long
|
|
372
|
+
└─c short └─c short
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
#### noteAlignToMemo : boolean
|
|
376
|
+
|
|
377
|
+
default: `true`
|
|
378
|
+
|
|
379
|
+
Whether notes line up with the memo column. `false` puts them right after the branch, which holds up better with deep trees or long notes.
|
|
380
|
+
|
|
381
|
+
```text
|
|
382
|
+
true false
|
|
383
|
+
├─/components UI ├─/components UI
|
|
384
|
+
│ │ ・has buttons │ │ ・has buttons
|
|
385
|
+
│ │ ・Storybook │ │ ・Storybook
|
|
386
|
+
│ └─Button.tsx generic │ └─Button.tsx generic
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
#### noteBullet : string
|
|
390
|
+
|
|
391
|
+
default: `・`
|
|
392
|
+
|
|
393
|
+
The mark in front of each note line. An empty string removes it.
|
|
394
|
+
|
|
395
|
+
#### noteIndentSize : number
|
|
396
|
+
|
|
397
|
+
default: `2`
|
|
398
|
+
|
|
399
|
+
Indent width of one note level, in half-width spaces.
|
|
400
|
+
|
|
401
|
+
#### cjkFont : boolean
|
|
402
|
+
|
|
403
|
+
default: `true`
|
|
404
|
+
|
|
405
|
+
Box drawing characters are full-width in CJK fonts, half-width elsewhere. Set `false` for the latter.
|
|
406
|
+
|
|
407
|
+
> Alignment assumes monospace, and counts `keepMarkdown` names by their rendered length (`**bold**` is 4).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,129 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
//#region src/types/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* 名前を持たずメモだけの行(`- -- xxx`)。
|
|
4
|
+
* 名前の右に書くmemoと区別してnoteと呼ぶ。アウトライン形式で階層を持てる。
|
|
5
|
+
*/
|
|
6
|
+
type NoteNode = {
|
|
7
|
+
text: string;
|
|
8
|
+
children: NoteNode[];
|
|
9
|
+
};
|
|
10
|
+
type DirNode = {
|
|
11
|
+
name: string;
|
|
12
|
+
/** 名前と同じ行に書かれたメモ */
|
|
13
|
+
memo?: string;
|
|
14
|
+
/** 子として書かれた、名前を持たないメモ */
|
|
15
|
+
notes?: NoteNode[];
|
|
16
|
+
children: DirNode[];
|
|
17
|
+
};
|
|
18
|
+
type DirTree = DirNode[];
|
|
19
|
+
type ParseOptions = {
|
|
20
|
+
keepMarkdown: boolean;
|
|
21
|
+
/** 名前とmemo/noteを割る文字。memoとnoteの両方に効くので接頭辞を付けない */
|
|
22
|
+
delimiter: string | false;
|
|
23
|
+
};
|
|
24
|
+
type ConvertOptions = {
|
|
25
|
+
treeType: (typeof treeTypeValues)[number];
|
|
26
|
+
emptyBeforeUpperHierarchy: boolean;
|
|
27
|
+
spaceBeforeName: boolean;
|
|
28
|
+
spaceSize: number;
|
|
29
|
+
/**
|
|
30
|
+
* CJKフォントで表示する前提かどうか。
|
|
31
|
+
* 罫線や丸数字は環境によって半角・全角どちらにも描画されるため、
|
|
32
|
+
* メモを揃える幅の計算をどちらに寄せるかの判断に使う。
|
|
33
|
+
*/
|
|
34
|
+
cjkFont: boolean;
|
|
35
|
+
keepMarkdown: boolean;
|
|
36
|
+
/** memo(行内)をどの範囲で揃えるか */
|
|
37
|
+
memoAlign: (typeof memoAlignValues)[number];
|
|
38
|
+
/** 名前とmemoの間の最小間隔(半角スペース換算) */
|
|
39
|
+
memoGap: number;
|
|
40
|
+
/**
|
|
41
|
+
* memo列の上限桁数。falseなら無制限。
|
|
42
|
+
* 極端に長い名前1つに全行が引きずられるのを防ぐためのもので、
|
|
43
|
+
* 上限を超える名前の行だけがmemoGapぶんだけ空けて置かれ、揃いから外れる。
|
|
44
|
+
*/
|
|
45
|
+
memoMaxColumn: number | false;
|
|
46
|
+
/** noteをmemo列に揃えるか。falseなら罫線の直後に置く */
|
|
47
|
+
noteAlignToMemo: boolean;
|
|
48
|
+
/** noteの行頭に付ける記号。空文字なら付けない */
|
|
49
|
+
noteBullet: string;
|
|
50
|
+
/** noteの階層1つあたりのインデント幅(半角スペース換算) */
|
|
51
|
+
noteIndentSize: number;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* 出力1行分。階層構造を上から下へのフラットな行列に落としたもの。
|
|
55
|
+
* 空白は揃え済みの文字列で持つので、連結すればそのまま出力になる。
|
|
56
|
+
* 利用側で独自にレンダリングするときは、この単位でスタイルを当てられる。
|
|
57
|
+
*/
|
|
58
|
+
type NodeLine = {
|
|
59
|
+
type: "node";
|
|
60
|
+
/** 罫線部分。`│ ├─` など */
|
|
61
|
+
branch: string;
|
|
62
|
+
name: string;
|
|
63
|
+
/** 名前とメモの間の空白。メモがなければ空文字 */
|
|
64
|
+
gap: string;
|
|
65
|
+
/** 名前と同じ行に書かれたメモ */
|
|
66
|
+
memo?: string;
|
|
67
|
+
/** この行のもとになったDirNode */
|
|
68
|
+
node: DirNode;
|
|
69
|
+
/** 階層の深さ。0が最上位 */
|
|
70
|
+
hierarchy: number;
|
|
71
|
+
};
|
|
72
|
+
type NoteLine = {
|
|
73
|
+
type: "note";
|
|
74
|
+
/** 罫線部分。親の位置を引き継いだもの */
|
|
75
|
+
branch: string;
|
|
76
|
+
/** 罫線からnote本文までの空白 */
|
|
77
|
+
gap: string;
|
|
78
|
+
/** note内階層のインデント */
|
|
79
|
+
indent: string;
|
|
80
|
+
/** 行頭の記号 */
|
|
81
|
+
bullet: string;
|
|
82
|
+
text: string;
|
|
83
|
+
/** note内の階層。0が最上位 */
|
|
84
|
+
depth: number;
|
|
85
|
+
/** このnoteが属するDirNode */
|
|
86
|
+
node: DirNode;
|
|
87
|
+
/** この行のもとになったNoteNode */
|
|
88
|
+
noteNode: NoteNode;
|
|
89
|
+
};
|
|
90
|
+
/** 罫線だけの空行(emptyBeforeUpperHierarchy)。 */
|
|
91
|
+
type EmptyLine = {
|
|
92
|
+
type: "empty";
|
|
93
|
+
branch: string;
|
|
94
|
+
};
|
|
95
|
+
type Line = NodeLine | NoteLine | EmptyLine;
|
|
96
|
+
type OptionsBase = ParseOptions & ConvertOptions;
|
|
97
|
+
type SymbolSet = {
|
|
98
|
+
vertical: string;
|
|
99
|
+
horizontal: string;
|
|
100
|
+
crossing: string;
|
|
101
|
+
end: string;
|
|
102
|
+
space: string;
|
|
103
|
+
};
|
|
104
|
+
type Options = Partial<OptionsBase>;
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/constants/constant.d.ts
|
|
107
|
+
declare const symbolSets: { [key in OptionsBase["treeType"]]: SymbolSet };
|
|
108
|
+
declare const defaultOptions: OptionsBase;
|
|
109
|
+
declare const treeTypeValues: readonly ["normal", "bold", "ascii"];
|
|
110
|
+
declare const memoAlignValues: readonly ["all", "siblings", "none"];
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/modules/convert.d.ts
|
|
113
|
+
/** Lineを1行の文字列にする。 */
|
|
114
|
+
declare const lineToString: (line: Line) => string;
|
|
115
|
+
/**
|
|
116
|
+
* 階層構造を、上から下へのフラットな行データに落とす。
|
|
117
|
+
* 罫線・名前・空白・メモが分かれているので、利用側で独自にレンダリングできる。
|
|
118
|
+
*/
|
|
119
|
+
declare const layout: (dirTree: DirTree, options?: Options) => Line[];
|
|
120
|
+
declare const convert: (dirTree: DirTree, options?: Options) => string;
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/modules/parse.d.ts
|
|
123
|
+
declare const parse: (chunk: string, options?: Options) => DirTree[];
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/index.d.ts
|
|
5
126
|
declare const dirtreeist: (markdown: string, option?: Options) => string[];
|
|
6
|
-
|
|
7
|
-
export default
|
|
8
|
-
export type { DirTree, Options };
|
|
127
|
+
//#endregion
|
|
128
|
+
export { type DirNode, type DirTree, type EmptyLine, type Line, type NodeLine, type NoteLine, type NoteNode, type Options, convert, dirtreeist as default, defaultOptions, layout, lineToString, memoAlignValues, parse, symbolSets, treeTypeValues };
|
|
9
129
|
//# sourceMappingURL=index.d.ts.map
|