Comments (10)
Are you able to give an example? Thanks.
from humps.
Example:
const myArr = [{
validTill: 'date obj',
eventId: 'uniq id'
}]
const decamelizeKeys = humps.decamelizeKeys(myArr); // Throws error obj.hasOwnProperty is not a function
// OR
const decamelizeKeys = _.map(myArr, (item) => humps.decamelizeKeys(item)); // Throws error obj.hasOwnProperty is not a function
Environment: Node 6
It works fine on browser.
from humps.
Sorry I am unable to reproduce this. I have tested the following in Node 6.9.3 and it works as expected:
> var humps = require('./')
undefined
> const myArr = [{
... validTill: 'date obj',
... eventId: 'uniq id'
... }]
undefined
>
> const decamelizeKeys = humps.decamelizeKeys(myArr);
undefined
> decamelizeKeys
[ { valid_till: 'date obj', event_id: 'uniq id' } ]
from humps.
Hi,
I came across this issue too trying to run decamelizeKeys on the output object produced by the Joi validator. It turns out that the .hasOwnProperty method gets stripped by Joi.
Since we can't rely on supplied objects having the hasOwnProperty method (or a modified version) I have created a pull request to call hasOwnProperty directly from the Object prototype.
Lloyd
from humps.
Any chance of merging the fix and making a new release?
from humps.
I'm running into the same issue, but in the browser. The PR above seems to fix it.
from humps.
Any update on this? I'm running into this issue on the browser as well.
from humps.
obj.hasOwnProperty
is a widely recognised method to check object properties, so I would like to understand why this is happening before merging. If anyone can provide a failing demo, I can look into it. Thanks.
from humps.
Yes, hasOwnProperty is the de facto way to check objects for properties, but unfortunately it's mutable so out in the wild it can't be relied on.
Here are a couple of examples of how you can't rely on the hasOwnProperty method of an object you haven't created.
const foo = Object.create(null);
foo; // {}
foo.bar = 'baz';
foo.hasOwnProperty('bar'); // TypeError: foo.hasOwnProperty is not a function
Object.prototype.hasOwnProperty.call(foo, 'bar'); // true
const foo2 = { bar: 'baz' };
foo2.hasOwnProperty = () => false;
foo2.hasOwnProperty('bar'); // false
Object.prototype.hasOwnProperty.call(foo2, 'bar'); // true
The comments above demonstrate this is more than just a hypothetical problem and I think that a library with no control over the objects that it receives should follow the principle:
Be conservative in what you do, be liberal in what you accept from others
from humps.
Perfect, thanks for the explanation! #36 has been merged and released in v2.0.1
from humps.
Related Issues (20)
- Option to not camelize all-caps CONSTANTS HOT 1
- 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
- Exclude specific path(s) from being converted 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.