Closed itslenny closed 7 years ago
This seems neat, especially for debugging. A small nit, shouldn't the protoype stuff be copied into a plain "prototype" key so that you can differentiate between something.blah
and something.prototype.blah
?
Also, I think the function stringification should probably do the same things that the string code does where it cuts off if it's too long (since functions have a tendency to get big). Or maybe it could search for the opening {
and make another disclosure there?
Great idea. I added the disclosure for javascript functions.
Regarding the prototype, for my purposes it needs to be flattened like this. The idea is that it is a representation of how you'd actually use the object. For example, if I call obj.fn()
and fn
is somewhere in the prototype chain it will be executed as if it were defined on obj
directly. I like that you an look at an object and see exactly what you have access to.
Maybe there could be another option to preserve the prototype chain vs flattening it? I'm thinking this would be a separate addition.
I was also thinking that this would be a great extension to the package. In my case, I do not have functions or prototype, but Date
objects. it would be great if those would be displayed as dates. Currently, the are displayed as {}
. :-(
@mitar, you're right—it's wrong that the Date object isn't rendered. Also the Number objects and Boolean objects aren't rendered. I think the answer is to make sure the implementation of renderjson follows the JSON.stringify()
API and spec. I would also add replacer stuff, which should be powerful enough to support what @itslenny wants to do. I've been avoiding merging this pull request because it doesn't feel right for the changes to be in the core code, even behind an option. If we can hoist them out as a separate add-on function then it would be much better, I think.
I added replacer
and property_list
config options, which act like the JSON.stringify()
parameters of the same names. I believe this should be powerful enough to implement the original request here without needing to modify the core code any further.
I added the ability to run in "Javascript Mode" which is for handling javascript objects. This mode causes two changes
I'm not sure if this is a feature that is valuable to you or not, but I figured I might as well submit it.