Skip to content

tryCoerce

tryCoerce(value, type) → value · Type

Try to coerce a value to the target type, returning null on failure (instead of throwing).

  • value (required): value to coerce

  • type (required): target type string (e.g. "number", "boolean")

utlx
tryCoerce("42", "number")                // 42
tryCoerce("not-a-number", "number")      // null (no error)

Released under AGPL-3.0.