Skip to main content

Crate camelcase

Crate camelcase 

Source
Expand description

§camelcase — convert a string to camelCase

Convert a dash/dot/underscore/space-separated string (or snake_case, kebab-case, PascalCase, …) to camelCase: foo-barfooBar, foo_bar_bazfooBarBaz. A faithful Rust port of the widely-used camelcase npm package.

use camelcase::camel_case;

assert_eq!(camel_case("foo-bar"), "fooBar");
assert_eq!(camel_case("foo_bar_baz"), "fooBarBaz");
assert_eq!(camel_case("XML-http"), "xmlHttp");

Use camel_case_with for PascalCase or to preserve consecutive uppercase runs:

use camelcase::{camel_case_with, Options};

assert_eq!(camel_case_with("foo-bar", Options::new().pascal_case(true)), "FooBar");
assert_eq!(
    camel_case_with("XML-http", Options::new().preserve_consecutive_uppercase(true)),
    "XMLHttp"
);

Structs§

Options
Options for camel_case_with.

Functions§

camel_case
Convert input to camelCase with the default options.
camel_case_slice
Convert a list of fragments to camelCase (each is trimmed, empties dropped, joined by -).
camel_case_with
Convert input to camelCase with the given Options.