De-Camelize

by Patrick Hund

JavaScript

var testCases = [
  "foo",
  "fooBar",
  "FooBar",
  "fooXBar",
  "fooXYBar",
  "fooXYZBar"
];

testCases.forEach(function (testCase) {
  console.log(testCase + " => " + decamelize(testCase));
});

function decamelize(input) {
  return input.replace(/(.)([A-Z])/g, "$1-$2").toLowerCase();
}