All files / utils string-utils.ts

100% Statements 28/28
100% Branches 7/7
100% Functions 2/2
100% Lines 28/28

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 291x 1x 1x 1x 1x 1x 23x 23x 23x 23x 23x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 7x 3x 3x 4x 3x 3x 3x  
/**
 * Converts a kebab-case string to PascalCase
 * @param str The string to convert.
 * @returns The converted string.
 */
export function kebabCaseToPascalCase(str: string) {
  return str
    .split("-")
    .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
    .join("");
}
 
/**
 * Converts a kebab-case string to camelCase
 * @param str The string to convert.
 * @returns The converted string.
 */
export function kebabCaseToCamelCase(str: string) {
  return str
    .split("-")
    .map((segment, index) => {
      if (index === 0) {
        return segment;
      }
      return segment.charAt(0).toUpperCase() + segment.slice(1);
    })
    .join("");
}