README

Flect

GoDoc CI Go Report Card

This is a new inflection engine to replace https://github.com/markbates/inflect designed to be more modular, more readable, and easier to fix issues on than the original.

Installation

$ go get -u -v github.com/gobuffalo/flect

github.com/gobuffalo/flect

GoDoc

The github.com/gobuffalo/flect package contains "basic" inflection tools, like pluralization, singularization, etc...

The Ident Type

In 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.

The Ident type contains two fields.

  • Original - This is the original string that was used to create the Ident
  • 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

Examples of creating new inflection rules using Ident can be found in the github.com/gobuffalo/flect/name package.

github.com/gobuffalo/flect/name

GoDoc

The github.com/gobuffalo/flect/name package contains more "business" inflection rules like creating proper names, table names, etc...

Expand ▾ Collapse ▴

Documentation

Overview

    Package flect 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.

    Index

    Constants

    View Source
    const Version = "v0.1.6"

      Version holds Flect version number

      Variables

      This section is empty.

      Functions

      func AddPlural

      func AddPlural(suffix string, repl string)

        AddPlural adds a rule that will replace the given suffix with the replacement suffix.

        func AddSingular

        func AddSingular(ext string, repl string)

          AddSingular adds a rule that will replace the given suffix with the replacement suffix.

          func Camelize

          func Camelize(s string) string

            Camelize returns a camelize version of a string

            bob dylan = bobDylan
            widget_id = widgetID
            WidgetID = widgetID
            

            func Capitalize

            func Capitalize(s string) string

              Capitalize will cap the first letter of string

              user = User
              bob dylan = Bob dylan
              widget_id = Widget_id
              

              func Dasherize

              func Dasherize(s string) string

                Dasherize returns an alphanumeric, lowercased, dashed string

                Donald E. Knuth = donald-e-knuth
                Test with + sign = test-with-sign
                admin/WidgetID = admin-widget-id
                

                func Humanize

                func Humanize(s string) string

                  Humanize returns first letter of sentence capitalized. Common acronyms are capitalized as well. Other capital letters in string are left as provided.

                  employee_salary = Employee salary
                  employee_id = employee ID
                  employee_mobile_number = Employee mobile number
                  first_Name = First Name
                  firstName = First Name
                  

                  func LoadAcronyms

                  func LoadAcronyms(r io.Reader) error

                    LoadAcronyms loads rules from io.Reader param

                    func LoadInflections

                    func LoadInflections(r io.Reader) error

                      LoadInflections loads rules from io.Reader param

                      func Ordinalize

                      func Ordinalize(s string) string

                        Ordinalize converts a number to an ordinal version

                        42 = 42nd
                        45 = 45th
                        1 = 1st
                        

                        func Pascalize

                        func Pascalize(s string) string

                          Pascalize returns a string with each segment capitalized

                          user = User
                          bob dylan = BobDylan
                          widget_id = WidgetID
                          

                          func Pluralize

                          func Pluralize(s string) string

                            Pluralize returns a plural version of the string

                            user = users
                            person = people
                            datum = data
                            

                            func PluralizeWithSize

                            func PluralizeWithSize(s string, i int) string

                              PluralizeWithSize will pluralize a string taking a number number into account.

                              PluralizeWithSize("user", 1) = user
                              PluralizeWithSize("user", 2) = users
                              

                              func Singularize

                              func Singularize(s string) string

                                Singularize returns a singular version of the string

                                users = user
                                data = datum
                                people = person
                                

                                func SingularizeWithSize

                                func SingularizeWithSize(s string, i int) string

                                  SingularizeWithSize will singular a string taking a number number into account.

                                  SingularizeWithSize("user", 1) = user
                                  SingularizeWithSize("user", 2) = users
                                  

                                  func Titleize

                                  func Titleize(s string) string

                                    Titleize will capitalize the start of each part

                                    "Nice to see you!" = "Nice To See You!"
                                    "i've read a book! have you?" = "I've Read A Book! Have You?"
                                    "This is `code` ok" = "This Is `code` OK"
                                    

                                    func Underscore

                                    func Underscore(s string) string

                                      Underscore a string

                                      bob dylan = bob_dylan
                                      Nice to see you! = nice_to_see_you
                                      widgetID = widget_id
                                      

                                      Types

                                      type CustomDataParser

                                      type CustomDataParser func(io.Reader) error

                                        CustomDataParser are functions that parse data like acronyms or plurals in the shape of a io.Reader it receives.

                                        type Ident

                                        type Ident struct {
                                        	Original string
                                        	Parts    []string
                                        }

                                          Ident represents the string and it's parts

                                          func New

                                          func New(s string) Ident

                                            New creates a new Ident from the string

                                            func (Ident) Camelize

                                            func (i Ident) Camelize() Ident

                                              Camelize returns a camelize version of a string

                                              bob dylan = bobDylan
                                              widget_id = widgetID
                                              WidgetID = widgetID
                                              

                                              func (Ident) Capitalize

                                              func (i Ident) Capitalize() Ident

                                                Capitalize will cap the first letter of string

                                                user = User
                                                bob dylan = Bob dylan
                                                widget_id = Widget_id
                                                

                                                func (Ident) Dasherize

                                                func (i Ident) Dasherize() Ident

                                                  Dasherize returns an alphanumeric, lowercased, dashed string

                                                  Donald E. Knuth = donald-e-knuth
                                                  Test with + sign = test-with-sign
                                                  admin/WidgetID = admin-widget-id
                                                  

                                                  func (Ident) Humanize

                                                  func (i Ident) Humanize() Ident

                                                    Humanize First letter of sentence capitalized

                                                    func (*Ident) LastPart

                                                    func (i *Ident) LastPart() string

                                                      LastPart returns the last part/word of the original string

                                                      func (Ident) MarshalText

                                                      func (i Ident) MarshalText() ([]byte, error)

                                                        MarshalText marshals Ident into byte array

                                                        func (Ident) Ordinalize

                                                        func (i Ident) Ordinalize() Ident

                                                          Ordinalize converts a number to an ordinal version

                                                          42 = 42nd
                                                          45 = 45th
                                                          1 = 1st
                                                          

                                                          func (Ident) Pascalize

                                                          func (i Ident) Pascalize() Ident

                                                            Pascalize returns a string with each segment capitalized

                                                            user = User
                                                            bob dylan = BobDylan
                                                            widget_id = WidgetID
                                                            

                                                            func (Ident) Pluralize

                                                            func (i Ident) Pluralize() Ident

                                                              Pluralize returns a plural version of the string

                                                              user = users
                                                              person = people
                                                              datum = data
                                                              

                                                              func (Ident) ReplaceSuffix

                                                              func (i Ident) ReplaceSuffix(orig, new string) Ident

                                                                ReplaceSuffix creates a new Ident with the original suffix replaced by new

                                                                func (Ident) Singularize

                                                                func (i Ident) Singularize() Ident

                                                                  Singularize returns a singular version of the string

                                                                  users = user
                                                                  data = datum
                                                                  people = person
                                                                  

                                                                  func (Ident) String

                                                                  func (i Ident) String() string

                                                                    String implements fmt.Stringer and returns the original string

                                                                    func (Ident) Titleize

                                                                    func (i Ident) Titleize() Ident

                                                                      Titleize will capitalize the start of each part

                                                                      "Nice to see you!" = "Nice To See You!"
                                                                      "i've read a book! have you?" = "I've Read A Book! Have You?"
                                                                      "This is `code` ok" = "This Is `code` OK"
                                                                      

                                                                      func (Ident) ToLower

                                                                      func (i Ident) ToLower() Ident

                                                                        ToLower is a convience wrapper for strings.ToLower

                                                                        func (Ident) ToUpper

                                                                        func (i Ident) ToUpper() Ident

                                                                          ToUpper is a convience wrapper for strings.ToUpper

                                                                          func (Ident) Underscore

                                                                          func (i Ident) Underscore() Ident

                                                                            Underscore a string

                                                                            bob dylan = bob_dylan
                                                                            Nice to see you! = nice_to_see_you
                                                                            widgetID = widget_id
                                                                            

                                                                            func (*Ident) UnmarshalText

                                                                            func (i *Ident) UnmarshalText(data []byte) error

                                                                              UnmarshalText unmarshalls byte array into the Ident

                                                                              Directories

                                                                              Path Synopsis