inflect

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package inflect provides minimal, allocation-conscious string transformations used across the framework (snake_case, plural table names, etc.). It is intentionally small: callers may register irregulars at init time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Camel

func Camel(s string) string

Camel converts snake_case to camelCase.

func ForeignKey

func ForeignKey(structName string) string

ForeignKey returns the conventional foreign-key column for a struct name. e.g. "User" -> "user_id".

func Pascal

func Pascal(s string) string

Pascal converts snake_case to PascalCase. If the input already looks like CamelCase or PascalCase (no underscores, contains at least one uppercase letter), the existing casing is preserved and only the first character is upper-cased. This avoids destroying acronyms or compound names like "TagService" or "HTTPRequest" when the CLI re-normalizes user-supplied identifiers.

func Pluralize

func Pluralize(word string) string

Pluralize returns the (English) plural of word.

func RegisterIrregular

func RegisterIrregular(singular, plural string)

RegisterIrregular adds or overrides an irregular plural mapping.

func Singularize

func Singularize(word string) string

Singularize returns the singular form of word (best-effort).

func Snake

func Snake(s string) string

Snake converts CamelCase or PascalCase to snake_case.

"UserID"        -> "user_id"
"HTTPRequest"   -> "http_request"
"PostCommentID" -> "post_comment_id"

func Table

func Table(structName string) string

Table returns the conventional table name for a struct name: snake_case + pluralized. e.g. "UserProfile" -> "user_profiles".

Types

This section is empty.

Jump to

Keyboard shortcuts

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