Current section
Files
Jump to
Current section
Files
README.md
[](https://hex.pm/packages/glam)[](https://hexdocs.pm/glam/)✨ A package to help you easily pretty print structured data> ⚙️ This package works with both the Erlang and Javascript target## InstallationTo add this package to your Gleam project:```shgleam add glam```## Pretty printingWhen working with structured data (like JSON, XML, lists, ASTs, ...) it canbe useful to print it in a nice and tidy way.Of course, one could go the quick and dirty way and just `string.inspect`the data structure and call it a day.However, the result would hardly be readable for complex data structures.On the other hand, handwriting a pretty printing function can be quitedifficult (I sure have spent my fair share of time writing those) anderror-prone: there are a lot of moving pieces to juggle and it's easy for bugsto sneak in.A pretty printing package like Glam provides some basic building blocks to_describe_ the structure of your data and takes care of the heavy lifting ofactually finding the best layout to format the data, gracefully handling linelimits and indentation.## Getting startedIf you want to get started with Glam, a great starting point is the[learning materials page](https://hexdocs.pm/glam/learning_materials.html)!There you'll find a lot of step-by-step tutorials that will guide you throughsome awesome pretty printers and get you up and running with Glam.By the end of the tutorials you'll know most of the package's API and you'llhave implemented pretty printers for lists, JSON and error messages:```gleampretty_list(["Gleam", "is", "fun!"])|> doc.to_string(10) // Fit the list on lines of width 10// [// "Gleam",// "is",// "fun!",// ]```You can also have a look at the[`examples`](https://github.com/giacomocavalieri/glam/tree/main/test/glam/examples)folder in the GitHub repo, there you'll also find a JSON pretty printer.## ContributingIf you think there's any way to improve this package, or if you spot a bugdon't be afraid to open PRs, issues or requests of any kind!Any contribution is welcome 💜