https://github.com/rossmacarthur/anycase
💼 A case conversion library for Go and Python with Unicode support
https://github.com/rossmacarthur/anycase
camelcase go python snakecase
Last synced: 8 months ago
JSON representation
💼 A case conversion library for Go and Python with Unicode support
- Host: GitHub
- URL: https://github.com/rossmacarthur/anycase
- Owner: rossmacarthur
- Created: 2023-02-25T16:03:51.000Z (over 3 years ago)
- Default Branch: trunk
- Last Pushed: 2025-03-31T15:53:42.000Z (about 1 year ago)
- Last Synced: 2025-04-13T16:09:50.954Z (about 1 year ago)
- Topics: camelcase, go, python, snakecase
- Language: Rust
- Homepage:
- Size: 98.6 KB
- Stars: 23
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# anycase
A case conversion library for [Go](#go), [Rust](#rust), and [Python](#python).

Anycase provides a consistent way of converting between different case styles.
And has a similar API across languages.
## Go
Install using
```sh
go get -u github.com/rossmacarthur/anycase/go
```
Now convert a string using the relevant function.
```go
import "github.com/rossmacarthur/anycase/go"
anycase.ToSnake("XMLHttpRequest") // returns "xml_http_request"
```
[View full documentation](./go).
## Rust
Add the `anycase` crate to your Cargo manifest.
```sh
cargo add anycase
```
Now convert a string using the relevant function.
```rust
anycase::to_snake("XMLHttpRequest"); // returns "xml_http_request"
```
[View full documentation](./rust).
## Python
Install using
```sh
pip install py-anycase
```
Now convert a string using the relevant function.
```python
import anycase
anycase.to_snake("XMLHttpRequest") # returns "xml_http_request"
```
[View full documentation](./python).
## How does it work?
Each implementation divides the input string into words and applies a “word
function” to each word and calls a “delimiter function” for each word
boundary (the space between words).
Word boundaries are defined as follows:
- A set of consecutive non-letter/number/symbol e.g. `foo _bar` is two words
`foo` and `bar`.
- A transition from a lowercase letter to an uppercase letter e.g. `fooBar`
is two words `foo` and `Bar`.
- The second last uppercase letter in a word with multiple uppercase letters
e.g. `FOOBar` is two words `FOO` and `Bar`.
## License
This project is distributed under the terms of both the MIT license and the
Apache License (Version 2.0).
See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT) for details.