@scalar/api-reference
Version:
Generate beautiful API references from OpenAPI documents
26 lines (25 loc) • 932 B
JavaScript
//#region src/components/Content/Schema/helpers/format-example.ts
/**
* Converts an example value to a string that can be displayed in the UI.
*/
function formatExample(example) {
if (Array.isArray(example)) return `[${example.map((item) => {
if (typeof item === "string") return `"${item.toString().trim()}"`;
if (typeof item === "object") return JSON.stringify(item);
if (item === void 0) return "undefined";
if (item === null) return "null";
return item;
}).join(", ")}]`;
if (example === null) return "null";
if (typeof example === "object") {
if ("value" in example) return example.value;
if ("externalValue" in example) return example.externalValue;
return JSON.stringify(example);
}
if (example === void 0) return "undefined";
if (typeof example === "string") return example.trim();
return example.toString().trim();
}
//#endregion
export { formatExample };
//# sourceMappingURL=format-example.js.map