Skip to content

record

DDataParser.record(keyParser, valueParser) validates dynamic dictionaries by checking both the shape of the keys (string/literal/template literal/number/union) and the associated values.

Interactive example

Parameters

  • key: parser for the keys (DP.string(), DP.templateLiteral(...), DP.literal([...]), etc.).
  • input: parser applied to each entry (DP.number(), DP.object(...), ...).
  • checkers: checkerRefine to express global constraints (required keys, minimum sum, etc.).
  • errorMessage: generic message if the input is not an indexable object.

Return value

A DataParserRecord. schema.parse(data) returns DEither.success<Record<OutputKey, OutputValue>> or DEither.error<DataParserError> with the incriminated keys.

See also

  • object - Parser for objects
  • empty - Parser for empty values

Released under the MIT license.