git.iko.soy/typeable/aeson-inflections
on master help sign in
[B2B API] order update hooks (#4714)
2e9190biko
src/Data/Aeson/Inflections.hs+9−1
@@ -3,6 +3,7 @@ module Data.Aeson.Inflections
3 , defaultFieldLabelModifier'
3 , defaultFieldLabelModifier'
4 , dropPrefix
4 , dropPrefix
5 , dropPrefixLower
5 , dropPrefixLower
6+ , dropByPrefixLength
6 , cutPrefix
7 , cutPrefix
7 , toUnderscore
8 , toUnderscore
8 , toDashed
9 , toDashed
@@ -12,7 +13,8 @@ module Data.Aeson.Inflections
12import Control.Lens
13import Control.Lens
13import Control.Monad
14import Control.Monad
14import Data.Char
15import 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)
16import Data.Void
18import Data.Void
17import qualified Text.Inflections as I
19import qualified Text.Inflections as I
18import Text.Megaparsec.Error
20import Text.Megaparsec.Error
@@ -30,6 +32,12 @@ defaultFieldLabelModifier' = T.pack . defaultFieldLabelModifier . T.unpack
30dropPrefix :: String -> String
32dropPrefix :: String -> String
31dropPrefix = dropWhile (not . isUpper)
33dropPrefix = dropWhile (not . isUpper)
32
34
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+
33-- | Cuts the prefix or throws error if prefix does not match. For TH
41-- | Cuts the prefix or throws error if prefix does not match. For TH
34-- modifiers only
42-- modifiers only
35cutPrefix :: String -> String -> String
43cutPrefix :: String -> String -> String