% cargo install ncase
Enforce the chosen case style on a string and write it to the standard output.
% ncase --pascal this is a test string
ThisIsATestString
% ncase --lower ThisIsATestString
this is a test string
By default, enforces the random case.
% ncase this is a test string
ThiS IS A tesT stRINg
Add the dependency to your Cargo.toml
.
toml
[dependencies]
ncase = "0.1"
Or from the command line.
% cargo add ncase@0.1
Use the functions for one-off case conversions.
rust
assert_eq!(ncase::camel("camel case"), "camelCase");
assert_eq!(ncase::snake("snake case"), "snake_case");
Use Words
if you need to convert one string into many case styles.
```rust use ncase::Words;
let s = "Lorem ipsum dolor sit amet"; let w = Words::from(s);
asserteq!(w.kebab(), "lorem-ipsum-dolor-sit-amet"); asserteq!(w.title(), "Lorem Ipsum Dolor Sit Amet"); ```
Or if you want to use the separator regex.
```rust use ncase::Words; use regex::Regex;
let s = "Lorem, ipsum (dolor sit) amet"; let sep = Regex::new(r"[\pP\s]+").unwrap(); let w = Words::with_separator(s, &sep);
asserteq!(w.lower(), "lorem ipsum dolor sit amet"); asserteq!(w.upper(), "LOREM IPSUM DOLOR SIT AMET"); ```