camelcase 0.1.0

Convert a dash/dot/underscore/space-separated string to camelCase (foo-bar -> fooBar). A faithful port of the camelcase npm package.
Documentation
  • Coverage
  • 100%
    9 out of 9 items documented3 out of 9 items with examples
  • Size
  • Source code size: 35.57 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 418.62 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • trananhtung/camelcase
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • trananhtung

camelcase

All Contributors

crates.io docs.rs CI license

Convert a string to camelCase.

foo-barfooBar, foo_bar_bazfooBarBaz, XML-httpxmlHttp. 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, and capitalize_after_number options
  • Differential-tested against the reference camelcase implementation

Install

[dependencies]
camelcase = "0.1"

Usage

use camelcase::{camel_case, camel_case_with, camel_case_slice, Options};

assert_eq!(camel_case("foo-bar"), "fooBar");
assert_eq!(camel_case("foo_bar_baz"), "fooBarBaz");
assert_eq!(camel_case("XML-http"), "xmlHttp");
assert_eq!(camel_case("p2p network"), "p2pNetwork");
assert_eq!(camel_case("foo123bar"), "foo123Bar");
assert_eq!(camel_case("__foo__bar__"), "__fooBar"); // leading _/$ preserved

// PascalCase:
assert_eq!(camel_case_with("foo-bar", Options::new().pascal_case(true)), "FooBar");

// Preserve consecutive uppercase runs:
assert_eq!(
    camel_case_with("XML-http", Options::new().preserve_consecutive_uppercase(true)),
    "XMLHttp"
);

// From a list of fragments:
assert_eq!(camel_case_slice(&["foo", "bar"], Options::default()), "fooBar");

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.