| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Text.Casing
Description
This module is inspired by casing package. Instead of String this
package uses Data.Text.Text
PascalCase- no spacing between words, first letter in word is uppercase, all others are lowercase.camelCase- likePascalCase, but the very first letter is lowercase.snake_Case- underscores delimit words, case is unrestricted.
Synopsis
- type NameWithOrigin = (Name, NameOrigin)
- type NameSuffixWithOrigin = (NameSuffix, NameOrigin)
- data GQLNameIdentifier = GQLNameIdentifier {}
- data NameOrigin
- fromTupleWith :: NameOrigin -> (Name, [NameSuffix]) -> GQLNameIdentifier
- fromNameWith :: NameOrigin -> Name -> GQLNameIdentifier
- fromAutogeneratedName :: Name -> GQLNameIdentifier
- fromCustomName :: Name -> GQLNameIdentifier
- fromAutogeneratedTuple :: (Name, [NameSuffix]) -> GQLNameIdentifier
- fromCustomTuple :: (Name, [NameSuffix]) -> GQLNameIdentifier
- fromNonEmptyList :: NonEmpty NameWithOrigin -> GQLNameIdentifier
- transformNameWith :: (Text -> Text) -> Name -> Name
- transformNameAndOriginWith :: (Text -> Text) -> NameWithOrigin -> NameWithOrigin
- transformGQLSuffixWith :: (Text -> Text) -> NameSuffix -> NameSuffix
- transformGQLSuffixAndOriginWith :: (Text -> Text) -> NameSuffixWithOrigin -> NameSuffixWithOrigin
- transformGQLIdentifierWith :: (Text -> Text) -> GQLNameIdentifier -> GQLNameIdentifier
- identifierToList :: GQLNameIdentifier -> [Text]
- toSnakeT :: [Text] -> Text
- toPascalT :: [Text] -> Text
- toCamelT :: [Text] -> Text
- toSnakeG :: GQLNameIdentifier -> Name
- toPascalG :: GQLNameIdentifier -> Name
- toCamelG :: GQLNameIdentifier -> Name
- transformPrefixAndSuffixAndConcat :: GQLNameIdentifier -> (Text -> Text) -> (Text -> Text) -> Name
- fromSnake :: Text -> [Text]
- snakeToPascal :: Text -> Text
- snakeToCamel :: Text -> Text
- lowerFirstChar :: Text -> Text
- upperFirstChar :: Text -> Text
Documentation
type NameWithOrigin = (Name, NameOrigin) Source #
type NameSuffixWithOrigin = (NameSuffix, NameOrigin) Source #
data GQLNameIdentifier Source #
An opaque type, representing a parsed identifier with prefix and suffixes.
Constructors
| GQLNameIdentifier | |
Fields | |
Instances
| Show GQLNameIdentifier Source # | |
Defined in Data.Text.Casing Methods showsPrec :: Int -> GQLNameIdentifier -> ShowS # show :: GQLNameIdentifier -> String # showList :: [GQLNameIdentifier] -> ShowS # | |
| Semigroup GQLNameIdentifier Source # | |
Defined in Data.Text.Casing Methods (<>) :: GQLNameIdentifier -> GQLNameIdentifier -> GQLNameIdentifier # sconcat :: NonEmpty GQLNameIdentifier -> GQLNameIdentifier # stimes :: Integral b => b -> GQLNameIdentifier -> GQLNameIdentifier # | |
data NameOrigin Source #
Represents the origin of a name entity.
CustomNamerepresents a custom user provided nameAutogeneratedNamerepresents a name which is generated by Hasura
For a custom table name foo, the select by pk field name elements:
foois aCustomNamebyis anAutogeneratedNamepkis anAutogeneratedName
However, for a table name foo_bar, the select by pk field name elements
foo, bar, by and pk are all AutogeneratedName
Constructors
| CustomName | |
| AutogeneratedName |
Instances
| Show NameOrigin Source # | |
Defined in Data.Text.Casing Methods showsPrec :: Int -> NameOrigin -> ShowS # show :: NameOrigin -> String # showList :: [NameOrigin] -> ShowS # | |
fromTupleWith :: NameOrigin -> (Name, [NameSuffix]) -> GQLNameIdentifier Source #
fromNameWith :: NameOrigin -> Name -> GQLNameIdentifier Source #
fromAutogeneratedName :: Name -> GQLNameIdentifier Source #
fromCustomName :: Name -> GQLNameIdentifier Source #
fromAutogeneratedTuple :: (Name, [NameSuffix]) -> GQLNameIdentifier Source #
fromCustomTuple :: (Name, [NameSuffix]) -> GQLNameIdentifier Source #
transformNameWith :: (Text -> Text) -> Name -> Name Source #
transforms a graphql name with a transforming function
Note: This will return the graphql name without transformation if the transformed name is not a valid GraphQL identifier
transformNameAndOriginWith :: (Text -> Text) -> NameWithOrigin -> NameWithOrigin Source #
same as transformNameWith but will not transform if the name is a custom name
transformGQLSuffixWith :: (Text -> Text) -> NameSuffix -> NameSuffix Source #
similar to transformNameWith but transforms NameSuffix instead of
Name
transformGQLSuffixAndOriginWith :: (Text -> Text) -> NameSuffixWithOrigin -> NameSuffixWithOrigin Source #
This is essentially same as second transformGQLSuffixWith
transformGQLIdentifierWith :: (Text -> Text) -> GQLNameIdentifier -> GQLNameIdentifier Source #
transforms a GQLNameIdentifier; this will apply the transformations on prefix as well as suffixes
identifierToList :: GQLNameIdentifier -> [Text] Source #
converts identifiers to Text (i.e. unNames and unNameSuffixs
identifiers)
toSnakeT :: [Text] -> Text Source #
To snake_case for Data.Text
>>>toSnakeT ["my","random","text","list"]"my_random_text_list"
toPascalT :: [Text] -> Text Source #
To PascalCase for Data.Text
>>>toPascalT ["my","random","text","list"]"MyRandomTextList"
toCamelT :: [Text] -> Text Source #
To camelCase for Data.Text
>>>toCamelT ["my","random","text","list"]"myRandomTextList"
toSnakeG :: GQLNameIdentifier -> Name Source #
To snake_case for GQLNameIdentifier
toPascalG :: GQLNameIdentifier -> Name Source #
To PascalCase for GQLNameIdentifier
toCamelG :: GQLNameIdentifier -> Name Source #
To camelCase for GQLNameIdentifier
transformPrefixAndSuffixAndConcat :: GQLNameIdentifier -> (Text -> Text) -> (Text -> Text) -> Name Source #
Transforms GQLNameIdentifier and returns a G.Name
fromSnake :: Text -> [Text] Source #
Convert from snake_cased
>>>fromSnake "_hello_world_foo"["_hello","world","foo"]
snakeToPascal :: Text -> Text Source #
Directly convert to PascalCase through fromSnake
snakeToCamel :: Text -> Text Source #
Directly convert to camelCase through fromSnake
lowerFirstChar :: Text -> Text Source #
An internal helper function to lowercase the first character
upperFirstChar :: Text -> Text Source #
An internal helper function to uppercase the first character