All files / src/cookie cookie.helper.ts

100% Statements 30/30
100% Branches 5/5
100% Functions 2/2
100% Lines 30/30

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 29 30 311x 1x 1x 1x 1x 1x 60x 60x 60x 60x 120x 120x 120x 60x 60x 60x 1x 1x 1x 1x 1x 1x 1x 319x 319x 319x 319x 319x 319x 319x  
/**
 * Converts a string in snake_case format to camelCase format.
 *
 * @param str - The string to be converted.
 * @returns The converted string in camelCase format.
 */
export function toCamelCase(str: string): string {
  const words = str.split('_')
 
  const camelCaseWords = words.map((word, index) => {
    // If the word is the first in the array, return it as-is.
    // Otherwise, capitalize the first letter of the word and concatenate it with the rest of the word.
    return index === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1)
  })
  return camelCaseWords.join('')
}
 
/**
 * Converts a string in camelCase format to snake_case format.
 *
 * @param text - The string to be converted.
 * @returns The converted string in snake_case format.
 */
export function toSnakeCase(text: string): string {
  return text
    .replace(/([A-Z])/g, ' $1')
    .split(' ')
    .join('_')
    .toLowerCase()
}