Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • "Boolean"

  • "Number"

  • "RegExp"

  • "String"

  • "Hex"

The following coercions are valid:

  • Strings can be coerced to numbers (integers or reals) and regular expressions. If the string is not parsable as a number, the result is null. The empty string parses as 0.
  • Numbers can be coerced to strings. 
  • Regular expressions can be coerced to strings.
  • Any expression can be coerced to Boolean.
  • null and false can be coerced to 0, and true can be coerced to 1
  • Hex values must match the regex /^[A-F0-9]+$/

An error is thrown for other attempted coercions, unless the value being coerced by as() is already of the target type.

...