...
1# Flect
2
3[](https://pkg.go.dev/github.com/gobuffalo/flect)
4[](https://github.com/gobuffalo/flect/actions/workflows/standard-go-test.yml)
5[](https://goreportcard.com/report/github.com/gobuffalo/flect)
6
7This is a new inflection engine to replace [https://github.com/markbates/inflect](https://github.com/markbates/inflect) designed to be more modular, more readable, and easier to fix issues on than the original.
8
9Flect provides word inflection features such as `Singularize` and `Pluralize`
10for English nouns and text utility features such as `Camelize`, `Capitalize`,
11`Humanize`, and more.
12
13Due to the flexibly-complex nature of English noun inflection, it is almost
14impossible to cover all exceptions (such as identical/irregular plural).
15With this reason along with the main purpose of Flect, which is to make it
16easy to develop web application in Go, Flect has limitations with its own
17rules.
18
19* It covers regular rule (adding -s or -es and of the word)
20* It covers well-known irregular rules (such as -is to -es, -f to -ves, etc)
21 * https://en.wiktionary.org/wiki/Appendix:English_irregular_nouns#Rules
22* It covers well-known irregular words (such as children, men, etc)
23* If a word can be countable and uncountable like milk or time, it will be
24 treated as countable.
25* If a word has more than one plural forms, which means it has at least one
26 irregular plural, we tried to find most popular one. (The selected plural
27 could be odd to you, please feel free to open an issue with back data)
28 * For example, we selected "stadiums" over "stadia", "dwarfs" over "dwarves"
29 * One or combination of en.wiktionary.org, britannica.com, and
30 trends.google.com are used to check the recent usage trends.
31* However, we cannot cover all cases and some of our cases could not fit with
32 your situation. You can override the default with functions such as
33 `InsertPlural()`, `InsertSingular()`, or `LoadInfrections()`.
34* If you have a json file named `inflections.json` in your application root,
35 the file will be automatically loaded as your custom inflection dictionary.
36
37## Installation
38
39```console
40$ go get github.com/gobuffalo/flect
41```
42
43
44## Packages
45
46### `github.com/gobuffalo/flect`
47
48The `github.com/gobuffalo/flect` package contains "basic" inflection tools, like pluralization, singularization, etc...
49
50#### The `Ident` Type
51
52In addition to helpful methods that take in a `string` and return a `string`, there is an `Ident` type that can be used to create new, custom, inflection rules.
53
54The `Ident` type contains two fields.
55
56* `Original` - This is the original `string` that was used to create the `Ident`
57* `Parts` - This is a `[]string` that represents all of the "parts" of the string, that have been split apart, making the segments easier to work with
58
59Examples of creating new inflection rules using `Ident` can be found in the `github.com/gobuffalo/flect/name` package.
60
61### `github.com/gobuffalo/flect/name`
62
63The `github.com/gobuffalo/flect/name` package contains more "business" inflection rules like creating proper names, table names, etc...
View as plain text