UNPKG

2.12 kBTypeScriptView Raw
1import { JsonMap } from '@salesforce/ts-types';
2import { Logger } from '../logger';
3/**
4 * Renders schema properties. By default, this is simply an identity transform. Subclasses may provide more
5 * interesting decorations of each values, such as ANSI coloring.
6 */
7export declare class SchemaPropertyRenderer {
8 /**
9 * Renders a name.
10 *
11 * @param name The name value to render.
12 */
13 renderName(name: string): string;
14 /**
15 * Renders a title.
16 *
17 * @param title The title value to render.
18 */
19 renderTitle(title: string): string;
20 /**
21 * Renders a description.
22 *
23 * @param description The description value to render.
24 */
25 renderDescription(description: string): string;
26 /**
27 * Renders a type.
28 *
29 * @param propertyType The type value to render.
30 */
31 renderType(propertyType: string): string;
32}
33/**
34 * Prints a JSON schema in a human-friendly format.
35 *
36 * ```
37 * import chalk from 'chalk';
38 * class MyPropertyRenderer extends SchemaPropertyRenderer {
39 * renderName(name) { return chalk.bold.blue(name); }
40 * }
41 *
42 * const printer = new SchemaPrinter(logger, schema, new MyPropertyRenderer());
43 * printer.getLines().forEach(console.log);
44 * ```
45 */
46export declare class SchemaPrinter {
47 private schema;
48 private propertyRenderer;
49 private logger;
50 private lines;
51 /**
52 * Constructs a new `SchemaPrinter`.
53 *
54 * @param logger The logger to use when emitting the printed schema.
55 * @param schema The schema to print.
56 * @param propertyRenderer The property renderer.
57 */
58 constructor(logger: Logger, schema: JsonMap, propertyRenderer?: SchemaPropertyRenderer);
59 /**
60 * Gets a read-only array of ready-to-display lines.
61 */
62 getLines(): readonly string[];
63 /**
64 * Gets a ready-to-display line by index.
65 *
66 * @param index The line index to get.
67 */
68 getLine(index: number): string;
69 /**
70 * Prints the accumulated set of schema lines as info log lines to the logger.
71 */
72 print(): void;
73 private addFn;
74 private parseProperty;
75}