# `OpenUI.Runtime.Value`
[🔗](https://github.com/ideia4it/openui/blob/v0.1.1/lib/openui/runtime/value.ex#L1)

The value semantics of OpenUI Lang (language.md, sections 3.1 and 3.2).

The spec defines coercion, loose equality and number formatting by
ECMAScript, so this module reproduces ToNumber, IsLooselyEqual and
Number::toString on Elixir terms. Two differences come from the BEAM:

  * there is no NaN or Infinity, so a string that ToNumber would read as
    Infinity (`"Infinity"`, `"1e400"`) counts as 0, like NaN does;
  * arrays and objects have no identity, so loose equality compares them by
    structure.

Numbers are integers when they hold an integral value within 2^53, and
floats otherwise, which keeps encoded JSON identical to JavaScript's.

# `binary_op`

```elixir
@spec binary_op(String.t(), term(), term()) :: term()
```

Applies a binary operator to two already evaluated operands.

# `loose_equal?`

```elixir
@spec loose_equal?(term(), term()) :: boolean()
```

IsLooselyEqual (`==`).

# `normalize_number`

```elixir
@spec normalize_number(number()) :: number()
```

Turns an integral float into an integer and an integer beyond 2^53 into a float.

# `parse_number`

```elixir
@spec parse_number(String.t()) :: number() | :nan
```

StringToNumber: the number a string reads as, or `:nan`. Leading and
trailing whitespace is ignored and the empty string is 0.

# `stringify`

```elixir
@spec stringify(term()) :: String.t()
```

ToString, as `String(value)` gives it.

# `text_length`

```elixir
@spec text_length(String.t()) :: non_neg_integer()
```

The length of a string as JavaScript counts it, in UTF-16 code units. Bytes
that are not valid UTF-8, as in text cut mid-character, count one each.

# `to_number`

```elixir
@spec to_number(term()) :: number()
```

ToNumber, with 0 in place of NaN.

# `truthy?`

```elixir
@spec truthy?(term()) :: boolean()
```

ToBoolean.

# `unary_op`

```elixir
@spec unary_op(String.t(), term()) :: term()
```

Applies `!` or unary `-`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
