summaryrefslogtreecommitdiff
path: root/src/Data/Torrent/JSON.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/Torrent/JSON.hs')
-rw-r--r--src/Data/Torrent/JSON.hs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/Data/Torrent/JSON.hs b/src/Data/Torrent/JSON.hs
new file mode 100644
index 00000000..3fa8973d
--- /dev/null
+++ b/src/Data/Torrent/JSON.hs
@@ -0,0 +1,31 @@
1module Data.Torrent.JSON
2 ( omitLensPrefix
3 , omitRecordPrefix
4 ) where
5
6import Data.Aeson.TH
7import Data.Char
8import Data.List as L
9
10
11-- | Ignore '_' prefix.
12omitLensPrefix :: Options
13omitLensPrefix = defaultOptions
14 { fieldLabelModifier = L.dropWhile (== '_')
15 , constructorTagModifier = id
16 , allNullaryToStringTag = True
17 , omitNothingFields = True
18 }
19
20mapWhile :: (a -> Bool) -> (a -> a) -> [a] -> [a]
21mapWhile p f = go
22 where
23 go [] = []
24 go (x : xs)
25 | p x = f x : go xs
26 | otherwise = xs
27
28omitRecordPrefix :: Options
29omitRecordPrefix = omitLensPrefix
30 { fieldLabelModifier = mapWhile isUpper toLower . L.dropWhile isLower
31 } \ No newline at end of file