mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-27 03:19:56 +00:00
* [Beta Menu] Shows unsaved state on browser tab title * Proper state management * Add playwright test * Fix browser tests
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
export function formatCamelCase(str: string): string {
|
|
// Check if the string is camel case
|
|
const isCamelCase = /^([A-Z][a-z]*)+$/.test(str)
|
|
|
|
if (!isCamelCase) {
|
|
return str // Return original string if not camel case
|
|
}
|
|
|
|
// Split the string into words, keeping acronyms together
|
|
const words = str.split(/(?=[A-Z][a-z])|\d+/)
|
|
|
|
// Process each word
|
|
const processedWords = words.map((word) => {
|
|
// If the word is all uppercase and longer than one character, it's likely an acronym
|
|
if (word.length > 1 && word === word.toUpperCase()) {
|
|
return word // Keep acronyms as is
|
|
}
|
|
// For other words, ensure the first letter is capitalized
|
|
return word.charAt(0).toUpperCase() + word.slice(1)
|
|
})
|
|
|
|
// Join the words with spaces
|
|
return processedWords.join(' ')
|
|
}
|
|
|
|
export function appendJsonExt(path: string) {
|
|
if (!path.toLowerCase().endsWith('.json')) {
|
|
path += '.json'
|
|
}
|
|
return path
|
|
}
|
|
|
|
export function trimJsonExt(path?: string) {
|
|
return path?.replace(/\.json$/, '')
|
|
}
|
|
|
|
export function highlightQuery(text: string, query: string) {
|
|
if (!query) return text
|
|
const regex = new RegExp(`(${query})`, 'gi')
|
|
return text.replace(regex, '<span class="highlight">$1</span>')
|
|
}
|