{"id":15681729,"url":"https://github.com/danielgtaylor/casing","last_synced_at":"2025-06-15T13:33:55.977Z","repository":{"id":57584675,"uuid":"332342533","full_name":"danielgtaylor/casing","owner":"danielgtaylor","description":"An intelligent casing conversion library for Go","archived":false,"fork":false,"pushed_at":"2024-02-01T17:49:15.000Z","size":9,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-07T10:14:35.536Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/danielgtaylor.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-24T01:16:08.000Z","updated_at":"2024-11-19T13:11:03.000Z","dependencies_parsed_at":"2024-06-19T17:53:21.430Z","dependency_job_id":null,"html_url":"https://github.com/danielgtaylor/casing","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielgtaylor%2Fcasing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielgtaylor%2Fcasing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielgtaylor%2Fcasing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielgtaylor%2Fcasing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielgtaylor","download_url":"https://codeload.github.com/danielgtaylor/casing/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252856558,"owners_count":21814858,"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":[],"created_at":"2024-10-03T16:59:25.567Z","updated_at":"2025-05-07T10:14:45.100Z","avatar_url":"https://github.com/danielgtaylor.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Casing\n\nA small Go library to switch between CamelCase, lowerCamelCase, snake_case, and kebab-case, among others. Features:\n\n- Unicode support 👩‍💻\n- Intelligent `Split` function\n- Camel, lowerCamel, snake, and kebab casing built-in\n- Extensible via simple composition\n- Optional handling of initialisms like `ID` and `HTTP`\n\nAlternatives\n\nI wrote this library because the below ones don't support unicode, or have strange edge cases, or used a different implementation approach that was less flexible / extensible. They are good projects worth linking to nonetheless, and inspired me to create this library.\n\n- [iancoleman/strcase](https://github.com/iancoleman/strcase)\n- [gobeam/stringy](https://github.com/gobeam/stringy)\n- [segmentio/go-camelcase](https://github.com/segmentio/go-camelcase)\n\nDue to the different approaches I decided to create a new library rather than submitting a PR to completely rewrite their projects, potentially introducing unexpected behavior or breaking their existing users.\n\n## Usage\n\nThe library is easy to get started with:\n\n```go\nimport \"github.com/danielgtaylor/casing\"\n\ninput := \"AnyKind of_string\"\n\n// Convert to different cases!\nfmt.Println(casing.Camel(input))\nfmt.Println(casing.LowerCamel(input))\nfmt.Println(casing.Snake(input))\nfmt.Println(casing.Kebab(input))\n\n// Unicode works too!\nfmt.Println(casing.Snake(\"UnsinnÜberall🎉\"))\n```\n\nIf you would rather convert unicode characters to ASCII approximations, check out [rainycape/unidecode](https://github.com/rainycape/unidecode) as a potential preprocessor.\n\n### Transforms\n\nEach casing function can also take in `TransformFunc` parameters that apply a transformation to each part of a split string. Here is a simple identity transform showing how to write such a function:\n\n```go\n// Identity returns the same part that was passed in.\nfunc Identity(part string) string {\n\treturn part\n}\n```\n\nYou may notice the transform function signature matches some existing standard library signatures, for example `strings.ToLower` and `strings.ToUpper`. These can be used directly as transform functions without needing to wrap them.\n\nThis supports any number of transformations before the casing join operation. For one example use-case, imagine generating Go code and you want to generate a public variable name that might contain an initialism that should be capitalized:\n\n```go\n// Generates `UserID` which passes go-lint\nname := casing.Camel(\"USER_ID\", strings.ToLower, casing.Initialism)\n```\n\nTransformations are applied in-order and provide a powerful way to customize output for many different use-cases.\n\nIf no transformation function is passed in, then `strings.ToLower` is used by default. You can pass in the identity function to disable this behavior.\n\n### Split, Join \u0026 Merge\n\nThe library also exposes intelligent split and join functions along with the ability to merge some parts together before casing, which are used by the high-level casing functions above.\n\n```go\n// Returns [\"Any\", \"Kind\", \"of\", \"STRING\"]\nparts := casing.Split(\"AnyKind of_STRING\")\n\n// Returns \"Any.Kind.Of.String\"\ncasing.Join(parts, \".\", strings.ToLower, strings.Title)\n```\n\nThere is also a function to merge numbers in some cases for nicer output. This is useful when joining with a separator and you want to prevent separators between some parts that are prefixed or suffixed with numbers. for example:\n\n```go\n// Splits into [\"mp\", \"3\", \"player\"]\nparts := casing.Split(\"mp3 player\")\n\n// Merges into [\"mp3\", \"player\"]\nmerged := casing.MergeNumbers(parts)\n\n// Returns \"MP3.Player\"\ncasing.Join(merged, \".\", strings.Title, casing.Initialism)\n```\n\nTogether these primitives make it easy to build your own custom casing if needed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielgtaylor%2Fcasing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielgtaylor%2Fcasing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielgtaylor%2Fcasing/lists"}