module Summoner.Text
( endLine
, packageToModule
, packageNameValid
, moduleNameValid
, intercalateMap
, headToUpper
, tconcatMap
) where
import qualified Data.Char as C
import qualified Data.Text as T
endLine :: Text
endLine :: Text
endLine = "\n"
packageToModule :: Text -> Text
packageToModule :: Text -> Text
packageToModule = (Text -> Text) -> [Text] -> Text
forall a. (a -> Text) -> [a] -> Text
tconcatMap Text -> Text
headToUpper ([Text] -> Text) -> (Text -> [Text]) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> [Text]
T.splitOn "-"
packageNameValid :: Text -> Bool
packageNameValid :: Text -> Bool
packageNameValid = (Char -> Bool) -> Text -> Bool
T.all (\c :: Char
c -> Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '-' Bool -> Bool -> Bool
|| Char -> Bool
C.isAlphaNum Char
c)
moduleNameValid :: Text -> Bool
moduleNameValid :: Text -> Bool
moduleNameValid = (Text -> Bool) -> [Text] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Text -> Bool
isValidFragment ([Text] -> Bool) -> (Text -> [Text]) -> Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Text -> [Text]
T.split (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '.')
where
isValidFragment :: Text -> Bool
isValidFragment :: Text -> Bool
isValidFragment s :: Text
s =
Text
s Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= ""
Bool -> Bool -> Bool
&& (Char -> Bool) -> Text -> Bool
T.all Char -> Bool
C.isAlphaNum Text
s
Bool -> Bool -> Bool
&& Char -> Bool
C.isUpper (Text -> Char
T.head Text
s)
intercalateMap :: Text -> (a -> Text) -> [a] -> Text
intercalateMap :: Text -> (a -> Text) -> [a] -> Text
intercalateMap between :: Text
between showT :: a -> Text
showT = Text -> [Text] -> Text
T.intercalate Text
between ([Text] -> Text) -> ([a] -> [Text]) -> [a] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Text) -> [a] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map a -> Text
showT
headToUpper :: Text -> Text
headToUpper :: Text -> Text
headToUpper t :: Text
t = case Text -> Maybe (Char, Text)
T.uncons Text
t of
Nothing -> ""
Just (x :: Char
x, xs :: Text
xs) -> Char -> Text -> Text
T.cons (Char -> Char
C.toUpper Char
x) Text
xs
tconcatMap :: (a -> Text) -> [a] -> Text
tconcatMap :: (a -> Text) -> [a] -> Text
tconcatMap f :: a -> Text
f = [Text] -> Text
T.concat ([Text] -> Text) -> ([a] -> [Text]) -> [a] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Text) -> [a] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map a -> Text
f