Skip to content

literal ​

DDataParser.literal() restricts the input to one or more exact values (string, number, bigint, boolean, null, undefined). Handy for expressing runtime enums without losing TypeScript inference.

Interactive example ​

Parameters ​

  • input: allowed value or array of values (automatically normalized to an array).
  • errorMessage: custom message if the input does not match the whitelist.
  • checkers: checkerRefine to add business logic.

Return value ​

A DataParserLiteral whose parse returns DEither.success<LiteralUnion> on success, otherwise DEither.error<DataParserError>.

Other examples ​

Custom checkers ​

Extended mode ​

See also ​

  • number - Parser for numbers
  • tuple - Parser for fixed-size arrays

Released under the MIT license.