nameconv

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: Apache-2.0 Imports: 3 Imported by: 1

README

UnitTest reviewdog codecov Go Reference Go Report Card
[日本語]

nameconv

nameconv is library that converts string naming conventions.

Convert functions

The following function converts the string passed as an argument to the specified naming convention.

function description
ToSnakeCase() convert string to snake_case style
ToChainCase() convert string to chain-case style
ToKebabCase() same as ToChainCase()
ToCamelCase() convert string to camelCase style
ToPascalCase() convert string to PascalCase style
ToFlatCase() convert string to flatcase style
ToUpperCase() convert string to UPPER_CASE style

Check naming convention

The following function returns true if the naming convention is as expected, false otherwise.

function description
IsSnakeCase() check whether string is snake_case style or not
IsChainCase() check whether string is chain-case style or not
IsKebabCase() same as IsChainCase()
IsCamelCase() check whether string is camelCase style or not
IsPascalCase() check whether string is PascalCase style or not
IsFlatCase() check whether string is flatcase style or not
IsUpperCase() check whether string is UPPER_CASE style or not

If first character is digit, IsCamelCase(), IsPascalCase(), IsFlatCase() always returns false. Because function can not judge upper or lower.

Example

package main

import (
	"fmt"

	"github.com/nao1215/nameconv"
)

func main() {
	fmt.Println(nameconv.ToSnakeCase("dave mustaine"))            // dave_mustaine
	fmt.Println(nameconv.ToChainCase("TifaLockhart"))             // tifa-lockhart
	fmt.Println(nameconv.ToKebabCase("The_Shawshank_Redemption")) // the-shawshank-redemption
	fmt.Println(nameconv.ToCamelCase("master-of_puppets"))        // masterOfPuppets
	fmt.Println(nameconv.ToPascalCase("Miracles_outOf-nowhere"))  // MiraclesOutOfNowhere
	fmt.Println(nameconv.ToFlatCase("SolBadguy"))                 // Sol badguy
	fmt.Println(nameconv.ToUpperCase("heaven and hell"))          // HEAVEN_AND_HELL

	fmt.Println(nameconv.IsSnakeCase("snake_case"))  // true
	fmt.Println(nameconv.IsChainCase("chain-case"))  // true
	fmt.Println(nameconv.IsKebabCase("kebab case"))  // false
	fmt.Println(nameconv.IsCamelCase("CamelCase"))   // false
	fmt.Println(nameconv.IsPascalCase("pascalCase")) // false
	fmt.Println(nameconv.IsFlatCase("flat-case"))    // false
	fmt.Println(nameconv.IsUpperCase("0_UPPER"))     // true
}

Contact

If you would like to send comments such as "find a bug" or "request for additional features" to the developer, please use one of the following contacts.

GitHub Issue

LICENSE

The nameconv project is the mixed-license.

  • MIT License(casee*.go and camelcase*.go)
  • Apache License Version 2.0(All codes other than the above)

The authors of the MIT license source code are pinzolo and Fatih Arslan. The code written by each author clearly states the full MIT license and Copyright.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCamelCase

func IsCamelCase(s string) bool

IsCamelCase check whether string is camelCase style or not. true: string is camel case, false: other. If first character is digit, always returns false

func IsChainCase

func IsChainCase(s string) bool

IsChainCase check whether string is chain-case style. true: string is chain case, false: other

func IsFlatCase

func IsFlatCase(s string) bool

IsFlatCase check whether string is flatcase style or not. true: string is flat case, false: other. If first character is digit, always returns false

func IsKebabCase

func IsKebabCase(s string) bool

IsKebabCase check whether string is kebab-case style. It's same as IsChainCase(). true: string is chain case, false: other

func IsPascalCase

func IsPascalCase(s string) bool

IsPascalCase check whether string is PascalCase style or not. true: string is pascal case, false: other. If first character is digit, always returns false

func IsSnakeCase

func IsSnakeCase(s string) bool

IsSnakeCase check whether string is snake_case style or not. true: string is snake case, false: other

func IsUpperCase

func IsUpperCase(s string) bool

IsUpperCase check whether string is UPPER_CASE style or not. true: string is flat case, false: other.

func ToCamelCase

func ToCamelCase(s string) string

ToCamelCase convert string to camelCase style. If argument is empty, return itself

func ToChainCase

func ToChainCase(s string) string

ToChainCase convert string to chain-case style. If argument is empty, return itself.

func ToFlatCase

func ToFlatCase(s string) string

ToFlatCase convert string to flatcase style. If argument is empty, return itself

func ToKebabCase

func ToKebabCase(s string) string

ToKebabCase convert string to kebab-case style. It's same as ToChainCase(). If argument is empty, return itself.

func ToPascalCase

func ToPascalCase(s string) string

ToPascalCase convert string to PascalCase style. If argument is empty, return itself

func ToSnakeCase

func ToSnakeCase(s string) string

ToSnakeCase convert string to snake_case style. If argument is empty, return itself.

func ToUpperCase

func ToUpperCase(s string) string

ToUpperCase convert string to UPPER_CASE style. If argument is empty, return itself.

Types

This section is empty.

Jump to

Keyboard shortcuts

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