Skip to content

Instantly share code, notes, and snippets.

@ianpgall
Last active December 20, 2015 21:59
Show Gist options
  • Save ianpgall/6201703 to your computer and use it in GitHub Desktop.
Save ianpgall/6201703 to your computer and use it in GitHub Desktop.
JavaScript functions that converts strings to camel case, or to a hyphenated version
var Format = (function () {
"use strict";
var toCamelCase, toHyphenated;
toCamelCase = (function () {
var re, ret;
re = /-([a-z])/g;
ret = function (str) {
str = str.replace(re, function (match, lower) {
return lower.toUpperCase();
});
return str;
};
return ret;
}());
toHyphenated = (function () {
var re, ret;
re = /([a-z])([A-Z])/g;
ret = function (str) {
return str.replace(re, "$1-$2").toLowerCase();
};
return ret;
}());
return {
toCamelCase: toCamelCase,
toHyphenated: toHyphenated
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment