git.iko.soy/typeable/aeson-inflections
on master help sign in
[B2B API] order update hooks (#4714)
commit2e9190ba7f5b95ad3d3856de7acbb0ca4f87afaa authoriko <ilyakooo0@gmail.com> dateMon 17 Aug 2020, 19:48 (6 years ago) parent2b631c3
1 file changed+9−1
src/Data/Aeson/Inflections.hs+9−1
src/Data/Aeson/Inflections.hs+9−1
@@ -3,6 +3,7 @@ module Data.Aeson.Inflections
33 , defaultFieldLabelModifier'
44 , dropPrefix
55 , dropPrefixLower
6+ , dropByPrefixLength
67 , cutPrefix
78 , toUnderscore
89 , toDashed
@@ -12,7 +13,8 @@ module Data.Aeson.Inflections
1213import Control.Lens
1314import Control.Monad
1415import Data.Char
15−import Data.Text as T (Text, pack, unpack)
16+import Data.Text (Text)
17+import qualified Data.Text as T (length, pack, unpack)
1618import Data.Void
1719import qualified Text.Inflections as I
1820import Text.Megaparsec.Error
@@ -30,6 +32,12 @@ defaultFieldLabelModifier' = T.pack . defaultFieldLabelModifier . T.unpack
3032dropPrefix :: String -> String
3133dropPrefix = dropWhile (not . isUpper)
3234
35+-- | The same as @Prelude.drop@, but takes a string, instead of a length.
36+-- This makes code more explicit (easier to see what exactly we are expecting to
37+-- @drop@)
38+dropByPrefixLength :: Text -> (String -> String)
39+dropByPrefixLength t = drop (T.length t)
40+
3341-- | Cuts the prefix or throws error if prefix does not match. For TH
3442-- modifiers only
3543cutPrefix :: String -> String -> String