fmtid

package module
v0.0.0-...-d439c02 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2020 License: LGPL-3.0 Imports: 4 Imported by: 0

README

fmtid

Moved to gitlab.com/akabio/fmtid

formats identifiers into different name schemas like

  • camelCase
  • kebab-case
  • snake_case

As input it takes an identifier in lower or upper camelCase with acronyms first upper and rest lowercase. The canonical form is UpperCamelCase.

purpose

It's intended purpose is to generate code for different data and programming languages.

The Identifier customerId is in go expected to be customerID or CustomerID whereas in json it's common to use customerId whereas in many languages as a constant it would be CUSTOMER_ID.

api

The functions take an input string in camel case and turn it into it's expected output. They are also available inside a map so it will be easier to add them as filters to a template language. The map keys use the name asId in the target format:

"as-id"  Kebab(...)
"as_id"  Snake(...)
"AS_ID"  UpperSnake(...)
"asId"   Camel(...)
"AsId"   UpperCamel(...)
"asID"   Go(...)
"AsID"   UpperGo(...)
"asid"   Lower(...)
"ASID"   Upper(...)
"plural" Plural(...)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Kebab      = MakeParseFmt("-", func(i int, s string) string { return s })
	Snake      = MakeParseFmt("_", func(i int, s string) string { return s })
	SnakeUpper = MakeParseFmt("_", func(i int, s string) string { return cap(s) })
	Camel      = MakeParseFmt("", func(i int, s string) string { return u(s, i > 0) })
	CamelUpper = MakeParseFmt("", func(i int, s string) string { return u(s, true) })
	Go         = MakeParseFmt("", func(i int, s string) string { return ug(s, i > 0) })
	GoUpper    = MakeParseFmt("", func(i int, s string) string { return ug(s, true) })
	Lower      = MakeParseFmt("", func(i int, s string) string { return s })
	Upper      = MakeParseFmt("", func(i int, s string) string { return cap(s) })
)
View Source
var Formats = map[string]func(string) (string, error){
	"as-id":  Kebab,
	"as_id":  Snake,
	"AS_ID":  SnakeUpper,
	"asId":   Camel,
	"AsId":   CamelUpper,
	"asID":   Go,
	"AsID":   GoUpper,
	"asid":   Lower,
	"ASID":   Upper,
	"plural": Plural,
}

Functions

func Fmt

func Fmt(id []string, sep string, f func(int, string) string) string

func MakeParseFmt

func MakeParseFmt(sep string, f func(int, string) string) func(string) (string, error)

func Parse

func Parse(n string) ([]string, error)

func ParseFmt

func ParseFmt(id string, sep string, f func(int, string) string) (string, error)

func Plural

func Plural(s string) (string, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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