yarn_parser v0.4.0 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

Link to this function

decode(input, opts \\ [])

View Source

Specs

decode(binary(), keyword()) ::
  {:ok, YarnParser.YarnLock.t()} | {:error, String.t()}

Parses a lock file

Examples

iex> input =
...>   """
...>   # yarn lockfile v1
...>   prop1 val1
...>   block1:
...>     prop2 true
...>   prop3 123
...>   """
iex> YarnParser.decode(input)
{:ok, %YarnParser.YarnLock{
  dependencies: %{
    "prop1" => "val1",
    "block1" => %{
      "prop2" => true
    },
    "prop3" => 123
  },
  metadata: %{
    "version" => 1
  }
}}

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(YarnParser.YarnLock.t()) :: nil | integer()

Extracts the version from the comments on a parsed lockfile