@@ -96,6 +96,7 @@ module Text.Inflections
9696 , camelizeCustom
9797 , dasherize
9898 , humanize
99+ , humanizeCustom
99100 , underscore
100101 , titleize
101102 , Transliterations
@@ -110,15 +111,17 @@ module Text.Inflections
110111 , toUnderscore
111112 , toDashed
112113 , toCamelCased
114+ , toHumanized
113115 , betterThrow )
114116where
115117
116118import Control.Monad.Catch (MonadThrow (..))
117119import Data.Text (Text)
120+import Data.Void (Void)
118121import Text.Inflections.Camelize (camelize, camelizeCustom)
119122import Text.Inflections.Dasherize (dasherize)
120123import Text.Inflections.Data (Transliterations, defaultTransliterations)
121−import Text.Inflections.Humanize (humanize)
124+import Text.Inflections.Humanize (humanize, humanizeCustom)
122125import Text.Inflections.Ordinal (ordinal, ordinalize)
123126import Text.Inflections.Parameterize (parameterize, parameterizeCustom)
124127import Text.Inflections.Parse.CamelCase (parseCamelCase)
@@ -139,7 +142,7 @@ import Prelude hiding (Word)
139142--
140143-- >>> toUnderscore "FooBarBazz"
141144-- "foo_bar_bazz"
142−toUnderscore :: Text -> Either (ParseError Char Dec) Text
145+toUnderscore :: Text -> Either (ParseErrorBundle Text Void) Text
143146toUnderscore = fmap underscore . parseCamelCase []
144147
145148-- | Transforms CamelCasedString to snake-cased-string-with-dashes.
@@ -148,26 +151,45 @@ toUnderscore = fmap underscore . parseCamelCase []
148151--
149152-- >>> toDashed "FooBarBazz"
150153-- "foo-bar-bazz"
151−toDashed :: Text -> Either (ParseError Char Dec) Text
154+toDashed :: Text -> Either (ParseErrorBundle Text Void) Text
152155toDashed = fmap dasherize . parseCamelCase []
153156
154157-- | Transforms underscored_text to CamelCasedText. If first argument is
155−-- 'True' then FirstCharacter in result string will be in upper case. If
156−-- 'False' then firstCharacter will be in lower case.
158+-- 'True' then the first character in the result string will be in upper case. If
159+-- 'False' then the first character will be in lower case.
157160--
158−-- > toCamelCased t = fmap (camelizeCustom t) . parseSnakeCase []
161+-- > toCamelCased c = fmap (camelizeCustom c) . parseSnakeCase []
159162--
160163-- >>> toCamelCased True "foo_bar_bazz"
161164-- "FooBarBazz"
162165-- >>> toCamelCased False "foo_bar_bazz"
163166-- "fooBarBazz"
164167toCamelCased
165− :: Bool -- ^ Capitalize the first character
166− -> Text -- ^ Input
167− -> Either (ParseError Char Dec) Text -- ^ Ouput
168−toCamelCased t = fmap (camelizeCustom t) . parseSnakeCase []
168+ :: Bool -- ^ Capitalize the first character
169+ -> Text -- ^ Input
170+ -> Either (ParseErrorBundle Text Void) Text -- ^ Output
171+toCamelCased c = fmap (camelizeCustom c) . parseSnakeCase []
169172
170−-- | Lift something of type @'Either' ('ParseError' 'Char' 'Dec') a@ to
173+-- | Transforms underscored_text to space-separated human-readable text.
174+-- If first argument is 'True' then the first character in the result
175+-- string will be in upper case. If 'False' then the first character will be
176+-- in lower case.
177+--
178+-- > toHumanized c = fmap (humanizeCustom c) . parseSnakeCase []
179+--
180+-- >>> toHumanized True "foo_bar_bazz"
181+-- "Foo bar bazz"
182+-- >>> toHumanized False "foo_bar_bazz"
183+-- "foo bar bazz"
184+--
185+-- /since 0.3.0.0/
186+toHumanized
187+ :: Bool -- ^ Capitalize the first character
188+ -> Text -- ^ Input
189+ -> Either (ParseErrorBundle Text Void) Text -- ^ Output
190+toHumanized c = fmap (humanizeCustom c) . parseSnakeCase []
191+
192+-- | Lift something of type @'Either' ('ParseError' 'Char' 'Void') a@ to
171193-- an instance of 'MonadThrow'. Useful when you want to shortcut on parsing
172194-- failures and you're in an instance of 'MonadThrow'.
173195--
@@ -175,6 +197,6 @@ toCamelCased t = fmap (camelizeCustom t) . parseSnakeCase []
175197--
176198-- /since 0.3.0.0/
177199
178−betterThrow :: MonadThrow m => Either (ParseError Char Dec) a -> m a
200+betterThrow :: MonadThrow m => Either (ParseErrorBundle Text Void) a -> m a
179201betterThrow (Left err) = throwM (InflectionParsingFailed err)
180202betterThrow (Right x) = return x