module Web.Slack.Util
( formOpts
, jsonOpts
)
where
import Data.Aeson.TH
import Data.Aeson.Types
import Data.Char
import Web.FormUrlEncoded (FormOptions(FormOptions))
import Data.Text (Text)
import qualified Data.Text as Text
formOpts
:: Text
-> FormOptions
formOpts prefix =
FormOptions (modifyLabel prefix)
jsonOpts
:: Text
-> Options
jsonOpts prefix =
defaultOptions
{ fieldLabelModifier = modifyLabel prefix
}
modifyLabel
:: Text
-> String
-> String
modifyLabel prefix =
fmap toLower
. addUnderscores
. drop (Text.length prefix)
addUnderscores
:: String
-> String
addUnderscores =
camelTo2 '_'