All files / string kebabCase.ts

100% Statements 14/14
50% Branches 1/2
100% Functions 3/3
100% Lines 13/13

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                      17x     1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x      
import { splitByCase } from './splitByCase'
 
/**
 * format string to kebab case
 *
 * @param text
 * @returns kebab case string
 *
 * {@link https://lodash.com/docs#kebabCase}
 */
export function kebabCase(text: string) {
  return splitByCase(text).map(word => word.toLocaleLowerCase()).join('-')
}
 
Eif (import.meta.vitest) {
  const { test, expect } = import.meta.vitest
 
  test('kebabCase', () => {
    expect(kebabCase('useXx')).toBe('use-xx')
    expect(kebabCase('usexx')).toBe('usexx')
    expect(kebabCase('use-xx')).toBe('use-xx')
    expect(kebabCase('use xx')).toBe('use-xx')
    expect(kebabCase('UseXx')).toBe('use-xx')
    expect(kebabCase('use_xx')).toBe('use-xx')
    expect(kebabCase('Use Xx')).toBe('use-xx')
    expect(kebabCase('Use-Xx')).toBe('use-xx')
    expect(kebabCase('USE XX')).toBe('use-xx')
  })
}