strcase

A lightweight Go library for converting strings to snake_case, kebab-case, or CamelCase.

Library
Go
vv0.3.0
1,143stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
36/100Needs Attention
Development Activity0
Maintenance0
Community56
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
66/100Good
Architecture72
Code Quality68
Innovation78
Learning Curve45

strcase is a focused Go library for converting strings between casing conventions. It exposes functions for snake_case, SCREAMING_SNAKE_CASE, kebab-case, SCREAMING-KEBAB-CASE, CamelCase, and lowerCamelCase, all built on top of a general ToScreamingDelimited primitive that also supports fully custom delimiters and a per-call ignore list for characters that shouldn’t trigger a new delimiter.

Beyond straightforward conversion, strcase lets callers register custom acronym mappings through ConfigureAcronym, backed by a concurrency-safe sync.Map, so abbreviations like API or TTM convert to a single predictable token instead of being split apart letter-by-letter. With no external dependencies and a compact, single-purpose codebase, it’s a common choice for database-to-struct field mapping, JSON key normalization, and code generators that need consistent identifier casing.

What You Get

  • A small set of pure functions (ToSnake, ToScreamingSnake, ToKebab, ToScreamingKebab, ToCamel, ToLowerCamel) covering the common case-conversion needs.
  • ToDelimited and ToScreamingDelimited primitives for building custom delimited case formats beyond the built-in presets.
  • A global, thread-safe acronym registry (ConfigureAcronym) to control how consecutive capital letters are treated during conversion.
  • Zero external dependencies and a single-file-per-concern layout (camel.go, snake.go, acronyms.go) that’s easy to audit or vendor.

Common Use Cases

  • Converting database column names to CamelCase struct fields for ORMs
  • Normalizing JSON keys between snake_case APIs and Go conventions
  • Generating consistent identifiers in code-generation tools
  • Deriving environment variable or CLI flag names from a canonical field name

Under The Hood

Architecture strcase is a single flat package with no internal layering: snake.go defines ToScreamingDelimited as the core conversion primitive, with ToSnake, ToScreamingSnake, ToKebab, and ToScreamingKebab implemented as thin wrappers around it, while camel.go implements a separate toCamelInitCase algorithm for the two camel-case variants; both files share a package-level acronym lookup defined in acronyms.go. As a leaf utility library with no interfaces, structs, or dependency injection, there is little to “break” architecturally - the design trades layering for directness, which suits its narrow scope well.

Tech Stack The module targets Go 1.16 and depends on nothing beyond the standard library (strings for byte-level string building, sync for the concurrent acronym map). There is no build tooling beyond go build/go test; CI is configured via a legacy .travis.yml matrix spanning Go 1.10 through 1.15 plus master, with no evidence of a modern GitHub Actions workflow.

Code Quality Test coverage is reasonably thorough for the package’s size: camel_test.go and snake_test.go together contain a large set of table-driven cases covering screaming variants, custom delimiters, and ignore-character behavior, and a dedicated concurrency_test.go exercises ConfigureAcronym under concurrent goroutines to validate the sync.Map choice. There is no visible linter configuration and the CI matrix is dated, but naming is idiomatic Go and the functions are pure with no error-swallowing since none of them return errors.

API Design The public API is intentionally minimal - every conversion function takes a plain string and returns a plain string, so getting started requires nothing beyond strcase.ToCamel(s). Acronym customization is opt-in through a single ConfigureAcronym call rather than mandatory setup, and the naming scheme (To<Case>, ToScreaming<Case>) is consistent enough to guess unfamiliar functions correctly. The README’s conversion table doubles as inline documentation, though the package lacks runnable Go example functions (example_test.go) that would otherwise surface in GoDoc.

Used by 5 apps in this directory

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search