All files / string startCase.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 31 32                          17x     1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x      
import { splitByCase } from './splitByCase'
import { upperFirst } from './upperFirst'
 
/**
 * format string to start case -- first letter of each word capitalized
 *
 *
 * @param text
 * @returns snake case string
 *
 * {@link https://lodash.com/docs#startCase}
 */
export function startCase(text: string) {
  return splitByCase(text).map(word => upperFirst(word)).join(' ')
}
 
Eif (import.meta.vitest) {
  const { test, expect } = import.meta.vitest
 
  test('startCase', () => {
    expect(startCase('useXx')).toBe('Use Xx')
    expect(startCase('usexx')).toBe('Usexx')
    expect(startCase('use-xx')).toBe('Use Xx')
    expect(startCase('use xx')).toBe('Use Xx')
    expect(startCase('UseXx')).toBe('Use Xx')
    expect(startCase('use_xx')).toBe('Use Xx')
    expect(startCase('Use Xx')).toBe('Use Xx')
    expect(startCase('Use-Xx')).toBe('Use Xx')
    expect(startCase('USE XX')).toBe('USE XX')
  })
}