nmconv

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2020 License: MIT Imports: 4 Imported by: 2

README

nmconv

Test Coverage Go Report Card GoDoc

import "git.fractalqb.de/fractalqb/nmconv"


Convert identifiers between different naming conventions

When one wants to convert names between e.g. camel-, snake- or lisp-case this nmconvage might come in handy.

Documentation

Index

Constants

View Source
const (
	// Lisp is the separator for lisp-like (kebab case) naming
	// convetions
	Lisp = "-"
	// Snake is the separator for C-like (snake case) naming
	// convetions
	Snake = "_"
)

Variables

This section is empty.

Functions

func Camel1Low

func Camel1Low(norm []string) string

func Camel1Up

func Camel1Up(norm []string) string

func CapWord

func CapWord(w string) string

func Convert

func Convert(name string, from Normalize, to Denormalize) string

Convert converts a given name by first normlizing it from its current naming convetion and then denormalizing its to the target naming convetnion.

func ConvertX

func ConvertX(name string, from Normalize, x Transform, to Denormalize) string

ConvertX converts a given name by first normlizing it from its current naming convetion then transforming the normalized name with x and eventually denormalizing its to the target naming convention.

func Uncamel

func Uncamel(str string) (norm []string)

Types

type Conversion

type Conversion struct {
	Norm   Normalize
	Xform  Transform
	Denorm Denormalize
}

func SepConvention

func SepConvention(separator string) Conversion

func SepXConvention

func SepXConvention(x Transform, separator string) Conversion

func (*Conversion) Convert

func (cnv *Conversion) Convert(str string) string

type Denormalize

type Denormalize func([]string) string

Denormalie functions convert names from the normalized form to a naming convention, i.e. it reverses the effect of a Normalize function.

func Sep

func Sep(separator string) Denormalize

func XDenorm

func XDenorm(x Transform, d Denormalize) Denormalize

type Normalize

type Normalize func(string) []string

Normalize functions convert names from some naming convetion to the normalized form, i.e. an array of strings - each containing one word of the name.

func NormX

func NormX(n Normalize, x Transform) Normalize

func Unsep

func Unsep(separator string) Normalize

type Transform

type Transform func([]string) []string

Transform the normalized name. Can be used for up-/downcase conversion or adding pre- or postfixes.

func ChainX

func ChainX(xs ...Transform) Transform

ChainX creates a Transform function that applies all xs functions in order.

func PerSegment

func PerSegment(x func(string) string) Transform

PerSegment creates a Transform function that replaces each name segment s in place with the result of x(s).

func Postfix

func Postfix(pfs ...string) Transform

Postfix creates a Transform function that adds segmens at the end of a noramlized name.

func Prefix

func Prefix(pfs ...string) Transform

Prefix creates a Transform function that adds segmens at the beginning of a noramlized name.

Jump to

Keyboard shortcuts

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