README
Flect
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
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 originalstring
that was used to create theIdent
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
The github.com/gobuffalo/flect/name
package contains more "business" inflection rules like creating proper names, table names, etc...
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
- func AddPlural(suffix string, repl string)
- func AddSingular(ext string, repl string)
- func Camelize(s string) string
- func Capitalize(s string) string
- func Dasherize(s string) string
- func Humanize(s string) string
- func LoadAcronyms(r io.Reader) error
- func LoadInflections(r io.Reader) error
- func Ordinalize(s string) string
- func Pascalize(s string) string
- func Pluralize(s string) string
- func PluralizeWithSize(s string, i int) string
- func Singularize(s string) string
- func SingularizeWithSize(s string, i int) string
- func Titleize(s string) string
- func Underscore(s string) string
- type CustomDataParser
- type Ident
- func (i Ident) Camelize() Ident
- func (i Ident) Capitalize() Ident
- func (i Ident) Dasherize() Ident
- func (i Ident) Humanize() Ident
- func (i *Ident) LastPart() string
- func (i Ident) MarshalText() ([]byte, error)
- func (i Ident) Ordinalize() Ident
- func (i Ident) Pascalize() Ident
- func (i Ident) Pluralize() Ident
- func (i Ident) ReplaceSuffix(orig, new string) Ident
- func (i Ident) Singularize() Ident
- func (i Ident) String() string
- func (i Ident) Titleize() Ident
- func (i Ident) ToLower() Ident
- func (i Ident) ToUpper() Ident
- func (i Ident) Underscore() Ident
- func (i *Ident) UnmarshalText(data []byte) error
Constants ¶
const Version = "v0.1.6"
Version holds Flect version number
Variables ¶
Functions ¶
func AddPlural ¶
AddPlural adds a rule that will replace the given suffix with the replacement suffix.
func AddSingular ¶
AddSingular adds a rule that will replace the given suffix with the replacement suffix.
func Camelize ¶
Camelize returns a camelize version of a string
bob dylan = bobDylan widget_id = widgetID WidgetID = widgetID
func Capitalize ¶
Capitalize will cap the first letter of string
user = User bob dylan = Bob dylan widget_id = Widget_id
func Dasherize ¶
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 ¶
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 ¶
LoadAcronyms loads rules from io.Reader param
func LoadInflections ¶
LoadInflections loads rules from io.Reader param
func Pascalize ¶
Pascalize returns a string with each segment capitalized
user = User bob dylan = BobDylan widget_id = WidgetID
func Pluralize ¶
Pluralize returns a plural version of the string
user = users person = people datum = data
func PluralizeWithSize ¶
PluralizeWithSize will pluralize a string taking a number number into account.
PluralizeWithSize("user", 1) = user PluralizeWithSize("user", 2) = users
func Singularize ¶
Singularize returns a singular version of the string
users = user data = datum people = person
func SingularizeWithSize ¶
SingularizeWithSize will singular a string taking a number number into account.
SingularizeWithSize("user", 1) = user SingularizeWithSize("user", 2) = users
func Titleize ¶
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 ¶
Underscore a string
bob dylan = bob_dylan Nice to see you! = nice_to_see_you widgetID = widget_id
Types ¶
type CustomDataParser ¶
CustomDataParser are functions that parse data like acronyms or plurals in the shape of a io.Reader it receives.
type Ident ¶
Ident represents the string and it's parts
func (Ident) Camelize ¶
Camelize returns a camelize version of a string
bob dylan = bobDylan widget_id = widgetID WidgetID = widgetID
func (Ident) Capitalize ¶
Capitalize will cap the first letter of string
user = User bob dylan = Bob dylan widget_id = Widget_id
func (Ident) Dasherize ¶
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) MarshalText ¶
MarshalText marshals Ident into byte array
func (Ident) Ordinalize ¶
Ordinalize converts a number to an ordinal version
42 = 42nd 45 = 45th 1 = 1st
func (Ident) Pascalize ¶
Pascalize returns a string with each segment capitalized
user = User bob dylan = BobDylan widget_id = WidgetID
func (Ident) Pluralize ¶
Pluralize returns a plural version of the string
user = users person = people datum = data
func (Ident) ReplaceSuffix ¶
ReplaceSuffix creates a new Ident with the original suffix replaced by new
func (Ident) Singularize ¶
Singularize returns a singular version of the string
users = user data = datum people = person
func (Ident) Titleize ¶
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) Underscore ¶
Underscore a string
bob dylan = bob_dylan Nice to see you! = nice_to_see_you widgetID = widget_id
func (*Ident) UnmarshalText ¶
UnmarshalText unmarshalls byte array into the Ident
Source Files
Directories
Path | Synopsis |
---|---|