RecordPlatformSpecific

com.github.tarao.record4s.RecordPlatformSpecific

Attributes

Source
RecordPlatformSpecific.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Record

Members list

Value members

Concrete methods

def fromJS[R <: %](obj: Any)(using nc: NativeConverter[R]): R

Construct a record from a JavaScript object.

Construct a record from a JavaScript object.

Any nested type T can be converted as long as a NativeConverter[T] instance is given.

This operation is of course unsafe. Missing primitive fields become zeros or nulls and missing object fields yield java.lang.RuntimeException.

Value parameters

nc

a conversion type class

obj

a JavaScript object

Attributes

Returns

a record

Example
 import scala.scalajs.js
 val obj: js.Any = js.Dynamic.literal(name = "tarao", age = 3)
 val r = Record.fromJS[% { val name: String; val age: Int }](obj)
 // val r: com.github.tarao.record4s.%{val name: String; val age: Int} = %(name = tarao, age = 3)
Source
RecordPlatformSpecific.scala
def fromJSON[R <: %](json: String)(using nc: NativeConverter[R]): R

Construct a record from a JSON string.

Construct a record from a JSON string.

Any nested type T can be converted as long as a NativeConverter[T] instance is given.

This operation is of course unsafe. Missing primitive fields become zeros or nulls and missing object fields yield java.lang.RuntimeException.

Value parameters

json

a JSON string

nc

a conversion type class

Attributes

Returns

a record

Example
 import scala.scalajs.js
 val json = """{"name":"tarao","age":3}"""
 val r = Record.fromJSON[% { val name: String; val age: Int }](json)
 // val r: com.github.tarao.record4s.%{val name: String; val age: Int} = %(name = tarao, age = 3)
Source
RecordPlatformSpecific.scala

Givens

Givens

inline given nativeConverter[R <: %](using r: RecordLike[R]): NativeConverter[R]

Attributes

Source
RecordPlatformSpecific.scala

Extensions

Extensions

extension [R <: %](record: R)
def toJS(using NativeConverter[R]): Any

Convert this record to a JavaScript object

Convert this record to a JavaScript object

Any nested type T can be converted as long as a NativeConverter[T] instance is given.

Attributes

Returns

a JavaScript object

Example
 val r = %(name = "tarao", age = 3)
 val obj = r.toJS
 // val obj: scala.scalajs.js.Any = [object Object]
Source
RecordPlatformSpecific.scala
def toJSON(using NativeConverter[R]): String

Convert this record to a JSON string

Convert this record to a JSON string

Any nested type T can be converted as long as a NativeConverter[T] instance is given.

Attributes

Returns

a JSON string

Example
 val r = %(name = "tarao", age = 3)
 val json = r.toJSON
 // val json: String = {"name":"tarao","age":3}
Source
RecordPlatformSpecific.scala