yarn_parser v0.3.1 YarnParser View Source

A parser for Yarn lock files

Link to this section Summary

Functions

Parses a lock file

Encodes a map into a yarn lockfile format

Extracts the version from the comments on a parsed lockfile

Link to this section Functions

Specs

decode(binary()) :: {:ok, map()} | {:error, String.t()}

Parses a lock file

Examples

iex> input =
...>   """
...>   prop1 val1
...>   block1:
...>     prop2 true
...>   prop3 123
...>   """
iex> YarnParser.decode(input)
{:ok, %{
  "prop1" => "val1",
  "block1" => %{
    "prop2" => true
  },
  "prop3" => 123
}}

Specs

encode(map(), keyword()) :: String.t()

Encodes a map into a yarn lockfile format

Options

  • :version The yarn lockfile version. Defaults to 1.
  • :no_header If true, it skips header comments. Defaults to false.

Examples

iex> map = %{"prop1" => 1,"block1" => %{"prop2" => true}}
iex> YarnParser.encode(map, no_header: true)
"block1:\n  prop2 true\n\nprop1 1"

Specs

get_version(map()) :: nil | integer()

Extracts the version from the comments on a parsed lockfile