morley-1.20.0: Developer tools for the Michelson Language
Safe HaskellSafe-Inferred
LanguageHaskell2010

Morley.Util.Text

Synopsis

Documentation

headToLower :: HasCallStack => Text -> Text Source #

Leads first character of text to lower case.

For empty text this will throw an error.

surround :: Semigroup a => a -> a -> a -> a Source #

dquotes :: (Semigroup a, IsString a) => a -> a Source #

stripFieldPrefix :: Text -> Text Source #

Cut fields prefixes which we use according to the style guide.

>>> stripFieldPrefix "cmMyField"
"myField"

dropPrefix :: Text -> Text Source #

Drops the field name prefix from a field.

We assume a convention of the prefix always being non-uppercase, and the first letter of the actual field name being uppercase.

toCamel :: Text -> Text Source #

Transform text to camelCase.

If the text starts with a single uppercase letter, it is lowercased. If it starts with a cluster of non-lowercase letters, all but the last in the cluster are lowercased.

>>> toCamel "MyField"
"myField"
>>> toCamel "USPosition"
"usPosition"
>>> toCamel "FA2Config"
"fa2Config"

toPascal :: Text -> Text #

O(n) Convert casing to PascalCasePhrase. Subject to fusion.

toSnake :: Text -> Text Source #

Transform text to snake_case.

Non-lowercase clusters starting with an uppercase letter are treated as separate words, except the last letter in the cluster.

>>> toSnake "MyField"
"my_field"
>>> toSnake "USPosition"
"us_position"
>>> toSnake "FA2Config"
"fa2_config"
>>> toSnake "MyUSPosition"
"my_us_position"
>>> toSnake "MyFie123d"
"my_fie123d"

toSpinal :: Text -> Text Source #

Transform text to spinal-case.

Non-lowercase clusters starting with an uppercase letter are treated as separate words, except the last letter in the cluster.

>>> toSpinal "MyField"
"my-field"
>>> toSpinal "USPosition"
"us-position"
>>> toSpinal "FA2Config"
"fa2-config"
>>> toSpinal "MyUSPosition"
"my-us-position"
>>> toSpinal "MyFie123d"
"my-fie123d"

lowerCaseCluster :: Text -> Text Source #

If text starts with a cluster of non-lowercase letters, lowercase them except the last one.

>>> lowerCaseCluster "USPosition"
"usPosition"
>>> lowerCaseCluster "Position"
"Position"
>>> lowerCaseCluster "FA2Config"
"fa2Config"