inflections: Inflections library for Haskell

[ library, mit, text ] [ Propose Tags ] [ Report a vulnerability ]

Inflections provides methods for singularization, pluralization, dasherizing, etc. The library is based on Rails' inflections library.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
dev

Turn on development settings.

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.1.0.4, 0.1.0.5, 0.1.0.6, 0.1.0.7, 0.1.0.8, 0.1.0.9, 0.1.0.10, 0.2.0.0, 0.2.0.1, 0.3.0.0, 0.4.0.0, 0.4.0.1, 0.4.0.3, 0.4.0.4, 0.4.0.5, 0.4.0.6, 0.4.0.7
Change log CHANGELOG.md
Dependencies base (>=4.11 && <5.0), exceptions (>=0.6 && <0.11), megaparsec (>=7.0.1 && <10.0), text (>=0.2 && <2.1), unordered-containers (>=0.2.7 && <0.3), void (>=0.7 && <0.8) [details]
License MIT
Copyright 2014–2016 Justin Leitgeb
Author Justin Leitgeb <justin@stackbuilders.com>
Maintainer Justin Leitgeb <justin@stackbuilders.com>
Category Text
Home page https://github.com/stackbuilders/inflections-hs
Bug tracker https://github.com/stackbuilders/inflections-hs/issues
Source repo head: git clone https://github.com/stackbuilders/inflections-hs.git
Uploaded by stackbuilders at 2023-08-08T19:56:09Z
Distributions LTSHaskell:0.4.0.7, NixOS:0.4.0.7
Reverse Dependencies 7 direct, 5 indirect [details]
Downloads 17689 total (80 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2023-08-08 [all 1 reports]

Readme for inflections-0.4.0.7

[back to package description]

String Inflections for Haskell

License MIT Hackage Stackage Nightly Stackage LTS Build

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.

Author

Justin Leitgeb justin@stackbuilders.com

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.


Stack Builders Check out our libraries | Join our team