MCPcopy Index your code
hub / github.com/glideapps/quicktype / serializeRenderResult

Function serializeRenderResult

src/Source.ts:165–266  ·  view source on GitHub ↗
(
    { rootSource, names }: RenderResult,
    indentation: string
)

Source from the content-addressed store, hash-verified

163}
164
165export function serializeRenderResult(
166 { rootSource, names }: RenderResult,
167 indentation: string
168): SerializedRenderResult {
169 let indent = 0;
170 let indentNeeded = 0;
171
172 const lines: string[] = [];
173 let currentLine: string[] = [];
174 const annotations: Annotation[] = [];
175
176 function indentIfNeeded(): void {
177 if (indentNeeded === 0) return;
178 currentLine.push(_.repeat(indentation, indentNeeded));
179 indentNeeded = 0;
180 }
181
182 function flattenCurrentLine(): string {
183 const str = currentLine.join("");
184 currentLine = [str];
185 return str;
186 }
187
188 function currentLocation(): Location {
189 return { line: lines.length, column: flattenCurrentLine().length };
190 }
191
192 function finishLine(): void {
193 lines.push(flattenCurrentLine());
194 currentLine = [];
195 }
196
197 function serializeToStringArray(source: Source): void {
198 switch (source.kind) {
199 case "text":
200 indentIfNeeded();
201 currentLine.push(source.text);
202 break;
203 case "newline":
204 finishLine();
205 indent += source.indentationChange;
206 indentNeeded = indent;
207 break;
208 case "sequence":
209 source.sequence.forEach((s: Source) => serializeToStringArray(s));
210 break;
211 case "table":
212 const t = source.table;
213 const widths = t
214 .map((l: List<Source>) => l.map((s: Source) => sourceLineLength(s, names)).toList())
215 .toList();
216 const numRows = t.size;
217 if (numRows === 0) break;
218 const numColumns = defined(t.map((l: List<Source>) => l.size).max());
219 if (numColumns === 0) break;
220 const columnWidths = defined(
221 Range(0, numColumns).map((i: number) => widths.map((l: List<number>) => l.get(i) || 0).max())
222 );

Callers 4

renderGraphAndSerializeFunction · 0.90
sourceLineLengthFunction · 0.85
serializeToStringArrayFunction · 0.85

Calls 2

serializeToStringArrayFunction · 0.85
finishLineFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…