Crate ncase

Source
Expand description

ncase [ɪn’keɪs] is a library to enforce case styles.

§Usage

Use the free functions for one-off case conversions. They automatically split the input string into words just as Words::from

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 a separator regex (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");

§Features

regex : Enables Words::with_separator in the library and -F <separator> in the binary. Adds the regex dependency.

rand : Enables rANdOm cASe support. Adds the rand dependency.

Structs§

Words
Sequence of words of some original string.

Functions§

camel
Free form of Words::camel.
kebab
Free form of Words::kebab.
lower
Free form of Words::lower.
pascal
Free form of Words::pascal.
random
Free form of Words::random.
screaming_kebab
Free form of Words::screaming_kebab.
screaming_snake
Free form of Words::screaming_snake.
snake
Free form of Words::snake.
title
Free form of Words::title.
toggle
Free form of Words::toggle.
upper
Free form of Words::upper.