{"id":17355203,"url":"https://github.com/zephinzer/go-strcase","last_synced_at":"2025-03-27T15:21:59.678Z","repository":{"id":57631515,"uuid":"410190160","full_name":"zephinzer/go-strcase","owner":"zephinzer","description":"Case conversion library for Go","archived":false,"fork":false,"pushed_at":"2021-11-19T02:31:15.000Z","size":39,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-01T19:14:07.696Z","etag":null,"topics":["case","case-converter","go","golang","golang-package","reflect","reflection","reflection-library","variable-names","variable-naming"],"latest_commit_sha":null,"homepage":"https://gitlab.com/zephinzer/go-strcase","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zephinzer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-25T06:01:14.000Z","updated_at":"2021-11-19T02:31:18.000Z","dependencies_parsed_at":"2022-09-04T22:33:06.390Z","dependency_job_id":null,"html_url":"https://github.com/zephinzer/go-strcase","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zephinzer%2Fgo-strcase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zephinzer%2Fgo-strcase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zephinzer%2Fgo-strcase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zephinzer%2Fgo-strcase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zephinzer","download_url":"https://codeload.github.com/zephinzer/go-strcase/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245868335,"owners_count":20685609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["case","case-converter","go","golang","golang-package","reflect","reflection","reflection-library","variable-names","variable-naming"],"created_at":"2024-10-15T17:42:37.130Z","updated_at":"2025-03-27T15:21:59.654Z","avatar_url":"https://github.com/zephinzer.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-strcase\n\n![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/zephinzer/go-strcase)\n[![pipeline status](https://gitlab.com/zephinzer/go-strcase/badges/master/pipeline.svg)](https://gitlab.com/zephinzer/go-strcase/-/commits/master)\n[![coverage report](https://gitlab.com/zephinzer/go-strcase/badges/master/coverage.svg)](https://gitlab.com/zephinzer/go-strcase/-/commits/master)\n\nA string case converter for use in Golang applications.\n\n- [go-strcase](#go-strcase)\n- [Usage](#usage)\n  - [Importing](#importing)\n  - [Methods](#methods)\n    - [`ToCamel`](#tocamel)\n    - [`ToCapital`](#tocapital)\n    - [`ToFlat`](#toflat)\n    - [`ToLowerKebab`](#tolowerkebab)\n    - [`ToLowerSnake`](#tolowersnake)\n    - [`ToUpperKebab`](#toupperkebab)\n    - [`ToUpperSnake`](#touppersnake)\n  - [Constraints/design decisions](#constraintsdesign-decisions)\n    - [Character delimiters](#character-delimiters)\n    - [Casing delimiters](#casing-delimiters)\n    - [Number delimiters](#number-delimiters)\n    - [Additional trivia](#additional-trivia)\n- [Code design (how it works)](#code-design-how-it-works)\n  - [Requirements](#requirements)\n  - [Tokenization](#tokenization)\n  - [Reconciliation](#reconciliation)\n- [Contributing](#contributing)\n  - [Changelog](#changelog)\n- [License](#license)\n\n# Usage\n\n## Importing\n\n```go\nimport \"github.com/zephinzer/go-strcase\"\n```\n\n## Methods\n\n### `ToCamel`\n\nUse this if you want your string to `lookLikeThisFormat`\n\n```go\nfmt.Printf(\"camel case: %s\", strcase.ToCamel(\"hello world\"))\n// output: helloWorld\n```\n\n\u003e Useful for: **C-like sematics, JSON, YAML**\n\n### `ToCapital`\n\nUse this if you want your string to `LookLikeThis`\n\n```go\nfmt.Printf(\"capital case: %s\", strcase.ToCamel(\"hello world\"))\n// output: HelloWorld\n```\n\nAliases: `ToCapitalCamel`, `ToPascal`\n\n\u003e Useful for: **C-like sematics**\n\n### `ToFlat`\n\nUse this if you want your string to `looklikethis`\n\n```go\nfmt.Printf(\"flat case: %s\", strcase.ToFlat(\"helloGreatBigWorld\"))\n// output: hellogreatbigworld\n```\n\nAliases: `ToLazy`\n\n\u003e Useful for: **Java/Gopackage names**\n\n### `ToLowerKebab`\n\nUse this if you want your string to `look-like-this`\n\n```go\nfmt.Printf(\"lower kebab case: %s\", strcase.ToCamel(\"hello world\"))\n// output: hello-world\n```\n\nAliases: `ToCaterpillar`, `ToCSS`, `ToDash`, `ToHyphen`, `ToLazy`, `ToLisp`\n\n\u003e Useful for: **JSON, YAML**\n\n### `ToLowerSnake`\n\nUse this if you want your string to `look_like_this`\n\n```go\nfmt.Printf(\"lower snake case: %s\", strcase.ToCamel(\"hello world\"))\n// output: hello_world\n```\n\n\u003e Useful for: **Python, Perl, Shell**, JSON, YAML\n\n### `ToUpperKebab`\n\nUse this if you want your string to `LOOK-LIKE-THIS`\n\n```go\nfmt.Printf(\"upper kebab case: %s\", strcase.ToCamel(\"hello world\"))\n// output: HELLO-WORLD\n```\n\nAliases: `ToMacro`\n\n\u003e Useful for: **?**\n\n### `ToUpperSnake`\n\nUse this if you want your string to `LOOK_LIKE_THIS`\n\n```go\nfmt.Printf(\"upper snake case: %s\", strcase.ToCamel(\"hello world\"))\n// output: HELLO_WORLD\n```\n\n\u003e Useful for: **Shell**, JSON, YAML\n\n## Constraints/design decisions\n\n### Character delimiters\n\n- Only dashes, underscores, spaces are considered as character delimtiers (eg. `a-pizza`, `a_pizza`, and `a pizza` are seens as `a` and `pizza`)\n- Character delimitations take precedence over the other delimiters (eg. `i want 1 Pizza` is `[i, want, 1, Pizza]`, but `iWant1Pizza` is `[i, want1, pizza]`)\n\n### Casing delimiters\n\n- An upper-cased character is considered a delimiter only when the character after that is a lower-cased character (eg. `APizza` is seen as `A` and `Pizza`, but `sendAPIRequest` is seen as `[send, api, request]`)\n\n### Number delimiters\n\n- The end of any series of numbers is considered a delimiter. This decision was made since variable names usually cannot begin with a number (eg. `1pizza` is `[1, pizza]`, but `pizza1` is `[pizza1]`)\n\n### Additional trivia\n\n- After writing the above, the world pizza doesn't hold any more meaning in my mind. Send help.\n\n# Code design (how it works)\n\n## Requirements\n\nThis package was created mainly for usage within a tool that needs to handle cross-runtime naming conventions such as between `SHELL_VARIABLES` and `javascriptVars` or `python_vars`\n\n## Tokenization\n\nThis package works by first tokenizing the input string into separate words first before applying any transformations. This looks like:\n\n```\nHelloWorld =\u003e [hello, world]\nhelloWorld =\u003e [hello, world]\n10PizzasPlease =\u003e [10, pizzas, please]\n1-for-1 =\u003e [1, for, 1]\n1for1 =\u003e [1, for1]\n```\n\n## Reconciliation\n\nAfter the above tokenization, the transformations are added:\n\n```\n[hello, world] =(ToCamel)=\u003e helloWorld\n[10, pizzas, please] =(ToCamel)=\u003e 10PizzasPlease\n[1, for, 1] =(ToCamel)=\u003e 1For1\n[1, for1] =(ToCamel)=\u003e 1For1\n```\n\n# Contributing\n\nThe working repository is at Gitlab at [https://gitlab.com/zephinzer/go-strcase](https://gitlab.com/zephinzer/go-strcase), if you are seeing this on Github, it's just for SEO since y'know all the cool new kids are on Github 😂\n\n## Changelog\n\nA rough changelog when the contributors can remember to add it is here:\n\n| Version  | Description                                                                                                                                 |\n| -------- | ------------------------------------------------------------------------------------------------------------------------------------------- |\n| `v1.0.1` | Added code comments for just-in-time documentation, added alises for a few of the case names                                                |\n| `v1.0.0` | Initial release with support for `camelCase`, `CapitalCase`, `lower-kebab-case`, `lower_snake_case`, `UPPER-KEBAB-CASE`, `UPPER_SNAKE_CASE` |\n\n# License\n\nUse this anywhere you need to. Licensed under [the MIT license](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzephinzer%2Fgo-strcase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzephinzer%2Fgo-strcase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzephinzer%2Fgo-strcase/lists"}