@@ -111,11 +111,13 @@ module Text.Inflections
111111 , toUnderscore
112112 , toDashed
113113 , toCamelCased
114+ , toHumanized
114115 , betterThrow )
115116where
116117
117118import Control.Monad.Catch (MonadThrow (..))
118119import Data.Text (Text)
120+import Data.Void (Void)
119121import Text.Inflections.Camelize (camelize, camelizeCustom)
120122import Text.Inflections.Dasherize (dasherize)
121123import Text.Inflections.Data (Transliterations, defaultTransliterations)
@@ -140,7 +142,7 @@ import Prelude hiding (Word)
140142--
141143-- >>> toUnderscore "FooBarBazz"
142144-- "foo_bar_bazz"
143−toUnderscore :: Text -> Either (ParseError Char Dec) Text
145+toUnderscore :: Text -> Either (ParseErrorBundle Text Void) Text
144146toUnderscore = fmap underscore . parseCamelCase []
145147
146148-- | Transforms CamelCasedString to snake-cased-string-with-dashes.
@@ -149,26 +151,45 @@ toUnderscore = fmap underscore . parseCamelCase []
149151--
150152-- >>> toDashed "FooBarBazz"
151153-- "foo-bar-bazz"
152−toDashed :: Text -> Either (ParseError Char Dec) Text
154+toDashed :: Text -> Either (ParseErrorBundle Text Void) Text
153155toDashed = fmap dasherize . parseCamelCase []
154156
155157-- | Transforms underscored_text to CamelCasedText. If first argument is
156−-- 'True' then FirstCharacter in result string will be in upper case. If
157−-- '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.
158160--
159−-- > toCamelCased t = fmap (camelizeCustom t) . parseSnakeCase []
161+-- > toCamelCased c = fmap (camelizeCustom c) . parseSnakeCase []
160162--
161163-- >>> toCamelCased True "foo_bar_bazz"
162164-- "FooBarBazz"
163165-- >>> toCamelCased False "foo_bar_bazz"
164166-- "fooBarBazz"
165167toCamelCased
166− :: Bool -- ^ Capitalize the first character
167− -> Text -- ^ Input
168− -> Either (ParseError Char Dec) Text -- ^ Ouput
169−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 []
170172
171−-- | 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
172193-- an instance of 'MonadThrow'. Useful when you want to shortcut on parsing
173194-- failures and you're in an instance of 'MonadThrow'.
174195--
@@ -176,6 +197,6 @@ toCamelCased t = fmap (camelizeCustom t) . parseSnakeCase []
176197--
177198-- /since 0.3.0.0/
178199
179−betterThrow :: MonadThrow m => Either (ParseError Char Dec) a -> m a
200+betterThrow :: MonadThrow m => Either (ParseErrorBundle Text Void) a -> m a
180201betterThrow (Left err) = throwM (InflectionParsingFailed err)
181202betterThrow (Right x) = return x