Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jinzhu/inflection
Pluralizes and singularizes English nouns
https://github.com/jinzhu/inflection
go golang inflection
Last synced: 5 days ago
JSON representation
Pluralizes and singularizes English nouns
- Host: GitHub
- URL: https://github.com/jinzhu/inflection
- Owner: jinzhu
- License: mit
- Created: 2015-07-15T04:10:01.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-10-16T08:40:02.000Z (about 1 year ago)
- Last Synced: 2024-10-29T19:59:01.198Z (3 months ago)
- Topics: go, golang, inflection
- Language: Go
- Homepage:
- Size: 28.3 KB
- Stars: 501
- Watchers: 23
- Forks: 66
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- go-awesome - Inflection - Pluralizes and singularizes English nouns (Open source library / Word Processing)
README
# Inflection
Inflection pluralizes and singularizes English nouns
[![Build Status](https://github.com/jinzhu/inflection/actions/workflows/go.yml/badge.svg)](https://github.com/jinzhu/inflection/actions/workflows/go.yml)
## 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.Singular("people") => "person"
inflection.Singular("People") => "Person"
inflection.Singular("PEOPLE") => "PERSON"
inflection.Singular("buses") => "bus"
inflection.Singular("BUSES") => "BUS"
inflection.Singular("Buses") => "Bus"inflection.Plural("FancyPerson") => "FancyPeople"
inflection.Singular("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:
```go
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"
```## Contributing
You can help to make the project better, check out [http://gorm.io/contribute.html](http://gorm.io/contribute.html) for things you can do.
## Author
**jinzhu**
*
*
*## License
Released under the [MIT License](http://www.opensource.org/licenses/MIT).