transform-string-case
Transform strings between snake, camel, and upper camel case.
Use Case
transform-string-case
is a tiny, versatile library that can convert your strings between several different cases. My original use case was this: I was building a JavaScript project that needed to interact with both the [Firebase][firebase] and the [Twilio][twilio] APIs. The issue is that my lettercase was different everywhere. Since I was using JavaScript, my variables were all camel cased (thisIsACamelCasedVariable
). Firebase, however, sent all their JSON keys in snake case (this_is_a_snake_cased_variable
), while Twilio sent all of their JSON keys in upper camel case (ThisIsAnUpperCamelCasedVariable
).
To make matters worse, my ESlint config enforced camel casing and I didn't want to change it! Instead, I wrote a couple of tools to solve the issue: convert-object-keys
and transform-string-case
.
Usage
To use transform-string-case
, you need to pass it a string, what case the string is starting as, and what case the string is being transformed to:
// 'camel_case_string' // 'SnakeCaseString' // 'upper_camel_case_string'
Exports
transform-string-case
has a default export, as well as a couple of named helper exports (capitalizeFirstCharacter
and lowercaseFirstCharacter
). these helpers are used internally by the transformStringCase
, but they are exposed for convenience.
// or // 'Hello world!' // 'hello World!' // '😁ello World!'
Contributing
If you want to contribute, make sure to check out our contributing guide!
Contributors
Trezy 💻 📖 🤔 🚇 🚧 🔧 ⚠️ |