humanize.go 729 B

12345678910111213141516171819202122232425262728293031
  1. package flect
  2. import (
  3. "strings"
  4. )
  5. // Humanize returns first letter of sentence capitalized.
  6. // Common acronyms are capitalized as well.
  7. // Other capital letters in string are left as provided.
  8. // employee_salary = Employee salary
  9. // employee_id = employee ID
  10. // employee_mobile_number = Employee mobile number
  11. // first_Name = First Name
  12. // firstName = First Name
  13. func Humanize(s string) string {
  14. return New(s).Humanize().String()
  15. }
  16. // Humanize First letter of sentence capitalized
  17. func (i Ident) Humanize() Ident {
  18. if len(i.Original) == 0 {
  19. return New("")
  20. }
  21. parts := xappend([]string{}, Titleize(i.Parts[0]))
  22. if len(i.Parts) > 1 {
  23. parts = xappend(parts, i.Parts[1:]...)
  24. }
  25. return New(strings.Join(parts, " "))
  26. }