Skip to content

Commit 286f94c

Browse files
committed
Add a readme
1 parent 31c6340 commit 286f94c

File tree

1 file changed

+69
-2
lines changed

1 file changed

+69
-2
lines changed

README.md

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,78 @@
11
# sx
22

3-
[![Go Reference](https://pkg.go.dev/badge/github.com/gomantics/sx.svg)](https://pkg.go.dev/github.com/gomantics/sx)
3+
[![Go Reference](https://pkg.go.dev/badge/github.com/gomantics/sx.svg)](https://pkg.go.dev/github.com/gomantics/sx) [![CI](https://github.com/gomantics/sx/actions/workflows/ci.yml/badge.svg)](https://github.com/gomantics/sx/actions/workflows/ci.yml)
44

5-
TODO Description
5+
A simple Go library for string case conversion. Converts between camelCase, PascalCase, kebab-case, snake_case, and more.
66

77
## Installation
88

99
```bash
1010
go get github.com/gomantics/sx
1111
```
12+
13+
## Usage
14+
15+
```go
16+
package main
17+
18+
import (
19+
"fmt"
20+
21+
"github.com/gomantics/sx"
22+
)
23+
24+
func main() {
25+
// Convert to different cases
26+
fmt.Println(sx.CamelCase("hello-world")) // helloWorld
27+
fmt.Println(sx.PascalCase("hello_world")) // HelloWorld
28+
fmt.Println(sx.KebabCase("HelloWorld")) // hello-world
29+
fmt.Println(sx.SnakeCase("HelloWorld")) // hello_world
30+
fmt.Println(sx.TrainCase("hello-world")) // Hello-World
31+
fmt.Println(sx.FlatCase("hello-world")) // helloworld
32+
33+
// Works with mixed separators and cases
34+
fmt.Println(sx.CamelCase("mixed_caseWith-different.separators")) // mixedCaseWithDifferentSeparators
35+
36+
// Handle complex acronyms
37+
fmt.Println(sx.KebabCase("XMLHttpRequest")) // xml-http-request
38+
fmt.Println(sx.CamelCase("HTML5Parser")) // html5Parser
39+
}
40+
```
41+
42+
## Case Functions
43+
44+
- `CamelCase()` - converts to camelCase
45+
- `PascalCase()` - converts to PascalCase
46+
- `KebabCase()` - converts to kebab-case
47+
- `SnakeCase()` - converts to snake_case
48+
- `TrainCase()` - converts to Train-Case
49+
- `FlatCase()` - converts to flatcase (no separators)
50+
51+
## Utilities
52+
53+
- `SplitByCase()` - splits strings into words by case changes and separators
54+
- `UpperFirst()` - capitalizes first character
55+
- `LowerFirst()` - lowercases first character
56+
57+
## Options
58+
59+
Some functions support options for customization:
60+
61+
```go
62+
// Normalize case for strict PascalCase/camelCase
63+
sx.PascalCase("XMLHttpRequest", sx.WithNormalize(true)) // XmlHttpRequest
64+
65+
// Custom separators for splitting
66+
sx.SplitByCase("hello.world", sx.WithSeparators('.')) // ["hello", "world"]
67+
68+
// Custom separator for kebab case
69+
sx.KebabCase("hello world", "|") // hello|world
70+
```
71+
72+
## Contributing
73+
74+
Contributors are always welcome! Feel free to raise a PR or create an issue first.
75+
76+
## License
77+
78+
MIT

0 commit comments

Comments
 (0)