Copyright | © Jonathan Lorimer 2023 |
---|---|
License | MIT |
Maintainer | jonathanlorimer@pm.me |
Stability | stable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module provides type level tags that can be used to configure string transformations against configuration keys derived from things like record fields.
Since: 0.0.2.0
Synopsis
- class KeyModifier t where
- getKeyModifier :: Text -> Text
- data Identity
- data ToLower
- data ToUpper
- data LowerFirst
- data UpperFirst
- data StripPrefix (prefix :: Symbol)
- data StripSuffix (suffix :: Symbol)
- data CamelTo (separator :: Char)
- type CamelToSnake = CamelTo '_'
- type CamelToKebab = CamelTo '-'
- mapFirst :: (Char -> Char) -> Text -> Maybe Text
- camelTo :: Char -> String -> String
- camelToText :: Char -> Text -> Text
Key Modifiers
class KeyModifier t where Source #
This typeclass turns a type level "tag" into a function from Text ->
Text
. In addition to the instances for the "tags", there are also
instances for type level lists and tuples up to an arity of 4.
important: For type level lists and tuples the modifiers are applied in order from left to right.
>>>
getKeyModifier @'[ToUpper, ToLower] "Hello World"
"hello world"
>>>
getKeyModifier @(ToLower, ToUpper) "Hello World"
"HELLO WORLD"
>>>
getKeyModifier @CamelToSnake "iLoveCFGProject"
"i_love_cfg_project"
Since: 0.0.2.0
getKeyModifier :: Text -> Text Source #
Instances
Identity transformation, corresponds to id
, does not change the string.
Since: 0.0.2.0
Instances
KeyModifier Identity Source # | |
Defined in Cfg.Deriving.KeyModifier getKeyModifier :: Text -> Text Source # |
Lower cases all alphabetical characters, corresponds to toLower
.
Since: 0.0.2.0
Instances
KeyModifier ToLower Source # | |
Defined in Cfg.Deriving.KeyModifier getKeyModifier :: Text -> Text Source # |
Upper cases all alphabetical characters, corresponds to toUpper
.
Since: 0.0.2.0
Instances
KeyModifier ToUpper Source # | |
Defined in Cfg.Deriving.KeyModifier getKeyModifier :: Text -> Text Source # |
data LowerFirst Source #
Lower cases the first character, corresponds to toLower
.
Since: 0.0.2.0
Instances
KeyModifier LowerFirst Source # | |
Defined in Cfg.Deriving.KeyModifier getKeyModifier :: Text -> Text Source # |
data UpperFirst Source #
Upper cases the first character, corresponds to toUpper
.
Since: 0.0.2.0
Instances
KeyModifier UpperFirst Source # | |
Defined in Cfg.Deriving.KeyModifier getKeyModifier :: Text -> Text Source # |
data StripPrefix (prefix :: Symbol) Source #
Takes a type level string and removes that from the beginning of the text,
corresponds to stripPrefix
.
Since: 0.0.2.0
Instances
KnownSymbol prefix => KeyModifier (StripPrefix prefix :: Type) Source # | |
Defined in Cfg.Deriving.KeyModifier getKeyModifier :: Text -> Text Source # |
data StripSuffix (suffix :: Symbol) Source #
Takes a type level string and removes that from the end of the text, corresponds to 'Data.Text.stripSuffix.
Since: 0.0.2.0
Instances
KnownSymbol prefix => KeyModifier (StripSuffix prefix :: Type) Source # | |
Defined in Cfg.Deriving.KeyModifier getKeyModifier :: Text -> Text Source # |
data CamelTo (separator :: Char) Source #
Takes a type level character known as the "separator" and will break the camel case string on its "humps" and then rejoin the string with the separator.
Since: 0.0.2.0
Instances
KnownChar separator => KeyModifier (CamelTo separator :: Type) Source # | |
Defined in Cfg.Deriving.KeyModifier getKeyModifier :: Text -> Text Source # |
type CamelToSnake = CamelTo '_' Source #
Specialized version of CamelTo
where the separator is "_". Results in
snake cased strings.
Since: 0.0.2.0
type CamelToKebab = CamelTo '-' Source #
Specialized version of CamelTo
where the separator is "-". Results in
kebab cased strings.
Since: 0.0.2.0
Helper Functions
mapFirst :: (Char -> Char) -> Text -> Maybe Text Source #
Map over the first character of a stream of Text
Since: 0.0.2.0
Function for breaking a camel case string on its "humps" and re-joining on a provided separator char.
Since: 0.0.2.0
camelToText :: Char -> Text -> Text Source #
Data.Text.Text version of camelTo
Since: 0.0.2.0