Coder Social home page Coder Social logo

bcpeinhardt / glam Goto Github PK

View Code? Open in Web Editor NEW

This project forked from giacomocavalieri/glam

0.0 1.0 0.0 1.82 MB

A package to help you easily pretty print structured data ✨

Home Page: https://hexdocs.pm/glam/

License: Apache License 2.0

Gleam 100.00%

glam's Introduction

Glam

Package Version Hex Docs

A package to help you easily pretty print structured data ✨

⚙️ This package works with both the Erlang and Javascript target

Installation

To add this package to your Gleam project:

gleam add glam

Pretty printing

When working with structured data (like JSON, XML, lists, ASTs, ...) it can be 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 quite difficult (I sure have spent my fair share of time writing those) and error-prone: there are a lot of moving pieces to juggle and it's easy for bugs to 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 of actually finding the best layout to format the data, gracefully handling line limits and indentation.

Getting started

If you want to get started with Glam, a great starting point is the learning materials page! There you'll find a lot of step-by-step tutorials that will guide you through some 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'll have implemented pretty printers for lists, JSON and error messages:

pretty_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 folder in the GitHub repo, there you'll also find a JSON pretty printer.

Contributing

If you think there's any way to improve this package, or if you spot a bug don't be afraid to open PRs, issues or requests of any kind! Any contribution is welcome 💜

glam's People

Contributors

giacomocavalieri avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.