yarn_parser

A simple yarn.lock parser


Keywords
elixir-lang, elixir-library, yarn, yarnpkg
License
MIT

Documentation

YarnParser

Installation

Available in Hex, the package can be installed by adding yarn_parser to your list of dependencies in mix.exs:

def deps do
  [
    {:yarn_parser, "~> 0.3.1"}
  ]
end

Usage

iex> input = 
  """
  # Some comment
  # yarn lockfile v1
  key1, key2:
    val1 true
    subkey1:
      val2 123
  """

iex> {:ok, parsed} = YarnParser.decode(input)
iex> parsed
%YarnParser.YarnLock{
  metadata: %{
    "version" => 1
  }
  dependencies: {
    "key1" => %{
      "val1" => true,
      "subkey1" => %{
        "val2" => 123
      }
    },
    "key2" => %{
      "val1" => true,
      "subkey1" => %{
        "val2" => 123
      }
    }
  }
}

iex> YarnParser.get_version(parsed)
1

iex> YarnParser.encode(parsed)
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1

key1, key2:
  subkey1:
    val2 123
  val1 true

TODO

  • Parse with merge conflicts
  • Improve error messages
  • Improve test suite
  • Implement encoder for v2 lockfiles