The countable-inflections package

[Tags:library, mit, test]

Provides methods for singularizing and pluralizing text. The library is based on Rails' inflections.


[Skip to Readme]

Properties

Versions 0.0.1, 0.1.0, 0.2.0
Change log CHANGELOG.md
Dependencies base (>=4.6 && <4.10), bytestring, exceptions (>=0.6 && <0.9), pcre-utils, regex-pcre-builtin, text (>=0.2 && <1.3) [details]
License MIT
Copyright 2016 Brady Ouren
Author Brady Ouren <brady@andand.co>
Maintainer Brady Ouren <brady@andand.co>
Stability Unknown
Category Text
Home page https://github.com/tippenein/countable-inflections
Bug tracker https://github.com/tippenein/countable-inflections/issues
Source repository head: git clone https://github.com/tippenein/countable-inflections.git
Uploaded Fri Dec 2 05:33:32 UTC 2016 by tippenein
Distributions NixOS:0.2.0
Downloads 73 total (5 in the last 30 days)
Votes
0 []
Status Docs available [build log]
Last success reported on 2016-12-02 [all 1 reports]

Modules

[Index]

Flags

NameDescriptionDefaultType
devTurn on development settings.DisabledManual

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

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for countable-inflections

Readme for countable-inflections-0.2.0

Countable Inflections

License MIT Hackage Stackage LTS Build Status

This library implements pluralization and singularization in a similar way to the rails inflectors

It uses regexes to define the non-standard transformations and therefore doesn't provide much safety. If you need to provide the same pluralization and singularization which rails does out of the box, this will work the same. If you want more you should be using inflections-hs which uses megaparsec to give you more guarantees

Usage

λ: pluralize "person"
"people"

λ: singularize "branches"
"branch"

These can also be given custom inflection matchers

λ: :t singularizeWith
[Inflection] -> Text -> Text

There are 3 different types of transformations:

Match

Takes a PCRE regex and a replacement string.

λ: :t makeMatchMapping
[(RegexPattern, RegexReplace)] -> [Inflection]

λ: let mapping = makeMatchMapping [("(octop)us", "\1i")]
λ: pluralizeWith mapping "octopus"
"octopi"

Irregular

From singular to plural with no greater pattern.

λ: :t makeIrregularMapping
[(Singular, Plural)] -> [Inflection]

λ: let mapping = makeIrregularMapping [("zombie","zombies")]
λ: pluralizeWith mapping "zombie"
"zombies"

Uncountable

Doesn't have a mapping, word stays the same) so it has the type:

[Text] -> [Inflection]

License

MIT - see the LICENSE file.