ToJs

zio.blocks.html.ToJs
See theToJs companion object
trait ToJs[-A]

Typeclass for values that can be safely interpolated into JavaScript via js"...".

This is a '''templating''' typeclass, not a code generator. It converts Scala values into JavaScript '''expressions''' (value literals). Every JavaScript expression is also a valid statement, so ToJs output works in all template contexts: inline event handlers, script content, and variable assignments. For JavaScript control flow (if/for/while), use Js("...") directly.

Instance behavior:

  • String is quoted with " and JS-escaped (including `` protection)
  • Numeric types render as unquoted literals
  • Boolean renders as true/false
  • Option renders as the value or null
  • List/Map render as JSON arrays/objects
  • Types with a zio.blocks.schema.Schema auto-derive via JSON serialization

Attributes

Companion
object
Source
ToJs.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

def toJs(a: A): String
Implicitly added by listToJs

Attributes

Source
ToJs.scala
def toJs(a: A): String
Implicitly added by mapToJs

Attributes

Source
ToJs.scala
def toJs(a: A): String
Implicitly added by optionToJs

Attributes

Source
ToJs.scala
def toJs(a: A): String

Attributes

Source
ToJs.scala