Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bettyblocks/case_style_ex
https://github.com/bettyblocks/case_style_ex
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bettyblocks/case_style_ex
- Owner: bettyblocks
- License: mit
- Created: 2020-09-13T18:20:32.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-09-27T15:40:53.000Z (over 1 year ago)
- Last Synced: 2024-10-18T05:07:57.917Z (3 months ago)
- Language: Elixir
- Size: 77.1 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CaseStyle
Convert from and to different CaseStyles.
This library is different than the others, because you need to explicitly say from and to which case you want to convert.
This is nice because you can keep some context and this makes it possible to convert between cases without losing data (check the tests for the edge cases).## Usage
### Manual method
```elixir
input = "testing_testing"
# we convert from SnakeCase
{:ok, casing} = CaseStyle.from_string(input, CaseStyle.SnakeCase)
# casing is a struct with a list of tokens
converted = CaseStyle.to_string(casing, CaseStyle.CamelCase)
# converted is "testingTesting"
```In the above example the modules can be dynamically passed. If you know what you want upfront you can use the convenience functions:
### Convenient method
```elixir
{:ok, "testingTesting"} = CaseStyle.snake_to_camel("testing_testing")
```## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `case_style` to your list of dependencies in `mix.exs`:```elixir
def deps do
[
{:case_style, "~> 0.2.1"}
]
end
```Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/case_style](https://hexdocs.pm/case_style).