Expand description
§humanize-string — make a machine string human-readable
Convert a camelCase, snake_case, or dash-case string into a readable phrase:
fooBar → Foo bar, background-color → Background color,
XMLHttpRequest → Xml 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
stringhuman-readable: split camelCase, replace_/-with spaces, collapse whitespace, and capitalize the first letter. - humanize_
string_ with - Make
stringhuman-readable, optionally preserving the original casing.