Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: getKebabCase #294 #313

Merged
merged 18 commits into from
Jul 25, 2021
Merged
Changes from 7 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
8 changes: 3 additions & 5 deletions lib/string-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function replaceSpacesWithCamelCase(str: string): string {
* @returns {string} `str`, without non-alphanumeric characters
*/
export function replaceSpecialCharacterWithSpace(str: string): string {
return str.replace(/[^a-zA-Z0-9. ]/g, " ");
return str.replace(/[^a-zA-Z0-9]/g, " ");
}

/**
Expand All @@ -60,7 +60,7 @@ export function removeSpaces(str: string): string {
* @returns {string} kebab-cased version of `str`
*/
export function convertToKebabCase(str: string): string {
return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
return str.trim().replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_.]+/g, '-').toLowerCase();
}

/**
Expand All @@ -71,9 +71,7 @@ export function convertToKebabCase(str: string): string {
*/
export function getKebabCase(str?: string): string {
return convertToKebabCase(
removeSpaces(
replaceSpecialCharacterWithSpace(replaceSpacesWithCamelCase(str ?? "")),
),
replaceSpecialCharacterWithSpace(str ?? ""),
);
}

Expand Down