git.iko.soy/typeable/aeson-inflections
on master help sign in
SSO-183: Implement agency balance updates without using code from Air (#5544)
commit66ac49cc1e468f36bf9d6c78b73bdabcfca0855d authorYuras <shumovichy@gmail.com> dateWed 9 Dec 2020, 13:37 (6 years ago) parentcd3ce10
1 file changed+7−1
src/Data/Aeson/Inflections.hs+7−1
src/Data/Aeson/Inflections.hs+7−1
@@ -7,6 +7,7 @@ module Data.Aeson.Inflections
77 , dropPrefixLower
88 , dropByPrefixLength
99 , cutPrefix
10+ , cutOptionalPrefix
1011 , toUnderscore
1112 , toDashed
1213 , toSpaced
@@ -17,8 +18,9 @@ import Control.Monad
1718import Data.Aeson
1819import Data.Aeson.TH
1920import Data.Char
21+import Data.Maybe
2022import Data.Text (Text)
21−import qualified Data.Text as T (length, pack, unpack)
23+import qualified Data.Text as T
2224import Data.Void
2325import Language.Haskell.TH
2426import qualified Text.Inflections as I
@@ -60,6 +62,10 @@ cutPrefix pref s = if pref == take plen s
6062 where
6163 plen = length pref
6264
65+-- | Drop prefix if exists
66+cutOptionalPrefix :: Text -> Text -> Text
67+cutOptionalPrefix prefix txt = fromMaybe txt $ T.stripPrefix prefix txt
68+
6369-- | Drops prefix and turns first character to lowercase
6470dropPrefixLower :: String -> String
6571dropPrefixLower = over _head toLower . dropPrefix