{"id":13879671,"url":"https://github.com/piotrmurach/strings-case","last_synced_at":"2025-06-25T06:04:23.955Z","repository":{"id":56896781,"uuid":"220563381","full_name":"piotrmurach/strings-case","owner":"piotrmurach","description":"Convert strings between different cases.","archived":false,"fork":false,"pushed_at":"2024-03-10T22:06:27.000Z","size":145,"stargazers_count":97,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-12T13:09:26.029Z","etag":null,"topics":["conversions","convert-strings","ruby","rubygem","string-casing","string-conversion","strings"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/piotrmurach.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null},"funding":{"github":"piotrmurach"}},"created_at":"2019-11-08T23:25:43.000Z","updated_at":"2024-10-02T17:59:37.000Z","dependencies_parsed_at":"2022-08-20T17:10:33.307Z","dependency_job_id":"52c414f9-fa6e-4fcd-86d7-4447f890b809","html_url":"https://github.com/piotrmurach/strings-case","commit_stats":{"total_commits":66,"total_committers":2,"mean_commits":33.0,"dds":"0.015151515151515138","last_synced_commit":"f9701eedf0cda97c0c1f46a0a7451215335f378b"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/piotrmurach/strings-case","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Fstrings-case","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Fstrings-case/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Fstrings-case/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Fstrings-case/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/piotrmurach","download_url":"https://codeload.github.com/piotrmurach/strings-case/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Fstrings-case/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261816306,"owners_count":23213862,"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":["conversions","convert-strings","ruby","rubygem","string-casing","string-conversion","strings"],"created_at":"2024-08-06T08:02:28.425Z","updated_at":"2025-06-25T06:04:23.934Z","avatar_url":"https://github.com/piotrmurach.png","language":"Ruby","readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"225\" src=\"https://github.com/piotrmurach/strings/blob/master/assets/strings_logo.png\" alt=\"strings logo\" /\u003e\n\u003c/div\u003e\n\n# Strings::Case\n\n[![Gem Version](https://badge.fury.io/rb/strings-case.svg)][gem]\n[![Actions CI](https://github.com/piotrmurach/strings-case/actions/workflows/ci.yml/badge.svg)][gh_actions_ci]\n[![Build status](https://ci.appveyor.com/api/projects/status/yr87c96wxp1cw2ep?svg=true)][appveyor]\n[![Maintainability](https://api.codeclimate.com/v1/badges/7938258c4af196a19843/maintainability)][codeclimate]\n[![Coverage Status](https://coveralls.io/repos/github/piotrmurach/strings-case/badge.svg?branch=master)][coverage]\n\n[gem]: http://badge.fury.io/rb/strings-case\n[gh_actions_ci]: https://github.com/piotrmurach/strings-case/actions/workflows/ci.yml\n[appveyor]: https://ci.appveyor.com/project/piotrmurach/strings-case\n[codeclimate]: https://codeclimate.com/github/piotrmurach/strings-case/maintainability\n[coverage]: https://coveralls.io/github/piotrmurach/strings-case?branch=master\n\n\u003e Convert strings to different cases.\n\n**Strings::Case** provides string case conversions for\n[Strings](https://github.com/piotrmurach/strings) utilities.\n\n## Features\n\n* No monkey-patching String class\n* Convert strings to many common cases\n* Support for Unicode characters\n* Preserve acronyms\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem \"strings-case\"\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install strings-case\n\n## Contents\n\n* [1. Usage](#1-usage)\n* [2. API](#2-api)\n  * [2.1 configure](#21-configure)\n  * [2.2 camelcase](#22-camelcase)\n  * [2.3 constcase](#23-constcase)\n  * [2.4 headercase](#24-headercase)\n  * [2.5 kebabcase \\| dashcase](#25-kebabcase--dashcase)\n  * [2.6 pascalcase](#26-pascalcase)\n  * [2.7 pathcase](#27-pathcase)\n  * [2.8 sentencecase](#28-sentencecase)\n  * [2.9 snakecase \\| underscore](#29-snakecase--underscore)\n  * [2.10 titlecase](#210-titlecase)\n* [3. Extending String class](#3-extending-string-class)\n\n## 1. Usage\n\nStart by creating an instance of the `Strings::Case` class:\n\n```ruby\nstrings = Strings::Case.new\n```\n\nThen, use one of many case conversion methods, for example,\nthe `snakecase` method:\n\n```ruby\nstrings.snakecase(\"FooBarBaz\")\n# =\u003e \"foo_bar_baz\"\n```\n\nAs a convenience, case conversion methods are also available on class:\n\n```ruby\nStrings::Case.snakecase(\"FooBarBaz\")\n# =\u003e \"foo_bar_baz\"\n```\n\nCase conversion methods will transform any string into an expected case:\n\n```ruby\nstrings.snakecase(\"supports IPv6 on iOS?\")\n# =\u003e \"supports_i_pv6_on_i_os\"\n```\n\nThe methods also support converting Unicode characters:\n\n```ruby\nstrings.snakecase(\"ЗдравствуйтеПривет\")\n# =\u003e \"здравствуйте_привет\"\n```\n\nTo preserve acronyms for all case conversions, configure them once\non an instance:\n\n```ruby\nstrings.configure do |config|\n  config.acronym \"IPv6\"\n  config.acronym \"iOS\"\nend\n```\n\nThis will preserve acronyms for any case conversion method:\n\n```ruby\nstrings.snakecase(\"supports IPv6 on iOS?\")\n# =\u003e \"supports_ipv6_on_ios\"\n```\n\nOr, use the `acronyms` keyword in a case conversion method:\n\n```ruby\nstrings.snakecase(\"supports IPv6 on iOS?\", acronyms: %w[IPv6 iOS])\n# =\u003e \"supports_ipv6_on_ios\"\n```\n\nHere is a quick summary of available case conversions:\n\n| Case Type                     | Result          |\n| ----------------------------- | --------------- |\n| `camelcase(\"foo bar baz\")`    | `\"fooBarBaz\"`   |\n| `constcase(\"foo bar baz\")`    | `\"FOO_BAR_BAZ\"` |\n| `headercase(\"foo bar baz\")`   | `\"Foo-Bar-Baz\"` |\n| `kebabcase(\"foo bar baz\")`    | `\"foo-bar-baz\"` |\n| `pascalcase(\"foo bar baz\")`   | `\"FooBarBaz\"`   |\n| `pathcase(\"foo bar baz\")`     | `\"foo/bar/baz\"` |\n| `sentencecase(\"foo bar baz\")` | `\"Foo bar baz\"` |\n| `snakecase(\"foo bar baz\")`    | `\"foo_bar_baz\"` |\n| `titlecase(\"foo bar baz\")`    | `\"Foo Bar Baz\"` |\n\n## 2. API\n\n### 2.1 configure\n\nUse the `acronyms` keyword at initialization to add acronyms for all\ncase conversions.\n\nFor example, to add `HTTP` and `XML` acronyms:\n\n```ruby\nstrings = Strings::Case.new(acronyms: %w[HTTP XML])\n```\n\nAfter initialization, use the `configure` method to add acronyms\nin a block with the `acronym` method:\n\n```ruby\nstrings.configure do |config|\n  config.acronym \"HTTP\"\n  config.acronym \"XML\"\n\n  # or config.acronym \"HTTP\", \"XML\"\nend\n```\n\nOr, use the `configure` method with the `acronyms` keyword:\n\n```ruby\nstrings.configure(acronyms: %w[HTTP XML])\n```\n\nThis will result in a conversion preserving acronyms:\n\n```ruby\nstrings.camelcase(\"xml_http_request\")\n# =\u003e \"XMLHTTPRequest\"\n```\n\n### 2.2 camelcase\n\nUse the `camelcase` method to convert a string into a camel case. It will\nlowercase first and capitalise all remaining words, joining them by\nremoving any space. For example:\n\n```ruby\nstrings.camelcase(\"PostgreSQL adapter\")\n# =\u003e \"postgreSqlAdapter\"\n```\n\nUse the `acronyms` keyword to preserve acronyms:\n\n```ruby\nstrings.camelcase(\"PostgreSQL adapter\", acronyms: [\"PostgreSQL\"])\n# =\u003e \"PostgreSQLAdapter\"\n```\n\n### 2.3 constcase\n\nUse the `constcase` method to convert a string into a constant case. It will\nuppercase all words and separate them with an underscore `_`. For example:\n\n```ruby\nstrings.constcase(\"PostgreSQL adapter\")\n# =\u003e \"POSTGRE_SQL_ADAPTER\"\n```\n\nUse the `acronyms` keyword to preserve acronyms:\n\n```ruby\nstrings.constcase(\"PostgreSQL adapter\", acronyms: [\"PostgreSQL\"])\n# =\u003e \"POSTGRESQL_ADAPTER\"\n```\n\n### 2.4 headercase\n\nUse the `headercase` method to convert a string into a header case. It will\ncapitalise all words and separate them with a hyphen `-`. For example:\n\n```ruby\nstrings.headercase(\"PostgreSQL adapter\")\n# =\u003e \"Postgre-Sql-Adapter\"\n```\n\nUse the `acronyms` keyword to preserve acronyms:\n\n```ruby\nstrings.headercase(\"PostgreSQL adapter\", acronyms: [\"PostgreSQL\"])\n# =\u003e \"PostgreSQL-Adapter\"\n```\n\n### 2.5 kebabcase | dashcase\n\nUse the `kebabcase` or `dashcase` method to convert a string into a kebab case.\nIt will lowercase all words and separate them with a dash `-` like a words\nkebab on a skewer. For example:\n\n```ruby\nstrings.kebabcase(\"PostgreSQL adapter\")\n# =\u003e \"postgre-sql-adapter\"\n```\n\nUse the `acronyms` keyword to preserve acronyms:\n\n```ruby\nstrings.dashcase(\"PostgreSQL adapter\", acronyms: [\"PostgreSQL\"])\n# =\u003e \"postgresql-adapter\"\n```\n\n### 2.6 pascalcase\n\nUse the `pascalcase` method to convert a string into a Pascal case. It will\ncapitalise all words and join them by removing any space. For example:\n\n```ruby\nstrings.pascalcase(\"PostgreSQL adapter\")\n# =\u003e \"PostgreSqlAdapter\"\n```\n\nUse the `acronyms` keyword to preserve acronyms:\n\n```ruby\nstrings.pascalcase(\"PostgreSQL adapter\", acronyms: [\"PostgreSQL\"])\n# =\u003e \"PostgreSQLAdapter\"\n```\n\n### 2.7 pathcase\n\nUse the `pathcase` to convert a string into a path case. It will lowercase\nall words and join them with a forward slash `/`. For example:\n\n```ruby\nstrings.pathcase(\"PostgreSQL adapter\")\n# =\u003e \"postgre/sql/adapter\"\n```\n\nUse the `acronyms` keyword to preserve acronyms:\n\n```ruby\nstrings.pathcase(\"PostgreSQL adapter\", acronyms: [\"PostgreSQL\"])\n# =\u003e \"postgresql/adapter\"\n```\n\nUse the `separator` keyword to change the default forward slash `/` path\nseparator. For example, to use backslash `\\` as a path separator:\n\n```ruby\nstrings.pathcase(\"PostgreSQL adapter\", separator: \"\\\\\")\n# =\u003e \"postgre\\\\sql\\\\adapter\"\n```\n\n### 2.8 sentencecase\n\nUse the `sentencecase` to convert a string into a sentence case. It will\ncapitalise first and lowercase all remaining words, separating them with\nspace. For example:\n\n```ruby\nstrings.sentencecase(\"PostgreSQL adapter\")\n# =\u003e \"Postgre sql adapter\"\n```\n\nUse the `acronyms` keyword to preserve acronyms:\n\n```ruby\nstrings.sentencecase(\"PostgreSQL adapter\", acronyms: [\"PostgreSQL\"])\n# =\u003e \"PostgreSQL adapter\"\n```\n\n### 2.9 snakecase | underscore\n\nUse the `snakecase` or `underscore` method to convert a string into\na snake case. It will lowercase all words and separate them with\nan underscore `_`. For example:\n\n```ruby\nstrings.snakecase(\"PostgreSQL adapter\")\n# =\u003e \"postgre_sql_adapter\"\n```\n\nUse the `acronyms` keyword to preserve acronyms:\n\n```ruby\nstrings.underscore(\"PostgreSQL adapter\", acronyms: [\"PostgreSQL\"])\n# =\u003e \"postgresql_adapter\"\n```\n\n### 2.10 titlecase\n\nUse `titlecase` to convert a string into a title case. It will capitalise all\nwords and separate them with space. For example:\n\n```ruby\nstrings.titlecase(\"PostgreSQL adapter\")\n# =\u003e \"Postgre Sql Adapter\"\n```\n\nUse the `acronyms` keyword to preserve acronyms:\n\n```ruby\nstrings.titlecase(\"PostgreSQL adapter\", acronyms: [\"PostgreSQL\"])\n# =\u003e \"PostgreSQL Adapter\"\n```\n\n## 3. Extending String class\n\nPolluting core Ruby classes globally may have unintended consequences.\nInstead, consider adding the required methods to the `String` class\nusing refinements.\n\nFor example, to extend the `String` class with only the `snakecase` method:\n\n```ruby\nmodule MyStringExt\n  refine String do\n    def snakecase(*args)\n      Strings::Case.snakecase(self, *args)\n    end\n  end\nend\n```\n\nThen using refinement will make the `snakecase` method available\nfor any string:\n\n```ruby\nusing MyStringExt\n\n\"foo bar baz\".snakecase\n# =\u003e \"foo_bar_baz\"\n```\n\nLoad `Strings::Case::Extensions` refinement to extend the `String` class\nwith all case conversion methods:\n\n```ruby\nrequire \"strings/case/extensions\"\n\nusing Strings::Case::Extensions\n\n\"foo bar baz\".camelcase\n# =\u003e \"fooBarBaz\"\n\n\"foo bar baz\".snakecase\n# =\u003e \"foo_bar_baz\"\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies.\nThen, run `rake spec` to run the tests. You can also run `bin/console`\nfor an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`.\nTo release a new version, update the version number in `version.rb`, and\nthen run `bundle exec rake release`, which will create a git tag for\nthe version, push git commits and tags, and push the `.gem` file to\n[rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at\nhttps://github.com/piotrmurach/strings-case. This project is intended to be\na safe, welcoming space for collaboration, and contributors are expected\nto adhere to the [Contributor Covenant](http://contributor-covenant.org)\ncode of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the\n[MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Strings::Case project’s codebases, issue trackers,\nchat rooms and mailing lists is expected to follow the\n[code of conduct](https://github.com/piotrmurach/strings-case/blob/master/CODE_OF_CONDUCT.md).\n\n## Copyright\n\nCopyright (c) 2019 Piotr Murach. See LICENSE for further details.\n","funding_links":["https://github.com/sponsors/piotrmurach"],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiotrmurach%2Fstrings-case","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpiotrmurach%2Fstrings-case","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiotrmurach%2Fstrings-case/lists"}