A case conversion library for Go, Rust, and Python.
Anycase provides a consistent way of converting between different case styles. And has a similar API across languages.
Install using
go get -u github.com/rossmacarthur/anycase/go
Now convert a string using the relevant function.
import "github.com/rossmacarthur/anycase/go"
anycase.ToSnake("XMLHttpRequest") // returns "xml_http_request"
Add the anycase
crate to your Cargo manifest.
cargo add anycase
Now convert a string using the relevant function.
anycase::to_snake("XMLHttpRequest"); // returns "xml_http_request"
Install using
pip install py-anycase
Now convert a string using the relevant function.
import anycase
anycase.to_snake("XMLHttpRequest") # returns "xml_http_request"
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 wordsfoo
andbar
. - A transition from a lowercase letter to an uppercase letter e.g.
fooBar
is two wordsfoo
andBar
. - The second last uppercase letter in a word with multiple uppercase letters
e.g.
FOOBar
is two wordsFOO
andBar
.
This project is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.