Skip to content

union

DDataParser.union() tries multiple parsers in the provided order and returns the first success. On failure, all issues are aggregated to help with debugging.

Interactive example

Parameters

  • options: non-empty array of parsers ([DP.string(), DP.number(), ...]).
  • checkers: checkerRefine to apply a rule on the final result (e.g. forbid certain values).
  • errorMessage: custom message when no option matches.

Return value

A DataParserUnion. schema.parse(data) returns DEither.success<OutputUnion> if it finds a match, otherwise DEither.error<DataParserError> containing the errors from each option.

Other examples

Extended mode

See also

  • boolean - Parser for boolean values
  • date - Parser for dates

Released under the MIT license.