-
-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passthrough non-object parameters #15
Conversation
If this function is called with a non Object parameter, return it right away instead of letting WeakMap fail
Thinking about this more... Maybe the value should be passed to the cb function? This however does not match the We could even simplify |
It should not just silently pass through non-Object values. It should throw a TypeError. You also need to use a different object check as the one already there is focused on a different use-case. |
Hey @sindresorhus. Thanks for taking a look! 😄 I happen to disagree with your reasoning: With regard to throwing a TypeError, I can understand that logic. However with the recursive nature of this package, I think "recusing" "0" levels is a valid usage. If you want to keep the API the way you have it, that's your prerogative. I just think it's not very useful to With regard to using your |
I prefer strict typing. Imagine if this package was using TypeScript, it would be typed to accept an
I honestly don't remember why I chose to exclude RegExp, Date, Error. There are many more built-ins that could be added to that list. In hindsight, it would probably have been better to have made the check like this: const isObject = value => value !== null && (typeof type === 'object' || typeof type === 'function'); |
Except My main point is that the recursion logic is inconsistent. If the argument is an array, it recurses. If any of those arguments are not objects, it doesn't convert them or thow. Why not throw a TypeError when an array is passed in? Why not throw a TypeError when an array of non-objects is passed in? Recursing a depth of "0" is just as valid as any other depth. Throwing makes sense when there is no logical way to move forward. For instance, if the function is expecting an argument with a specific shape and is supposed to convert it to some other value. Maybe a function call like Maybe a better analogy is a function like You bring up a good point about functions. They do act a lot like objects. However changing that now would be a more significant breaking change as currently functions are not recursed. |
Would you consider passing through non-object parameters if |
If this function is called with a non Object parameter, return it right away instead of letting WeakMap fail