Optimize splitCamelCase function performance (#270)
Test if contain first then split
This commit is contained in:
@@ -342,14 +342,15 @@ export function chunkArray<T>(arr: T[], len: number): T[][] {
|
|||||||
* @param text
|
* @param text
|
||||||
*/
|
*/
|
||||||
export function splitCamelCase(text: string): string[] {
|
export function splitCamelCase(text: string): string[] {
|
||||||
const split = text
|
// if no camel case found, do nothing
|
||||||
|
if (!/[a-z][A-Z]/.test(text)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const splittedText = text
|
||||||
.replace(/([a-z](?=[A-Z]))/g, '$1 ')
|
.replace(/([a-z](?=[A-Z]))/g, '$1 ')
|
||||||
.split(' ')
|
.split(' ')
|
||||||
.filter(t => t)
|
.filter(t => t);
|
||||||
if (split.length > 1) {
|
return splittedText;
|
||||||
return split
|
|
||||||
}
|
|
||||||
return []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user