Skip to main content

Crate humanize_string

Crate humanize_string 

Source
Expand description

§humanize-string — make a machine string human-readable

Convert a camelCase, snake_case, or dash-case string into a readable phrase: fooBarFoo bar, background-colorBackground color, XMLHttpRequestXml http request. A faithful Rust port of the humanize-string npm package.

use humanize_string::humanize_string;

assert_eq!(humanize_string("fooBar"), "Foo bar");
assert_eq!(humanize_string("background-color"), "Background color");
assert_eq!(humanize_string("HELLO_WORLD"), "Hello world");

Pass preserve_case = true to skip the camelCase splitting and keep the original casing (only whitespace is normalized and the first letter capitalized):

use humanize_string::humanize_string_with;
assert_eq!(humanize_string_with("fooBar", true), "FooBar");
assert_eq!(humanize_string_with("HELLO_WORLD", true), "HELLO WORLD");

Functions§

humanize_string
Make string human-readable: split camelCase, replace _/- with spaces, collapse whitespace, and capitalize the first letter.
humanize_string_with
Make string human-readable, optionally preserving the original casing.