Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/theme/tools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ export function maybeConvertToRem(val: any, name?: string) {
return `${val / 16}rem`;
}

/**
* Converts a token name to camelCase, treating spaces, dashes and
* underscores as word separators.
*
* "AirportExpress" -> "airportExpress"
* "Strong Highlight", "strong--highlight", "strong_highlight" -> "strongHighlight"
*/
export function convertToCamelCase(input: string) {
return input.length === 0 ? '' : input.charAt(0).toLowerCase() + input.slice(1);
const [first = '', ...rest] = input.split(/[\s_-]+/).filter(Boolean);
return (
first.charAt(0).toLowerCase() + first.slice(1)
+ rest.map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join('')
);
}
Loading