A self hosted chat application with end-to-end encrypted messaging.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
580 B

  1. /**
  2. * Capitalizes first letters of words in string.
  3. * @param {string} str String to be modified
  4. * @param {boolean=false} lower Whether all other letters should be lowercased
  5. * @return {string}
  6. * @usage
  7. * capitalize('fix this string'); // -> 'Fix This String'
  8. * capitalize('javaSCrIPT'); // -> 'JavaSCrIPT'
  9. * capitalize('javaSCrIPT', true); // -> 'Javascript'
  10. */
  11. export function capitalize(str: string, lower = false): string {
  12. return (lower ? str.toLowerCase() : str).replace(
  13. /(?:^|\s|["'([{])+\S/g,
  14. (match) => match.toUpperCase()
  15. );
  16. }