Skip to content

string

Builds a parser for strings. DDataParser.string() guarantees the input is a string (with optional coercion support), applies the provided checkers, and returns a typed Either containing either the validated value or a detailed DataParserError.

Interactive example

Parameters

  • errorMessage: custom message injected into each issue when the input is not a string.
  • checkers: array of checkers (checkerStringMin, checkerStringMax, checkerStringRegex, checkerEmail, checkerUrl, checkerRefine, etc.) executed after the base validation.
  • coerce: true to transform non-string inputs (numbers, booleans, objects with toString) before running the checkers. Defaults to false.

Return value

A DataParserString providing parse, asyncParse, exec, asyncExec, addChecker, and clone. schema.parse(data) returns DEither.success<string> when all validations pass, or DEither.error<DataParserError> with the paths (path), messages, and rejected values.

Other examples

Custom checkers

Extended mode

See also

  • boolean — parser for boolean values
  • coerce.* — specialized variants to normalize inputs before strict validation

Released under the MIT license.