Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/String/Extra.elm
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ toTitleCase : String -> String
toTitleCase ws =
let
uppercaseMatch =
Regex.replace (regexFromString "\\w+") (.match >> toSentenceCase)
Regex.replace (regexFromString "\\S+") (.match >> toSentenceCase)
in
ws
|> Regex.replace
(regexFromString "^([a-z])|\\s+([a-z])")
(regexFromString "^(.)|\\s+(.)")
(.match >> uppercaseMatch)


Expand Down
13 changes: 13 additions & 0 deletions tests/Tests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ toTitleCaseTest =
|> String.length
in
Expect.equal expected result
, test "Works with accented characters" <|
\_ ->
Expect.equal "Álbum De Fotos" (toTitleCase "álbum de fotos")
, test "works with ñ" <|
\() ->
Expect.equal "El Niño" (toTitleCase "el Niño")
, test "works with French accents" <|
\() ->
Expect.equal "École De Paris" (toTitleCase "école de paris")
, test "works with fully accented phrase" <|
\() ->
Expect.equal "Ángel Éxtasis Ícono Ópera Único"
(toTitleCase "ángel éxtasis ícono ópera único")
]


Expand Down