pluralize

package module
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2020 License: MIT Imports: 4 Imported by: 473

README

go-pluralize

Build Status Go Report Card GoDoc

Pluralize and singularize any word

Acknowledgements

The go-pluralize module is the Golang adaptation of the great work from Blake Embrey and other contributors who created and maintain the NPM JavaScript pluralize package. The originating Javascript implementation can be found on https://github.com/blakeembrey/pluralize

Without their great work this module would have taken a lot more effort, thank you all!

Version mapping

The latest go-pluralize version is compatible with pluralize version 8.0.0 commit #e507706

go-pluralize version NPM Pluralize Package version
0.1.2 - Apr 1, 2020 v0.1.2 8.0.0 - Mar 14, 2020 #e507706
0.1.1 - Sep 15, 2019 v0.1.1 8.0.0 - Aug 27, 2019 #abb3991
0.1.0 - Jun 12, 2019 v0.1.0 8.0.0 - May 24, 2019 #0265e4d

Installation

To install the go module:

go get -u github.com/gertd/go-pluralize

To lock down a specific the version:

go get -u github.com/gertd/go-pluralize@0.1.2

Download the sources and binaries from the latest release

Usage

Code

import pluralize "github.com/gertd/go-pluralize"

word := "Empire"

pluralize := pluralize.NewClient()

fmt.Printf("IsPlural(%s)   => %t\n", input, pluralize.IsPlural(word))
fmt.Printf("IsSingular(%s) => %t\n", input, pluralize.IsSingular(word))
fmt.Printf("Plural(%s)     => %s\n", input, pluralize.Plural(word))
fmt.Printf("Singular(%s)   => %s\n", input, pluralize.Singular(word))

Result

IsPlural(Empire)   => false
IsSingular(Empire) => true
Plural(Empire)     => Empires
Singular(Empire)   => Empire

Pluralize Command Line

Installation

go get -x github.com/gertd/go-pluralize/cmd/pluralize

Usage

Help
pluralize -help
Usage of ./bin/pluralize:
  -cmd string
        command [All|IsPlural|IsSingular|Plural|Singular] (default "All")
  -version
        display version info
  -word string
        input value
Word with All Commands
pluralize -word Empire 

IsPlural(Empire)   => false
IsSingular(Empire) => true
Plural(Empire)     => Empires
Singular(Empire)   => Empire
Is Word Plural?
pluralize -word Cactus -cmd IsPlural

IsPlural(Cactus)   => false
Is Word Singular?
pluralize -word Cacti -cmd IsSingular

IsSingular(Cacti)  => false
Word Make Plural
pluralize -word Cactus -cmd Plural

Plural(Cactus)     => Cacti
Word Make Singular
pluralize -word Cacti -cmd Singular

Singular(Cacti)    => Cactus

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client --

func NewClient

func NewClient() *Client

NewClient - pluralization client factory method

func (*Client) AddIrregularRule

func (c *Client) AddIrregularRule(single string, plural string)

AddIrregularRule -- Add an irregular word definition

func (*Client) AddPluralRule

func (c *Client) AddPluralRule(rule string, replacement string)

AddPluralRule -- Add a pluralization rule to the collection

func (*Client) AddSingularRule

func (c *Client) AddSingularRule(rule string, replacement string)

AddSingularRule -- Add a singularization rule to the collection

func (*Client) AddUncountableRule

func (c *Client) AddUncountableRule(word string)

AddUncountableRule -- Add an uncountable word rule

func (*Client) IsPlural

func (c *Client) IsPlural(word string) bool

IsPlural -- Check if a word is plural

func (*Client) IsSingular

func (c *Client) IsSingular(word string) bool

IsSingular -- Check if a word is singular

func (*Client) Plural

func (c *Client) Plural(word string) string

Plural -- Pluralize a word

func (*Client) Pluralize

func (c *Client) Pluralize(word string, count int, inclusive bool) string

Pluralize -- Pluralize or singularize a word based on the passed in count

word: the word to pluralize
count: how many of the word exist
inclusive: whether to prefix with the number (e.g. 3 ducks)

func (*Client) Singular

func (c *Client) Singular(word string) string

Singular -- Singularize a word

type Rule

type Rule struct {
	Expression  *regexp.Regexp
	Replacement string
}

Rule --

Directories

Path Synopsis
cmd
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL