yay

unit_tests Hex.pm Docs

[Y]et [A]nother [Y]aml is a Gleam YAML parser supporting both Erlang and JavaScript targets.

Fork notice: This is a fork of glaml by @katekyy. The original glaml library provides the core YAML parsing functionality via yamerl. This fork started by adding typed error handling, value extraction utilities, and JavaScript target support and continues to evolve.

Installation

gleam add yay

JavaScript target: If targeting JavaScript (Deno), you also need to install js-yaml:

deno add npm:js-yaml

Usage

import yay

pub fn main() {
  // Parse a YAML string
  let assert Ok([doc]) = yay.parse_string("
name: yay
version: 1.0.0
features:
  - typed errors
  - value extraction
  - dual target support
")

  let root = yay.document_root(doc)

  // Extract values with type safety
  let assert Ok("yay") = yay.extract_string(root, "name")
  let assert Ok(features) = yay.extract_string_list(root, "features")
}

Features

Error Handling

All extraction functions return Result(T, ExtractionError) where ExtractionError is:

pub type ExtractionError {
  KeyMissing(key: String, failed_at_segment: Int)
  KeyValueEmpty(key: String)
  KeyTypeMismatch(key: String, expected: String, found: String)
  DuplicateKeysDetected(key: String, keys: List(String))
}

Acknowledgments

Thanks to @katekyy for creating glaml, which this library is forked from.

License

MIT

Search Document