Comments (2)
I had a similar problem, but in my case the key was nested much deeper, so I updated the source code to contain the path of the key being provided to the callback function
Here's the git patch for it
diff --git a/node_modules/humps/humps.js b/node_modules/humps/humps.js
index 444b4d9..670b8f0 100644
--- a/node_modules/humps/humps.js
+++ b/node_modules/humps/humps.js
@@ -10,7 +10,7 @@
;(function(global) {
- var _processKeys = function(convert, obj, options) {
+ var _processKeys = function(convert, obj, options, path = []) {
if(!_isObject(obj) || _isDate(obj) || _isRegExp(obj) || _isBoolean(obj) || _isFunction(obj)) {
return obj;
}
@@ -22,14 +22,14 @@
if(_isArray(obj)) {
output = [];
for(l=obj.length; i<l; i++) {
- output.push(_processKeys(convert, obj[i], options));
+ output.push(_processKeys(convert, obj[i], options, path));
}
}
else {
output = {};
for(var key in obj) {
if(Object.prototype.hasOwnProperty.call(obj, key)) {
- output[convert(key, options)] = _processKeys(convert, obj[key], options);
+ output[convert(key, options, path)] = _processKeys(convert, obj[key], options, path.concat(key));
}
}
}
@@ -106,8 +106,8 @@
return convert;
}
- return function(string, options) {
- return callback(string, convert, options);
+ return function(string, options, path) {
+ return callback(string, convert, options, path);
}
};
Then it can be used as follow:
humps.camelizeKeys(obj, (key, convert, _, path) => {
if (path.includes("media")) {
return key;
}
return convert(key);
});
Hope this helps
from humps.
I'm a bit late but maybe something like...
var raw = yourObject
var result = Object.assign(camelizeKeys(raw), { important_stuff: raw.important_stuff })
from humps.
Related Issues (20)
- Option to not camelize all-caps CONSTANTS HOT 1
- obj.hasOwnProperty is not a function HOT 10
- string.replace is not a function HOT 2
- decamelizeKeys fails in chrome 51 HOT 3
- Recurse nested objects HOT 2
- Conversion of screaming snake case to camel case HOT 2
- Decamelizing uppercase keys HOT 2
- unexpected behavior with ES6 imports & classes
- `_isNumerical` implementation doesn't make sense HOT 4
- humps corrupted FormData structure HOT 9
- 👀 Looking for a maintainer / transfer ownership HOT 10
- Continuous capitalization does not require segmentation
- invalid moment object when converting string to moment inside camelizeKeys HOT 1
- decamelize and camelize is not reverse operations
- Unhandled promise rejection RangeError: Maximum call stack size exceeded
- humps corrupted Blob structure
- Cannot split on numbers properly with the readme example HOT 2
- [🐛BUG] Unexpected underscore when using decamelize function HOT 1
- Camelize keys & uppercase HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from humps.