pprint

Types

Since Erlang handles BitArrays differently than JavaScript does, the BitArraysAsString config option enables compatibility between the two targets.

These options only affect the JS target, which does not convert bit arrays to strings by default like Erlang does.

pub type BitArrayMode {
  BitArraysAsString
  KeepBitArrays
}

Constructors

  • BitArraysAsString

    Bit arrays will be converted to strings when pretty printed.

  • KeepBitArrays

    Bit arrays will be kept the same.

Configuration for the pretty printer.

pub type Config {
  Config(
    style_mode: StyleMode,
    bit_array_mode: BitArrayMode,
    label_mode: LabelMode,
  )
}

Constructors

  • Config(
      style_mode: StyleMode,
      bit_array_mode: BitArrayMode,
      label_mode: LabelMode,
    )

This option only affects the JavaScript target since Erlang has a different runtime representation of custom types that omits labels.

pub type LabelMode {
  Labels
  NoLabels
}

Constructors

  • Labels

    Show field labels in custom types.

    Foo(42, bar: "bar", baz: "baz")
    
  • NoLabels

    Leave out field labels.

    Foo(42, "bar", "baz")
    

Styling can be configured with StyleMode.

pub type StyleMode {
  Styled
  Unstyled
}

Constructors

  • Styled

    Data structures are styled with ANSI style codes.

    ⚠️ WARNING: Styling is subject to change without a major release! This means that this option should only be used for debugging purposes and should not be used in tests.

  • Unstyled

    Everything remains unstyled.

Functions

pub fn debug(value: a) -> a

Pretty print a value with the config below to stderr for debugging purposes. The value is returned back from the function so it can be used in pipelines.

Config(Styled, KeepBitArrays, Labels)

Examples

pprint.debug([1, 2, 3])
|> list.each(pprint.debug)

// Prints:
// [1, 2, 3]
// 1
// 2
// 3
pub fn format(value: a) -> String

Pretty print a value as a string with the following config:

Config(Unstyled, BitArraysAsString, NoLabels)

This function behaves identically on both targets so it can be relied upon for snapshot testing.

pub fn styled(value: a) -> String

Pretty print a value as a string with the following config:

Config(Styled, BitArraysAsString, NoLabels)

This function behaves identically on both targets.

⚠️ WARNING: Styling is subject to change without a major release! This means that this function should only be used for debugging purposes and should not be used in tests.

pub fn with_config(value: a, config: Config) -> String

Pretty print a value as a string with a custom config.

Examples

[1, 2, 3, 4]
|> pprint.with_config(Config(Styled, KeepBitArrays, Labels))
Search Document