cahilfoley/utils

View on GitHub
src/transforms/capitalize.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
/**
 * @module transforms
 */

/**
 *
 * Capitalize the first letter of a string
 *
 * @param text The string to be capitalized
 * @return Returns the capitalized string
 *
 * @example
 * ```typescript
 *
 * const name = capitalize('bob') // => 'Bob'
 * ```
 *
 */
export default function capitalize(text: string): string {
  const [first, ...rest] = text
  return [first.toUpperCase(), ...rest].join('')
}