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.
Summary
Functions
Applies a binary operator to two already evaluated operands.
IsLooselyEqual (==).
Turns an integral float into an integer and an integer beyond 2^53 into a float.
StringToNumber: the number a string reads as, or :nan. Leading and
trailing whitespace is ignored and the empty string is 0.
ToString, as String(value) gives it.
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.
ToNumber, with 0 in place of NaN.
ToBoolean.
Applies ! or unary -.
Functions
Applies a binary operator to two already evaluated operands.
IsLooselyEqual (==).
Turns an integral float into an integer and an integer beyond 2^53 into a float.
StringToNumber: the number a string reads as, or :nan. Leading and
trailing whitespace is ignored and the empty string is 0.
ToString, as String(value) gives it.
@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.
ToNumber, with 0 in place of NaN.
ToBoolean.
Applies ! or unary -.