npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

encase

v2.0.1

Published

A utility library for changing between camel case, snake case, kebab case and more

Downloads

66

Readme

encase.js Build Status

An JavaScript library for changing between camelCase, snake_case, kebab-case, and more.

Installation

In a browser:

<script src="encase.js"></script>

Via bower:

bower install encase.js

Notes

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 transformed
  • tailTransform: how the rest of the words should be transformed
  • sep: how the words should be joined back together
  • str: the string to operate on

Here'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'

Author

| twitter/cdmckay | |---| | Cameron McKay |

License

This library is available under the MIT license.