name

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2019 License: CC0-1.0 Imports: 2 Imported by: 72

README

API Documentation Build Status

Naming convention library for the Go programming language. The functions offer flexible parsing and strict formatting for label techniques such as snake_case, Lisp-case, CamelCase and (Java) property keys.

This is free and unencumbered software released into the public domain.

Inspiration

  • name.CamelCase("pascal case", true) returns PascalCase
  • name.CamelCase("snake_to_camel AND CamelToCamel?", false) returns snakeToCamelANDCamelToCamel
  • name.Delimit("* All Hype is aGoodThing (TM)", '-') returns all-hype-is-a-good-thing-TM
  • name.DotSeparated("WebCrawler#socketTimeout") returns web.crawler.socket.timeout

Documentation

Overview

Package name implements naming conventions. The functions offer flexible parsing and strict formatting for label techniques such as snake_case, Lisp-case, CamelCase and (Java) property keys.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CamelCase

func CamelCase(s string, upper bool) string

CamelCase returns the medial capitals form of word sequence s. The input can be any case or even just a bunch of words. Upper case sequences (abbreviations) are preserved. Argument upper forces the letter case for the first rune. Use true for UpperCamelCase and false for lowerCamelCase.

Example
package main

import (
	"fmt"
	"github.com/pascaldekloe/name"
)

func main() {
	fmt.Println(name.CamelCase("pascal case", true))
	fmt.Println(name.CamelCase("snake_to_camel AND CamelToCamel?", false))

}
Output:
PascalCase
snakeToCamelANDCamelToCamel

func Delimit

func Delimit(s string, sep rune) string

Delimit returns word sequence s delimited with separator sep. The input can be any case or even just a bunch of words. Upper case sequences (abbreviations) are preserved. Use strings.ToLower and strings.ToUpper to enforce a letter case.

Example
package main

import (
	"fmt"
	"github.com/pascaldekloe/name"
)

func main() {
	// Garbage to Lisp-case:
	fmt.Println(name.Delimit("* All Hype is aGoodThing (TM)", '-'))

	// Builds a Java property key:
	fmt.Println(name.DotSeparated("WebCrawler#socketTimeout"))

}
Output:
all-hype-is-a-good-thing-TM
web.crawler.socket.timeout

func DotSeparated

func DotSeparated(s string) string

DotSeparated is an alias for Delimit(s, '.').

func SnakeCase

func SnakeCase(s string) string

SnakeCase is an alias for Delimit(s, '_').

Types

This section is empty.

Jump to

Keyboard shortcuts

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