Skip to content

Instantly share code, notes, and snippets.

@arisris
Created March 10, 2022 04:37
Show Gist options
  • Select an option

  • Save arisris/948faf69c0da6c913472cd0af69e3ce6 to your computer and use it in GitHub Desktop.

Select an option

Save arisris/948faf69c0da6c913472cd0af69e3ce6 to your computer and use it in GitHub Desktop.
ucfirst(); lcfirst(); ucwords(); in typescript
const ucFirst = (str: string) =>
  str
    .split("")
    .map((v, i) => (i === 0 ? v.toUpperCase() : v))
    .join("");
const lcFirst = (str: string) =>
  str
    .split("")
    .map((v, i) => (i === 0 ? v.toLowerCase() : v))
    .join("");
const ucWords = (str: string) =>
  str
    .split(" ")
    .map((i) => ucFirst(i))
    .join(" ");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment