Skip to main content

Crate decamelize

Crate decamelize 

Source
Expand description

§decamelize — convert camelCase to a separated lower-case string

Turn camelCase (or PascalCase) into a separated, lower-case string — fooBarfoo_bar, unicornsAndRainbowsunicorns_and_rainbows. A faithful Rust port of the widely-used decamelize npm package.

use decamelize::decamelize;

assert_eq!(decamelize("unicornsAndRainbows"), "unicorns_and_rainbows");
assert_eq!(decamelize("XMLHttpRequest"), "xml_http_request");
assert_eq!(decamelize("testGUILabel"), "test_gui_label");

Use decamelize_with for a custom separator or to preserve consecutive uppercase runs:

use decamelize::decamelize_with;

assert_eq!(decamelize_with("fooBar", "-", false), "foo-bar");
assert_eq!(decamelize_with("testGUILabel", "_", true), "test_GUI_label");

Zero dependencies and #![no_std].

Functions§

decamelize
Convert text from camelCase to a _-separated lower-case string.
decamelize_with
Convert text from camelCase using a custom separator.