camelcase
Convert a string to camelCase.
foo-bar → fooBar, foo_bar_baz → fooBarBaz, XML-http → xmlHttp. Handles dash,
dot, underscore, and space separators, as well as existing camelCase/PascalCase and
acronyms. A faithful Rust port of the widely-used
camelcase npm package.
It is the inverse of decamelize.
PascalCase,preserve_consecutive_uppercase, andcapitalize_after_numberoptions- Differential-tested against the reference
camelcaseimplementation
Install
[]
= "0.1"
Usage
use ;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!; // leading _/$ preserved
// PascalCase:
assert_eq!;
// Preserve consecutive uppercase runs:
assert_eq!;
// From a list of fragments:
assert_eq!;
Options
| Option | Default | Effect |
|---|---|---|
pascal_case |
false |
Uppercase the first character (FooBar). |
preserve_consecutive_uppercase |
false |
Keep runs of uppercase letters (XMLHttp instead of xmlHttp). |
capitalize_after_number |
true |
Treat a digit run as a word boundary (foo123Bar). |
Contributors ✨
This project follows the all-contributors specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the emoji key for how each contribution is recognized, and open a PR or issue to get involved.
Thanks goes to these wonderful people:
License
Licensed under either of MIT or Apache-2.0 at your option.