ex_yarn v0.3.1 ExYarn View Source

The library's main module

This module should be used as the public entrypoint of the library. It exposes a single function, parse/2, which is used to parse a lockfile's contents.

Note on performance: This library was built in part as a learning exercise and therefore does not necessarily apply the best possible practices and tools when it comes to code quality and performance. If performance is important to you, I recommend using Dorgan's library (hex.pm, Github), which uses NimbleParsec for better performance.

Example

Given the following yarn.lock file:

foo:
  "bar" true
  foo 10
  foobar: barfoo

The module should be used in the following manner:

iex> {:ok, input} = File.read("yarn.lock")
iex> ExYarn.parse(input, "yarn.lock")
{:ok, :success, %{"foo" => %{"bar" => true, "foo" => 10, "foobar" => "barfoo"}}}

Link to this section Summary

Types

The possible return values of parse/2

Functions

Receives the lockfile's contents, and optionnally the lockfile's name as inputs and returns the parse result

Link to this section Types

Specs

parseResult() ::
  {:ok, :merge | :success, map()}
  | {:error, ExYarn.ParseError.t()}
  | {:error, YamlElixir.FileNotFoundError}
  | {:error, YamlElixir.ParsingError}
  | {:error, :conflict, FunctionClauseError}

The possible return values of parse/2

Types details:

  • {:ok, :merge, map()}: The lockfile contained a merge conflict but was still successfully parsed
  • {:ok, :success, map()}: The locfile was successfully parsed
  • {:error, _}: There was an error while parsing the lockfile. The second element indicates the type of error that occured
  • {:error, :conflict, FunctionClauseError}: The lockfile contained a merge conflict which could not be parsed successfully.

Link to this section Functions

Link to this function

parse(str, file_loc \\ "lockfile")

View Source

Specs

parse(String.t(), String.t()) :: parseResult()

Receives the lockfile's contents, and optionnally the lockfile's name as inputs and returns the parse result

The lockfile's name is used to determine whether to parse the lockfile as an official yarn lockfile (i.e. with yarn's custom format) or as a regular YAML file. The function defaults to parsing the file as a yarn lockfile.