{-# LANGUAGE OverloadedStrings #-}
module Servant.Foreign.Inflections
( concatCase
, snakeCase
, camelCase
, concatCaseL
, snakeCaseL
, camelCaseL
) where
import Control.Lens hiding
(cons)
import qualified Data.Char as C
import Data.Text hiding
(map)
import Prelude hiding
(head, tail)
import Servant.Foreign.Internal
concatCase :: FunctionName -> Text
concatCase :: FunctionName -> Text
concatCase = forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getter FunctionName Text
concatCaseL
concatCaseL :: Getter FunctionName Text
concatCaseL :: Getter FunctionName Text
concatCaseL = Iso' FunctionName [Text]
_FunctionName forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to forall a. Monoid a => [a] -> a
mconcat
snakeCase :: FunctionName -> Text
snakeCase :: FunctionName -> Text
snakeCase = forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getter FunctionName Text
snakeCaseL
snakeCaseL :: Getter FunctionName Text
snakeCaseL :: Getter FunctionName Text
snakeCaseL = Iso' FunctionName [Text]
_FunctionName forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to (Text -> [Text] -> Text
intercalate Text
"_")
camelCase :: FunctionName -> Text
camelCase :: FunctionName -> Text
camelCase = forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getter FunctionName Text
camelCaseL
camelCaseL :: Getter FunctionName Text
camelCaseL :: Getter FunctionName Text
camelCaseL = Iso' FunctionName [Text]
_FunctionName forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to [Text] -> Text
convert
where
convert :: [Text] -> Text
convert [] = Text
""
convert (Text
p:[Text]
ps) = forall a. Monoid a => [a] -> a
mconcat forall a b. (a -> b) -> a -> b
$ Text
p forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map Text -> Text
capitalize [Text]
ps
capitalize :: Text -> Text
capitalize Text
"" = Text
""
capitalize Text
name = Char -> Char
C.toUpper (Text -> Char
head Text
name) Char -> Text -> Text
`cons` Text -> Text
tail Text
name