improve wordsFromCamel correctness (#3621)

Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
Ryan Cao 2025-09-08 22:49:24 +00:00 committed by GitHub
parent a4e1d026ea
commit 84957b0e88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -21,7 +21,8 @@ import { moment } from "@webpack/common";
// Utils for readable text transformations eg: `toTitle(fromKebab())` // Utils for readable text transformations eg: `toTitle(fromKebab())`
// Case style to words // Case style to words
export const wordsFromCamel = (text: string) => text.split(/(?=[A-Z])/).map(w => w.toLowerCase()); export const wordsFromCamel = (text: string) =>
text.split(/(?=[A-Z][a-z])|(?<=[a-z])(?=[A-Z])/).map(w => /^[A-Z]{2,}$/.test(w) ? w : w.toLowerCase());
export const wordsFromSnake = (text: string) => text.toLowerCase().split("_"); export const wordsFromSnake = (text: string) => text.toLowerCase().split("_");
export const wordsFromKebab = (text: string) => text.toLowerCase().split("-"); export const wordsFromKebab = (text: string) => text.toLowerCase().split("-");
export const wordsFromPascal = (text: string) => text.split(/(?=[A-Z])/).map(w => w.toLowerCase()); export const wordsFromPascal = (text: string) => text.split(/(?=[A-Z])/).map(w => w.toLowerCase());