Package Exports
- camelcase-keys-safe
- camelcase-keys-safe/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (camelcase-keys-safe) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
camelcase-keys-safe
Safely convert object keys to camelCase recursively with circular reference protection, deep traversal, and robust error handling.
Simple usage:
import camelCaseSafe from 'camelcase-keys-safe';
var camelGotHumps = camelCaseSafe({'test-1':123, 'test-2':{'test-3:':{'test-four':132}}});
//{ test1: 123, test2: { 'test3:': { testFour: 132 } } }
console.log(camelGotHumps);Works with Arrays too:
var anotherCamelWithTheHump = camelCaseSafe({
'test-1': 123,
'test-Two': [{
'test-three': {
'test-FOUR': [{'test-five':[{testSix:{'test-seven':8}}]}]
}
}]
});
//{"test1":123,"testTwo":[{"testThree":{"testFOUR":[{"testFive":[{"testSix":{"testSeven":8}}]}]}}]}
console.log(JSON.stringify(anotherCamelWithTheHump));Handles Circular References Safely:
// Create an object with circular reference
const obj = { 'user-name': 'John', 'user-data': {} };
obj['user-data'].parent = obj; // Circular reference!
// This would cause infinite loops with regular recursive functions
// But camelCaseSafe handles it gracefully
const safeResult = camelCaseSafe(obj);
console.log(safeResult);
// { userName: 'John', userData: { parent: [Circular] } }Features
- ✅ Circular Reference Protection: Uses WeakMap caching to prevent infinite loops
- ✅ Deep Traversal: Recursively processes nested objects and arrays
- ✅ Type Safety: Preserves Date objects and other special types
- ✅ Array Support: Handles arrays containing objects
- ✅ Performance Optimized: Efficient caching mechanism
- ✅ Zero Dependencies: Only depends on
map-objfor core functionality
Installation
npm install camelcase-keys-safeMore information on internal modules
map-obj // TODO
Contributing
Simply make a pr with details on your bug and tests.