Snake case mapping

Benchmark created on


Setup

function camelCaseObject(obj) {
	const result = {};
	for (const key of Object.keys(obj)) {
		const value = obj[key];
		if (value && typeof value === 'object') {
			result[_.camelCase(key)] = camelCaseObject(value);
		} else {
			result[_.camelCase(key)] = value;
		}
	}
	return result;
}

const staff = [
  {
    "uuid": "694045019-25dfa7ea-6f5e-47e4-ae5c-9162236e1f2c",
    "email": "nicholasroach@example.net",
    "preferred_name": "Liz",
    "role": "administrator",
    "permissions": [
      "user_can_manage_staff"
    ],
    "has_staff_pin": true,
    "staff_id": "1234",
    "staff_number": "EMP2022",
    "nested_example": {
    	"foo_bar": 42
    }
  }
];

// Make 10 copies of the staff member.
for (let i = 0; i < 10; ++i) {
	staff.push(staff[0]);
}

Test runner

Ready to run.

Testing in
TestOps/sec
Identity
staff;
ready
Lodash
camelCaseObject(staff);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.