File: README.md

package info (click to toggle)
golang-github-qor-inflection 0.0~git20151009.0.3272df6-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 60 kB
  • ctags: 21
  • sloc: makefile: 2
file content (39 lines) | stat: -rw-r--r-- 1,201 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Inflection
=========

Inflection pluralizes and singularizes English nouns

## Basic Usage

```go
inflection.Plural("person") => "people"
inflection.Plural("Person") => "People"
inflection.Plural("PERSON") => "PEOPLE"
inflection.Plural("bus")    => "buses"
inflection.Plural("BUS")    => "BUSES"
inflection.Plural("Bus")    => "Buses"

inflection.Singularize("people") => "person"
inflection.Singularize("People") => "Person"
inflection.Singularize("PEOPLE") => "PERSON"
inflection.Singularize("buses")  => "bus"
inflection.Singularize("BUSES")  => "BUS"
inflection.Singularize("Buses")  => "Bus"

inflection.Plural("FancyPerson") => "FancyPeople"
inflection.Singularize("FancyPeople") => "FancyPerson"
```

## Register Rules

Standard rules are from Rails's ActiveSupport (https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflections.rb)

If you want to register more rules, follow:

```
inflection.AddUncountable("fish")
inflection.AddIrregular("person", "people")
inflection.AddPlural("(bu)s$", "${1}ses") # "bus" => "buses" / "BUS" => "BUSES" / "Bus" => "Buses"
inflection.AddSingular("(bus)(es)?$", "${1}") # "buses" => "bus" / "Buses" => "Bus" / "BUSES" => "BUS"
```