-
Notifications
You must be signed in to change notification settings - Fork 26
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
Option to enable more compact layout for small objects and arrays #56
Comments
The default The idea of a "formatting function" sounds good, but it could be really tricky to create such a function. Do you have an example function? |
Hi there, sorry for taking a few days to get back to you. Thanks for your positive response! I've actually just had a quick look at the code now for the first time to see what it's doing; and it looks like adding the functionality that I have in mind will be reasonable. I'll need to play around with it and see what I come up with, I have some ideas. I've done a fair amount of this sort of thing before. It could be days or weeks til I've got some time to work on it; but I'm definitely interested. If you or anyone else decides to work on any such functionality, please keep this issue updated so that nobody wastes their time :) Chat soon PS: If having this issue open with no defined ETA on closing it bothers you, then feel free to close it, I won't be offended. |
I've been looking for a solution for this too... I think a very simple rule could be to evaluate every { } block and see if it could be rendered on one line without going over the line-break threshold. While this is simplistic, since the common use case for this is small fields (and probably arrays of small objects) it would likely work well enough. Smarter rules might even be worse; I often have an array of many small items with one or two objects with longer/extra properties; when I format them manually I just use multiple lines for those. Readability is enhanced by seeing more on the screen, more than be perfect consistency. |
I've noticed lately that node.js and mongosh are pretty good at not wasting lines when objects have few properties in them.
Would be really nice if pretty-print-json could present the stylers arrays on a single line.
So using 1 line instead of the 5 lines it currently uses to show the stylers arrays:
Instead of the current behavior.
It's very easy to see the number of elements are in an array, or keys in an object. Then doing a sanity check on the line length to determine if it should stay on a single line or spread over multiple lines. So it's very easy to produce a space efficient presentation.
One way to easily achieve this is if we could pass our own formatting function, so that the lib calls our function with the object(s) and we we format it in some way that the lib understands (spaces on left and newlines, etc) and return it.
Note I've used:
{ foo:1, bar:2, baz:3 }
The great thing, is with a callback etc we can style stuff how we like.
The text was updated successfully, but these errors were encountered: