
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
A utility library for changing between camel case, snake case, kebab case and more
An JavaScript library for changing between camelCase, snake_case, kebab-case, and more.
In a browser:
<script src="encase.js"></script>
Via bower:
bower install encase.js
This method will provides a global Encase object. That means that once you include it, you can use it like this:
var str = 'camelCase';
var convertedStr = Encase.toLowerSnake(str);
// = 'camel_case'
Encase supports switching to 6 cases:
toLowerCamel
(e.g. someVariableName
)toUpperCamel
(e.g. SomeVariableName
)toLowerSnake
(e.g. some_variable_name
)toUpperSnake
(e.g. SOME_VARIABLE_NAME
)toLowerKebab
(e.g. some-variable-name
)toUpperKebab
(e.g. SOME-VARIABLE-NAME
)Encase automatically detects the "from" case, so you only have to tell it what you want to switch to. It also provides
a general separate
function for splitting up strings:
var str = 'camelCase';
var words = Encase.separate(str);
// = ['camel', 'Case']
In addition to separate
, Encase provides a convert
function for making arbitrary conversions to any case:
The arguments are:
headTransform
: how the the first word should be transformedtailTransform
: how the rest of the words should be transformedsep
: how the words should be joined back togetherstr
: the string to operate onHere's an example for converting any casing to "colon case" (which is used in products like Redis for key naming):
var str = 'UpperCamel';
function toLowerCase(str) { return str.toLowerCase(); }
var convertedStr = Encase.convert(toLowerCase, toLowerCase, ':', str);
// = 'upper:camel'
And, if you want to get fancy:
Encase.toLowerColon = Encase.convert.bind(null,
Function.prototype.bind.call(String.prototype.toLowerCase),
Function.prototype.bind.call(String.prototype.toLowerCase),
':'
);
var str = 'UpperCamel';
var convertStr = Encase.toLowerColon(str);
// = 'upper:camel'
Cameron McKay |
This library is available under the MIT license.
FAQs
A utility library for changing between camel case, snake case, kebab case and more
We found that encase demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.