Skip to content

Commit

Permalink
feat: add convert convention util
Browse files Browse the repository at this point in the history
  • Loading branch information
timepresent95 committed Aug 20, 2024
1 parent 72bd421 commit a468ba5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/utils/string.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export function convertCamelToSnake(source: string) {
return source.replace(/[A-Z]/g, match => `_${match.toLowerCase()}`);
}

export function convertCamelToKebab(source: string) {
return source.replace(/[A-Z]/g, match => `-${match.toLowerCase()}`);
}

export function convertSnakeToCamel(source: string) {
return source.replace(/([-_][a-z])/g, group =>
group.toUpperCase().replace(/[-_]/, ''),
);
}

export function convertKebabToCamel(source: string) {
return source.replace(/([-][a-z])/g, group =>
group.toUpperCase().replace(/[-]/, ''),
);
}

0 comments on commit a468ba5

Please sign in to comment.