-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdivider.ts
More file actions
201 lines (190 loc) · 4.99 KB
/
divider.ts
File metadata and controls
201 lines (190 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/**
* @file Console divider and separator utilities. Provides various line styles
* for visual separation in CLI output.
*/
import { getDefaultLogger } from '../logger/default'
import { repeatString } from '../strings/format'
const logger = getDefaultLogger()
export interface DividerOptions {
/**
* Width of the divider line in characters.
*
* @default 55
*/
width?: number | undefined
/**
* Character to repeat for the divider line.
*
* @default '═'
*/
char?: string | undefined
/**
* Optional color function to apply to the divider. Accepts a function from
* `yoctocolors` or similar.
*/
color?: ((text: string) => string) | undefined
}
/**
* Create a divider line with custom character and width. Returns a string of
* repeated characters for visual separation.
*
* @example
* ;```ts
* console.log(divider()) // Default: 55 '═' characters
* console.log(divider({ char: '-', width: 40 }))
* console.log(divider({ char: '·', width: 30 }))
* ```
*
* @param options - Divider formatting options.
*
* @returns Divider string
*/
export function divider(options?: DividerOptions): string {
const opts = { __proto__: null, ...options } as DividerOptions
const { char = '═', width = 55 } = opts
return repeatString(char, width)
}
/**
* Common divider style presets. Provides quick access to popular divider
* styles.
*
* @example
* ;```ts
* console.log(dividers.thick()) // ═══════...
* console.log(dividers.thin()) // ───────...
* console.log(dividers.dotted()) // ·······...
* ```
*/
export const dividers = {
/**
* Thick double-line divider using `═`
*/
thick: () => divider({ char: '═' }),
/**
* Thin single-line divider using `─`
*/
thin: () => divider({ char: '─' }),
/**
* Double-line divider (alias for thick)
*/
double: () => divider({ char: '═' }),
/**
* Simple single dash divider using `-`
*/
single: () => divider({ char: '-' }),
/**
* Dotted divider using `·`
*/
dotted: () => divider({ char: '·' }),
/**
* Dashed divider using `╌`
*/
dashed: () => divider({ char: '╌' }),
/**
* Wave divider using `~`
*/
wave: () => divider({ char: '~' }),
/**
* Star divider using `*`
*/
star: () => divider({ char: '*' }),
/**
* Diamond divider using `◆`
*/
diamond: () => divider({ char: '◆' }),
/**
* Arrow divider using `→`
*/
arrow: () => divider({ char: '→' }),
} as const
/**
* Print a divider line directly to console.
*
* @example
* ;```ts
* printDivider() // Prints default divider
* printDivider({ char: '─', width: 60 })
* ```
*
* @param options - Divider formatting options.
*/
export function printDivider(options?: DividerOptions): void {
logger.log(divider(options))
}
/**
* Print a dotted divider line. Convenience function using `·` character.
*
* @example
* ;```ts
* printDottedDivider()
* // ·······················································
* ```
*/
export function printDottedDivider(): void {
printDivider({ char: '·' })
}
/**
* Print a section break with spacing directly to console.
*
* @example
* ;```ts
* console.log('Previous section')
* printSectionBreak()
* console.log('Next section')
* ```
*
* @param options - Divider formatting options.
*/
export function printSectionBreak(options?: DividerOptions): void {
logger.log(sectionBreak(options))
}
/**
* Print a thick divider line (default style). Convenience function using `═`
* character.
*
* @example
* ;```ts
* printThickDivider()
* // ═══════════════════════════════════════════════════
* ```
*/
export function printThickDivider(): void {
printDivider({ char: '═' })
}
/**
* Print a thin divider line. Convenience function using `─` character.
*
* @example
* ;```ts
* printThinDivider()
* // ───────────────────────────────────────────────────
* ```
*/
export function printThinDivider(): void {
printDivider({ char: '─' })
}
/**
* Create a section break with blank lines before and after the divider. Useful
* for creating visual separation between major sections.
*
* @example
* ;```ts
* console.log('Previous section')
* console.log(sectionBreak())
* console.log('Next section')
* // Output:
* // Previous section
* //
* // ═══════════════════════════════════════════════════
* //
* // Next section
* ```
*
* @param options - Divider formatting options.
*
* @returns Section break string with newlines
*/
export function sectionBreak(options?: DividerOptions): string {
const div = divider(options)
return `\n${div}\n`
}