Skip to content

rossmacarthur/anycase

Repository files navigation

anycase

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.

Go

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"

View full documentation.

Rust

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"

View full documentation.

Python

Install using

pip install py-anycase

Now convert a string using the relevant function.

import anycase

anycase.to_snake("XMLHttpRequest") # returns "xml_http_request"

View full documentation.

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 and LICENSE-MIT for details.

About

💼 A case conversion library for Go, Rust, and Python with Unicode support

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks