Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- camelCaseToKebabCase(value: string): string {
- const upperChars = value.match(/([A-Z])/g);
- if (!upperChars) {
- return value;
- }
- for (let i = 0; i < upperChars.length; i++) {
- const upperChar = value.charAt(value.indexOf(upperChars[i]));
- const kebabChar = `-${upperChars[i].toLowerCase()}`;
- value = value.replace(upperChar, kebabChar);
- }
- const isFirstCharHyphen = value.slice(0, 1) === '-';
- if (isFirstCharHyphen) {
- value = value.slice(1);
- }
- return value;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement