@@ -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