module Yarnlock

Constants

VERSION

Public Class Methods

config() click to toggle source
# File lib/yarnlock.rb, line 13
def self.config
  @config ||= Config.new
end
configure() { |config| ... } click to toggle source
# File lib/yarnlock.rb, line 17
def self.configure
  yield config
end
load(file) click to toggle source
# File lib/yarnlock.rb, line 43
def self.load(file)
  parse File.read(file)
end
parse(yarnlock) click to toggle source
# File lib/yarnlock.rb, line 21
def self.parse(yarnlock)
  json_string = JsExecutor.execute 'parse', yarnlock
  parsed = JSON.parse json_string

  raise "An error was occurred when parsing yarn.lock: #{parsed}" unless parsed.is_a? Hash
  raise "Could not parse yarn.lock: #{parsed['reason']}" if parsed['type'] == 'failure'

  return parsed['object'] unless config.return_collection

  Entry::Collection.parse parsed['object']
end
stringify(object) click to toggle source
# File lib/yarnlock.rb, line 33
def self.stringify(object)
  json_string = JsExecutor.execute 'stringify', JSON.generate(object)
  parsed = JSON.parse json_string

  raise "An error was occurred when stringing object: #{parsed}" unless parsed.is_a? Hash
  raise "Could not stringing object: #{parsed['reason']}" if parsed['type'] == 'failure'

  parsed['yarnlock']
end