Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing YAML in JS #186

Open
nightscape opened this issue Mar 26, 2021 · 2 comments
Open

Parsing YAML in JS #186

nightscape opened this issue Mar 26, 2021 · 2 comments

Comments

@nightscape
Copy link
Contributor

nightscape commented Mar 26, 2021

Hi all,

I've been having good success using js-yaml along with Circe to parse YAML in JS, so I thought I'd post a short comment here:

// build.sbt
libraryDependencies ++= Seq(
  "org.scalablytyped" %%% "js-yaml" % "3.12-dt-20200625Z-862e6d",
  "io.circe" %%% "circe-scalajs" % circeVersion
),
Compile / npmDependencies += "js-yaml" -> "3.12"
import io.circe.Decoder

import io.circe.scalajs._
import typings.jsYaml.{mod => yaml}

import scala.util.Try
object YamlDecoder {
  def parseAndDecode[T : Decoder](s: String): Either[Throwable, T] = {
    Try(yaml.load(s)).toEither.flatMap(decodeJs[T](_))
  }
}

Would something like this be worthy to put into circe-yaml itself?

@armanbilge
Copy link

I thought about this too, but since the intermediate representation in this case is effectively universal (i.e., Javascript Objects) I see no reason to prescribe a specific JS implementation for this.

@armanbilge
Copy link

I've now published a fork of this lib that uses Virtus Lab Scala Yaml and is cross-published for JVM and JS.
https://github.com/armanbilge/circe-scala-yaml/releases/tag/v0.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants