2025-01-02 02:33:57 -06:00
|
|
|
module Config.Helpers.Converters exposing
|
|
|
|
( formatName
|
|
|
|
, formatSocial
|
|
|
|
, toTitleCase
|
|
|
|
, wordCount
|
|
|
|
)
|
2024-12-09 19:53:09 -06:00
|
|
|
|
|
|
|
|
|
|
|
formatName : String -> String
|
|
|
|
formatName name =
|
|
|
|
name
|
|
|
|
|> String.toLower
|
|
|
|
|> String.replace " " ""
|
|
|
|
|> String.replace "'" ""
|
|
|
|
|> String.replace "." ""
|
|
|
|
|> String.replace "-" ""
|
|
|
|
|> String.replace "_" ""
|
|
|
|
|
|
|
|
|
|
|
|
formatSocial : String -> String
|
|
|
|
formatSocial name =
|
|
|
|
name
|
|
|
|
|> String.replace "https://x.com/" "@"
|
|
|
|
|> String.replace "https://www.threads.net/@" "@"
|
|
|
|
|> String.replace "https://bsky.app/profile/" "@"
|
|
|
|
|> String.replace "https://www.instagram.com/" "@"
|
2025-01-06 20:04:34 -06:00
|
|
|
|> String.replace "https://www.youtube.com/" "@"
|
2024-12-16 04:19:13 -06:00
|
|
|
|
|
|
|
|
|
|
|
wordCount : String -> Int
|
|
|
|
wordCount text =
|
|
|
|
text
|
|
|
|
|> String.words
|
|
|
|
|> List.length
|
2024-12-17 02:17:06 -06:00
|
|
|
|
|
|
|
|
|
|
|
toTitleCase : String -> String
|
|
|
|
toTitleCase input =
|
|
|
|
let
|
|
|
|
lowercaseWords =
|
|
|
|
[ "a", "an", "the", "and", "but", "or", "for", "nor", "on", "at", "to", "in", "of", "with", "by" ]
|
|
|
|
|
|
|
|
words =
|
|
|
|
String.words input
|
|
|
|
|
|
|
|
capitalizeFirst word =
|
|
|
|
case String.uncons word of
|
|
|
|
Just ( first, rest ) ->
|
|
|
|
String.toUpper (String.fromChar first) ++ String.toLower rest
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
""
|
|
|
|
|
|
|
|
capitalizeWord index word =
|
|
|
|
if index == 0 then
|
|
|
|
capitalizeFirst word
|
|
|
|
|
|
|
|
else if not (List.member (String.toLower word) lowercaseWords) then
|
|
|
|
capitalizeFirst word
|
|
|
|
|
|
|
|
else
|
|
|
|
String.toLower word
|
|
|
|
in
|
|
|
|
words
|
|
|
|
|> List.indexedMap capitalizeWord
|
|
|
|
|> String.join " "
|