danielnixon / safer-dom   0.5.0

GitHub

A scala-js-dom library that replaces nullable return types T with Option[T].

Scala versions: 2.12 2.11 2.10
Scala.js versions: 0.6

safer-dom

Build Status Maven Central

A scala-js-dom library that replaces nullable return types T (which the web APIs like to do everywhere) with Option[T].

Usage

  1. Add the dependency to your build:

libraryDependencies += "org.danielnixon" %%% "safer-dom" % "0.4.0"

  1. Import org.danielnixon.saferdom.implicits._.

  2. Replace calls to nullable methods (e.g. document.querySelector()) with their safer alternatives (e.g. document.querySelectorOpt()).

For example, this (which would have exploded with a TypeError at runtime):

window.document.querySelector("nope").innerHTML = "foo"

can be now be written as:

import org.danielnixon.saferdom.implicits._
window.document.querySelectorOpt("nope").foreach(_.innerHTML = "foo")