camelcase and camelcase-keys deep conversion: working versions (tested 2026-10-16)
Convert snake_case object keys deeply with camelcase-keys, including nested arrays, and transform strings with camelcase using the pascalCase option, asserting nested results offline.
passed4 passed · 0 failed2026-10-16 15:21 UTC- Status
- passed
- Last passed
- 2026-10-16 15:21 UTC
- Tests
- 4 / 4
- Language
- TypeScript
- Runtime
- node v22.23.3
pinned versions4
camelcase@10.0.0camelcase-keys@10.0.3@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false npm test
test environment
node v22.23.3 linux 6.17.0-1022-azure x64 runner: github-actions 38923127324
The code
Exactly the files that passed. Your agent can pull them with get_recipe("camelcase-keys-convert") (install), or see them on GitHub.
package.json
{
"name": "camelcase-keys-convert",
"private": true,
"type": "module",
"scripts": {
"test": "node --import tsx --test test/*.test.ts"
},
"dependencies": {
"camelcase": "10.0.0",
"camelcase-keys": "10.0.3"
},
"devDependencies": {
"@types/node": "26.6.5",
"tsx": "4.23.15"
}
}
src/convert.ts
import camelCase from "camelcase";
import camelcaseKeys from "camelcase-keys";
export function toCamel(input: string): string {
return camelCase(input);
}
export function toPascal(input: string): string {
return camelCase(input, { pascalCase: true });
}
export function convertKeysDeep<T>(input: T): T {
return camelcaseKeys(input as Record<string, unknown>, { deep: true }) as unknown as T;
}
test/convert.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { toCamel, toPascal, convertKeysDeep } from "../src/convert.ts";
test("camelcases a snake_case string", () => {
assert.equal(toCamel("hello_world"), "helloWorld");
});
test("camelcases a string with pascalCase option", () => {
assert.equal(toPascal("hello_world"), "HelloWorld");
});
test("deep converts snake_case keys including nested arrays", () => {
const input = {
user_id: 1,
first_name: "Ada",
home_address: {
zip_code: "12345",
geo_coords: { lat_long: [1, 2] },
},
order_items: [
{ item_id: "a", unit_price: 10 },
{ item_id: "b", unit_price: 20 },
],
};
const expected = {
userId: 1,
firstName: "Ada",
homeAddress: {
zipCode: "12345",
geoCoords: { latLong: [1, 2] },
},
orderItems: [
{ itemId: "a", unitPrice: 10 },
{ itemId: "b", unitPrice: 20 },
],
};
assert.deepEqual(convertKeysDeep(input), expected);
});
test("deep converts a top level array of objects", () => {
const input = [{ item_id: "a" }, { item_id: "b" }];
assert.deepEqual(convertKeysDeep(input), [{ itemId: "a" }, { itemId: "b" }]);
});
Connect to ProvenPin
Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.
terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp
~/.cursor/mcp.json
{ "mcpServers": { "provenpin": { "url": "https://mcp.provenpin.com/mcp" } } }.vscode/mcp.json
{ "servers": { "provenpin": { "type": "http", "url": "https://mcp.provenpin.com/mcp" } } }~/.codeium/windsurf/mcp_config.json
{ "mcpServers": { "provenpin": { "serverUrl": "https://mcp.provenpin.com/mcp" } } }MCP settings
{ "mcpServers": { "provenpin": { "type": "streamableHttp", "url": "https://mcp.provenpin.com/mcp" } } }Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.