JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="https://code.jquery.com/qunit/qunit-1.23.0.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-1.23.0.css">
<div id="qunit"></div>
<div id="qunit-fixture"></div>
JavaScript
QUnit.test("Group properties by camelCase", function (assert) {
function groupProperies(obj) {
var nObj = {};
for (var key in obj) {
var splity = key.split(/(?=[A-Z])/)
if (!(splity[0] in nObj))
nObj[splity[0]] = {};
var tempObj = {};
for (var i = splity.length - 1; i > 0; i--) {
var sp = splity[i].toLowerCase();
if (i == splity.length - 1) {
tempObj[sp] = obj[key];
} else {
//var sp1 = splity[i + 1].toLowerCase();
jQuery.extend(tempObj[sp], tempObj);
}
}
jQuery.extend(nObj[splity[0]], tempObj);
}
return nObj;
}
var obj = {
"animationsJump": "123",
"animationsRun": "456",
"animationsHide": "789",
"personName": "Grant",
"personPetsDog": "Snowy",
"personPetsCat": "Snowball"
};
var expect = {
"animations": {
"jump": "123",
"run": "456",
"hide": "789"
},
"person": {
"name": "Luke",
"pets": {
"dog": "Snowy",
"cat": "Snowball"
}
}
}
assert.equal(groupProperies(obj), expect, "Expect properties to be grouped by camelCase");
});