MIT licensed by Justin Leitgeb
Maintained by Marc Scholten
This version can be pinned in stack with:inflections-0.4.1.0@sha256:85a4c79612dd887ee9530decf0a3873e7f898f52ae0e955f758b6af3f1b5c825,4462

Module documentation for 0.4.1.0

Used by 1 package in nightly-2026-04-22(full list with versions):

String Inflections for Haskell

License MIT Hackage Stackage Nightly Stackage LTS Build

All Contributors

This library is a partial port of the String Inflector from Ruby on Rails. It currently implements methods such as parameterize, transliterate, camelize, underscore and dasherize. Please see the haddock documentation for a complete list of the functions implemented by this library.

Unlike the ActiveSupport (Rails) and Ember implementations of inflections, this library uses a parser to verify the input to functions like camelize. This is done to ensure that the output strings adhere to the syntax that they are supposed to generate. You can read more about the philosophy behind this library in the Haddock documentation.

Usage

The following examples demonstrate usage of the parameterize, transliterate and camelize functions:

λ: parameterize "Hola. ¿Cómo estás?"
"hola-como-estas"

λ: transliterate "Hola. ¿Cómo estás?"
"Hola. ?Como estas?"

λ: import Control.Monad (liftM)
λ: liftM camelize $ parseSnakeCase "hey_there"
"HeyThere"

Customization

Part of parameterizing strings is approximating all characters in the input encoding to ASCII characters. This library copies the character approximation table from the Ruby i18n library. This data structure is provided as defaultCharacterTransliterations. You can provide your own transliteration map by passing a Map structure (from Data.Map) to the parameterizeCustom function.

If you want to specify a custom default replacement or approximation table for the transliterate function, you should instead call the transliterateCustom function which accepts a String for replacements and a Map for substitution.

Future work

Ideally, we want to implement other functions found in the Rails inflections library. If you need one of those functions, please submit a pull request!

Further documentation

For more information, please see the the Haddock docs for this module.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT, see the LICENSE file.

Contributing

Do you want to contribute to this project? Please take a look at our contributing guideline to know how you can help us build it.


Check out our libraries | Join our team

Changes

Inflections 0.4.1.0

  • Fix parameterize emitting non-alphanumeric characters when the transliteration table maps an input to a string containing punctuation (e.g. ʼn previously produced 'n; now produces n). The output is now filtered to [a-z0-9_-] as the docs imply. Note: this is an observable behavior change for affected inputs, hence the minor-version bump.
  • Bump bounds for text and containers to support GHC 9.10 and 9.12
  • Tighten lower bound on text to >= 1.2.3 to reflect actual minimum
  • Widen upper bound on exceptions to < 0.12
  • Add tested-with covering GHC 8.4 through 9.12
  • CI now tests GHC 8.4 through 9.12

Inflections 0.4.0.7

  • Bump bounds for text in order to support ghc-9.6.1

Inflections 0.4.0.6

  • Support megaparsec == 9.0

Inflections 0.4.0.5

  • Support megaparsec == 8.0

Inflections 0.4.0.3

  • Support megaparsec == 7.0*.
  • Drop support for GHC 7.8.4.

Inflections 0.4.0.3

  • Support exceptions == 0.10.*

Inflections 0.4.0.2

  • Support exceptions == 0.9.*

Inflections 0.4.0.1

  • Support megaparsec >= 6.4.0

Inflections 0.4.0.0

  • Update megaparsec to version 6.

Inflections 0.3.0.0

  • A more type-safe API forbidding creation of invalid words.

  • Made the API use Text instead of String (which significally improved speed).

  • Switched to Megaparsec 5 for parsing.

  • Renamed defaultMap to defaultTransliterations.

  • Words now can contain digits (recognized by all parsers).

  • parseSnakeCase now is not confused when a word happens to have prefix coinciding with an acronym. This is harder to fix for parseCamelCase because acronym may contain capital letters, so old behavior is preserved for parseCamelCase for now.

  • parseCamelCase and parseSnakeCase take any instance of Foldable as a collection of acronyms, not just lists.

  • Added the CHANGELOG.md file.

  • Switched test suite to Hspec.

  • The toUnderscore, toDashed, and toCamelCased are not partial anymore. They return parse error in Left just like parsing functions, but this result can be lifted into any instance of MonadThrow with betterThrow helper.

  • Improved documentation.

Inflections 0.2.0.1

  • Support for GHC 8.0.

Inflections 0.2.0.0

  • Added other-modules to test suite.

Inflections 0.1.0.10

  • Support for GHC 7.10.

Inflections 0.1.0.9

  • Support for GHC 7.8.

Inflections 0.1.0.8

  • Fixed a typo in docs of humanize.

  • Added toUnderscore, toDashed, and toCamelCased.

Inflections 0.1.0.7

  • Support for base-4.7.

  • Improved documentation.

Inflections 0.1.0.6

  • Added titleize and humanize.

  • Improved documentation.

Inflections 0.1.0.5

  • Added module documentation for Text.Inflections.

Inflections 0.1.0.4

  • Reduced number of public modules to one: Text.Inflections.

  • Added ordinal and ordinalize.

  • Improved documentation.

Inflections 0.1.0.3

  • Added camelize, camelizeCustom, underscore, and underscoreCustom.

  • Made the word parser accept empty input.

  • Improved documentation.

Inflections 0.1.0.2

  • Added the transliterate and transliterateCustom functions.

Inflections 0.1.0.1

  • No changes.

Inflections 0.1.0.0

  • Initial release.