SHARE
TWEET

Untitled

a guest Jul 23rd, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. camelCaseToKebabCase(value: string): string {
  2.     const upperChars = value.match(/([A-Z])/g);
  3.  
  4.     if (!upperChars) {
  5.       return value;
  6.     }
  7.  
  8.     for (let i = 0; i < upperChars.length; i++) {
  9.       const upperChar = value.charAt(value.indexOf(upperChars[i]));
  10.       const kebabChar = `-${upperChars[i].toLowerCase()}`;
  11.       value = value.replace(upperChar, kebabChar);
  12.     }
  13.  
  14.     const isFirstCharHyphen = value.slice(0, 1) === '-';
  15.  
  16.     if (isFirstCharHyphen) {
  17.       value = value.slice(1);
  18.     }
  19.  
  20.     return value;
  21.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top