aboutsummaryrefslogtreecommitdiff
path: root/tea-cleaner/TeaCleaner/Options.hs
blob: 7353f8f3c78fa3cb941ef0a8ed55e9b160d394e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
module TeaCleaner.Options
    ( jsonOptions
    ) where

import qualified Data.Aeson.TH as Aeson
import Prelude hiding (id)
import Data.Char

applyFirst :: (Char -> Char) -> String -> String
applyFirst _ []     = []
applyFirst f [x]    = [f x]
applyFirst f (x:xs) = f x: xs

-- | Generic casing for symbol separated names
symbCase :: String -> String
symbCase = u . applyFirst toLower
  where u []                       = []
        u (x:xs) | isUpper x = '_' : toLower x : u xs
                 | otherwise = x : u xs

jsonOptions :: Aeson.Options
jsonOptions = Aeson.defaultOptions
    { Aeson.fieldLabelModifier = symbCase
    }