-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2577e80
commit 85ffaaf
Showing
3 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# cases | ||
|
||
💼 A case conversion library | ||
|
||
![cases](https://github.com/rossmacarthur/cases/assets/17109887/ab3a4c71-6090-49f3-a67f-b1ab395999c6) | ||
|
||
This repository provides a | ||
|
||
- [**Go module**](./go) | ||
|
||
Install using | ||
|
||
```sh | ||
go get -u github.com/rossmacarthur/cases | ||
``` | ||
|
||
Now convert a string using the relevant function. | ||
|
||
```go | ||
import "github.com/rossmacarthur/cases/go" | ||
|
||
cases.ToSnake("XMLHttpRequest") // returns "xml_http_request" | ||
``` | ||
|
||
- [**Python package**](./python) | ||
|
||
Install using | ||
|
||
```sh | ||
pip install pycases | ||
``` | ||
|
||
Now convert a string using the relevant function. | ||
|
||
```python | ||
import cases | ||
|
||
cases.to_snake("XMLHttpRequest") # returns "xml_http_request" | ||
``` | ||
|
||
Each language implementation is identical and use the same underlying | ||
implementation which does the following: | ||
|
||
- Divide the input string into words | ||
- Convert each word as required | ||
- Join the words back together optionally with a separator | ||
|
||
Word boundaries are defined as follows: | ||
|
||
- A set of consecutive Unicode non-letter and non-number characters. | ||
|
||
For example: 'foo _bar' is two words (foo and bar) | ||
|
||
- A transition from a lowercase letter to an uppercase letter. | ||
|
||
For example: fooBar is two words (foo and Bar) | ||
|
||
- A transition from multiple uppercase letters to a single uppercase letter | ||
followed by lowercase letters. | ||
|
||
For example: 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters