@redocly/theme
Version:
Shared UI components lib
32 lines • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.customCatalogOptionsCasing = customCatalogOptionsCasing;
/**
* Converts a string to title case for catalog option labels.
* Splits on whitespace, hyphens, and underscores; capitalizes each word.
* The first word is rendered as "API" when it is "api" (case-insensitive).
*
* @param str - The raw string to format (e.g. from config or entity data).
* @returns The formatted label with words capitalized and joined by spaces.
*
* @example
* customCatalogOptionsCasing('api_spec') // 'API Spec'
* customCatalogOptionsCasing('my-custom-option') // 'My Custom Option'
* customCatalogOptionsCasing('user name') // 'User Name'
* customCatalogOptionsCasing(' api version ') // 'API Version'
*/
function customCatalogOptionsCasing(str) {
const trimmedStr = str.trim();
if (!trimmedStr)
return trimmedStr;
const words = trimmedStr.split(/[\s-_]+/);
return words
.map((word, index) => {
if (index === 0 && word.toLowerCase() === 'api') {
return 'API';
}
return word[0].toUpperCase() + word.slice(1);
})
.join(' ');
}
//# sourceMappingURL=custom-catalog-options-casing.js.map