Crates.io | ncase |
lib.rs | ncase |
version | 0.2.2 |
source | src |
created_at | 2022-07-22 16:17:57.049861 |
updated_at | 2024-03-22 22:47:39.884718 |
description | Enforce a case style |
homepage | |
repository | https://codeberg.org/xmyst/ncase.git |
max_upload_size | |
id | 630901 |
size | 45,712 |
So that I could
% for f in *.pdf; do
mv "$f" "$(ncase -s `basename "$f" .pdf`).pdf"
done
% cargo install ncase
Enforce a case style on a string and write that to the standard output
% ncase --pascal this is a test string
ThisIsATestString
% ncase --lower ThisIsATestString
this is a test string
If built with the rand
feature, enforce rANdOm cASe
by default
% ncase this is a test string
ThiS IS A tesT stRINg
Otherwise, enforce tOGGLE cASE
by default
% ncase this is a test string
tHIS iS a tEST sTRING
Add the dependency to your Cargo.toml
[dependencies]
ncase = "0.2"
Or from the command line
% cargo add ncase@0.2
Use the free functions for one-off case conversions
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
use ncase::Words;
let s = "Lorem ipsum dolor sit amet";
let w = Words::from(s);
assert_eq!(w.kebab(), "lorem-ipsum-dolor-sit-amet");
assert_eq!(w.title(), "Lorem Ipsum Dolor Sit Amet");
Or if you want to use the separator regex (requires the regex
feature)
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);
assert_eq!(w.lower(), "lorem ipsum dolor sit amet");
assert_eq!(w.upper(), "LOREM IPSUM DOLOR SIT AMET");