1- module EmojiConverter exposing (textToEmoji , emojiToText , supportedEmojis )
1+ module EmojiConverter exposing (emojiToText , supportedEmojis , textToEmoji )
22
3- import List
4- import List.Extra
5- import String
63import Char
74import Dict
5+ import List
6+ import List.Extra
87import Regex
8+ import String
99
1010
1111type alias Key =
@@ -14,20 +14,32 @@ type alias Key =
1414
1515textToEmoji : Key -> String -> String
1616textToEmoji key text =
17- convert supportedLetters ( rotateEmojis key) ( Regex . regex " " ) text
17+ convert supportedLetters ( rotateEmojis key) splitEveryCharacter text
1818
1919
2020emojiToText : Key -> String -> String
2121emojiToText key emojis =
22- let
23- splitter =
24- -- due to JavaScript issues with splitting and unicode, we maually split the string.
25- ( Regex . regex " ([\\ uD800-\\ uDBFF][\\ uDC00-\\ uDFFF])" )
26- in
27- convert ( rotateEmojis key) supportedLetters splitter emojis
22+ convert ( rotateEmojis key) supportedLetters splitEveryEmoji emojis
23+
24+
25+ splitEveryCharacter : String -> List String
26+ splitEveryCharacter =
27+ String . split " "
28+
2829
30+ splitEveryEmoji : String -> List String
31+ splitEveryEmoji str =
32+ -- due to JavaScript issues with splitting and unicode, we maually split the string.
33+ Regex . fromString " ([\\ uD800-\\ uDBFF][\\ uDC00-\\ uDFFF])"
34+ |> Maybe . withDefault Regex . never
35+ |> Regex . find
36+ |> ( \ matcher ->
37+ matcher str
38+ |> List . map . match
39+ )
2940
30- convert : List String -> List String -> Regex .Regex -> String -> String
41+
42+ convert : List String -> List String -> (String -> List String ) -> String -> String
3143convert orderedKeys orderedValues splitter string =
3244 let
3345 lookupTable =
@@ -39,20 +51,19 @@ convert orderedKeys orderedValues splitter string =
3951 |> Dict . get key
4052 |> Maybe . withDefault key
4153 in
42- string
43- |> Regex . split Regex . All splitter
44- |> List . map ( getValueOrReturnKey)
45- |> String . join " "
54+ string
55+ |> splitter
56+ |> List . map getValueOrReturnKey
57+ |> String . join " "
4658
4759
4860rotateEmojis : Key -> List String
4961rotateEmojis key =
5062 supportedEmojis
5163 |> List . Extra . elemIndex key
5264 -- if the key can't be found, default to the first emoji listed.
53- |>
54- Maybe . withDefault 0
55- |> ( flip List . Extra . splitAt supportedEmojis)
65+ |> Maybe . withDefault 0
66+ |> ( \ a -> List . Extra . splitAt a supportedEmojis)
5667 |> ( \ ( head, tail ) -> [ tail, head ] )
5768 |> List . concat
5869
@@ -61,9 +72,11 @@ supportedLetters : List String
6172supportedLetters =
6273 [ -- lowercase letters
6374 List . range 97 122
64- -- uppercase letters
75+
76+ -- uppercase letters
6577 , List . range 65 90
66- -- numbers
78+
79+ -- numbers
6780 , List . range 48 57
6881 ]
6982 |> List . concat
0 commit comments