MCPcopy Index your code
hub / github.com/bombshell-dev/clack / wrapTextWithPrefix

Function wrapTextWithPrefix

packages/core/src/utils/index.ts:101–127  ·  view source on GitHub ↗
(
	output: Writable | undefined,
	text: string,
	prefix: string,
	startPrefix: string = prefix,
	endPrefix: string = prefix,
	lineFormatter?: (line: string, index: number) => string
)

Source from the content-addressed store, hash-verified

99};
100
101export function wrapTextWithPrefix(
102 output: Writable | undefined,
103 text: string,
104 prefix: string,
105 startPrefix: string = prefix,
106 endPrefix: string = prefix,
107 lineFormatter?: (line: string, index: number) => string
108): string {
109 const columns = getColumns(output ?? stdout);
110 const wrapped = wrapAnsi(text, columns - prefix.length, {
111 hard: true,
112 trim: false,
113 });
114 const lines = wrapped
115 .split('\n')
116 .map((line, index, arr) => {
117 const lineString = lineFormatter ? lineFormatter(line, index) : line;
118 if (index === 0) {
119 return `${startPrefix}${lineString}`;
120 } else if (index === arr.length - 1) {
121 return `${endPrefix}${lineString}`;
122 }
123 return `${prefix}${lineString}`;
124 })
125 .join('\n');
126 return lines;
127}

Callers 6

renderFunction · 0.90
renderFunction · 0.90
renderFunction · 0.90
renderFunction · 0.90
optFunction · 0.90
renderFunction · 0.90

Calls 1

getColumnsFunction · 0.85

Tested by

no test coverage detected