MCPcopy Index your code
hub / github.com/GitbookIO/gitbook / formatExample

Function formatExample

packages/react-openapi/src/utils.ts:128–139  ·  view source on GitHub ↗

* Format the example of a schema.

(example: unknown)

Source from the content-addressed store, hash-verified

126 * Format the example of a schema.
127 */
128function formatExample(example: unknown): string {
129 if (typeof example === 'string') {
130 return example
131 .replace(/\n/g, ' ') // Replace newlines with spaces
132 .replace(/\s+/g, ' ') // Collapse multiple spaces/newlines into a single space
133 .replace(/([\{\}:,])\s+/g, '$1 ') // Ensure a space after {, }, :, and ,
134 .replace(/\s+([\{\}:,])/g, ' $1') // Ensure a space before {, }, :, and ,
135 .trim();
136 }
137
138 return stringifyOpenAPI(example);
139}
140
141/**
142 * Check if an example should be displayed.

Callers 1

resolveFirstExampleFunction · 0.85

Calls 1

stringifyOpenAPIFunction · 0.90

Tested by

no test coverage detected